I''m unable to get nested attributes in fixtures to work with Rspec. The models and fixtures function fine outside of rspec, but I get a mysql error (Unknown column "<nested table>_attributes) when running tests with the same fixtures. I am able to get the specs to run by creating a separate fixture for the nested table. Shouldn''t Rspec handle nested attributes in fixtures, though?
On Mon, Oct 11, 2010 at 12:05 PM, Mack <mack.talcott at gmail.com> wrote:> I''m unable to get nested attributes in fixtures to work with Rspec. > The models and fixtures function fine outside of rspec, but I get a > mysql error (Unknown column "<nested table>_attributes) when running > tests with the same fixtures. > > I am able to get the specs to run by creating a separate fixture for > the nested table. ?Shouldn''t Rspec handle nested attributes in > fixtures, though?The only fixture support provided by RSpec are hooks into the Rails configuration to tell it where fixtures are stored, whether to use instantiated fixtures, and whether to use transactions around each example. There is no specific support for fixture loading - that all comes from Rails. That said, maybe we can help you, but you''ll need to provide some more info: * rspec version * rails version * spec code * implementation code * _full_ failure message Code and failure messages are fine in email or in gists. Cheers, David
I appreciate the quick response! Sorry for the delay. The relevant code is attached. Our model''s name is Scale, which has_many ScaleElements. We''re loading fixtures in specs with config.fixture_path = "#{::Rails.root}/spec/fixtures" Nested attributes don''t work (although they do outside of Rspec in Rails), and we''re currently solving the problem by creating a scale_elements.yml fixture and not nesting attributes. rspec version: 2.0.1 rails version: 3.0.0 Attachments: http://www.ruby-forum.com/attachment/5251/code.txt -- Posted via http://www.ruby-forum.com/.
On Wed, Oct 27, 2010 at 6:30 PM, Mack T. <lists at ruby-forum.com> wrote:> I appreciate the quick response! ?Sorry for the delay. ?The relevant > code is attached. ?Our model''s name is Scale, which has_many > ScaleElements. > > We''re loading fixtures in specs with config.fixture_path > "#{::Rails.root}/spec/fixtures" > > Nested attributes don''t work (although they do outside of Rspec in > Rails), and we''re currently solving the problem by creating a > scale_elements.yml fixture and not nesting attributes. > > rspec version: 2.0.1 > rails version: 3.0.0 > > Attachments: > http://www.ruby-forum.com/attachment/5251/code.txtI haven''t used fixtures myself in a couple of years, and never used nested attributes. Does anyone else on the list have any advice to offer about this?
Figured this out. Our fixtures outside Rspec are actually being used to create instances of ActiveRecord models. AR supports accepts_nested_attributes_for, but the Rspec fixtures bypass AR and simply attempt to set database values. -- Posted via http://www.ruby-forum.com/.
On Oct 28, 2010, at 3:25 PM, Mack T. wrote:> Figured this out. Our fixtures outside Rspec are actually being used to > create instances of ActiveRecord models. AR supports > accepts_nested_attributes_for, but the Rspec fixtures bypass AR and > simply attempt to set database values.There are no "RSpec fixtures," so I don''t really understand what you mean here. The only thing RSpec does with regard to fixtures is expose a couple of configuration bits in the RSpec.configure block. The rest is all managed by the Rails'' testing framework. What do you mean "our fixtures outside rspec"?
By "fixtures outside Rspec", I was referring to files in our db/fixtures directory, which I assumed were fixtures. On further investigation, I found these files are actually being used by some custom ''seeding'' code a coworker of mine wrote. The seeding is reading the fixtures and creating AR objects, so they aren''t actually fixtures. This is how accepts_nested_attributes is working - fixtures don''t appear to support that out of the box. Also, when I said Rspec fixtures, I meant the files in spec/fixtures. In short, never mind - this really has nothing to do with Rspec :) I appreciate the quick responses. -- Posted via http://www.ruby-forum.com/.
On Oct 29, 2010, at 2:41 PM, Mack T. wrote:> By "fixtures outside Rspec", I was referring to files in our db/fixtures > directory, which I assumed were fixtures. On further investigation, I > found these files are actually being used by some custom ''seeding'' code > a coworker of mine wrote. The seeding is reading the fixtures and > creating AR objects, so they aren''t actually fixtures. This is how > accepts_nested_attributes is working - fixtures don''t appear to support > that out of the box. > > Also, when I said Rspec fixtures, I meant the files in spec/fixtures. > > In short, never mind - this really has nothing to do with Rspec :) > I appreciate the quick responses.Glad you got it resolved :) Cheers, David