99miles
99miles

Reputation: 11232

FactoryGirl RSpec No method error when creating factory object where factory sets a property of that object

Anytime I create a Factory object, I get this error where the factory sets a property on that object -- in this case 'name'. Why???

businesses.rb

FactoryGirl.define do
  factory :business do

    factory :business_main do
      name "Dave's Toys"
    end
  end
end

businesses table

        Column        |            Type             |                        Modifiers                        
----------------------+-----------------------------+---------------------------------------------------------
 id                   | integer                     | not null default nextval('businesses_id_seq'::regclass)
 name                 | character varying(255)      | 
 address_line1        | character varying(255)      | 
 address_line2        | character varying(255)      | 
 city                 | character varying(255)      | 
 state                | character varying(255)      | 
 zip                  | character varying(255)      | 

business_spec.rb

...
business  = Factory(:business_main)
...

 # Failure/Error: business  = Factory(:business_main)
 # NoMethodError:       undefined method `name=' for #<Business:0x007fc991684590>

-

Using rails (3.1.3) 
Using factory_girl (2.3.2) 
Using factory_girl_rails (1.4.0)
Using rspec-core (2.7.1) 
Using rspec-expectations (2.7.0) 
Using rspec-mocks (2.7.0) 
Using rspec (2.7.0) 
Using rspec-rails (2.7.0) 

Upvotes: 3

Views: 1487

Answers (1)

Walking Wiki
Walking Wiki

Reputation: 699

Run rake db:test:clone and then all test DB columns will be mapped properly to Active Record methods.

Upvotes: 7

Related Questions