Ok guys. How does that make sense? Two nested factories (which are considered FactoryGirl inheritance) should not conflict with each other. What the hell is going on? Either this is not inheritance, or it is. I donโt know why they would call this inheritance if it werenโt. Am I just doing something wrong? (Notification f.account_type )
Have a look at the factory definition below.
factory :partner do |f| f.company_name { Faker::Company.name } f.username { Faker::Internet.user_name } f.password { Faker::Internet.password } f.password_confirmation { password } f.pid { Faker::Lorem.word } f.association :primary_contact # Inherited factory :business_partner do f.account_type "business" f.tax_id { Faker::Company.duns_number } end # Inherited factory :personal_partner do f.account_type "personal" f.ssn { Faker::Company.duns_number } end end
When I run my tests, I get this error.
Failure/Error: partner = FactoryGirl.create(:business_partner) FactoryGirl::AttributeDefinitionError: Attribute already defined: account_type
And just for the sake of completeness of my specification.
# spec/models/partner.rb require 'spec_helper' require 'pp' describe Partner do it "has a valid factory" do partner = FactoryGirl.create(:business_partner) partner.should be_valid puts partner end it "is invalid without a firstname" do
ruby ruby-on-rails-4 rspec factory-bot
Volte
source share