Jarrett
Jarrett

Reputation: 113

Error with building associations in FactoryGirl

I have this factory:

FactoryGirl.define do
  factory :asset_size do 

    sequence(:name) { |n| "AssetSize#{n}" }  

    after_create do |as|
      FactoryGirl.create(:midpoint, :asset_size => as)
      FactoryGirl.create(:midpoint, :asset_size => as, :grade => 18, :yearly_wage => 25000.00)
    end

  end
end

but keep getting this error:

AssetSize(#70166742384960) expected, got #<Class:0x007fa1eddef738>(#70166728637340)   (ActiveRecord::AssociationTypeMismatch) ./spec/factories/asset_size_factory.rb:7:in `block (3 levels) in './features/step_definitions/role_authorization_steps.rb:2:in `/^a basic balanced results employee$/'./features/role_authorization.feature:4:in `Given a basic balanced results employee'

after_create do |as|
  FactoryGirl.create(:midpoint, :asset_size => as)
  FactoryGirl.create(:midpoint, :asset_size => as, :grade => 18, :yearly_wage => 25000.00)

I underatand the error, but I don't understand how my syntax is off.

Upvotes: 0

Views: 173

Answers (1)

pjammer
pjammer

Reputation: 9577

Isn't the syntax: after(:create) { this_runs_first } so i wonder if it will work if you do it that way.

Upvotes: 2

Related Questions