0

我有这个工厂:

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

但不断收到此错误:

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)

我理解错误,但我不明白我的语法是如何关闭的。

4

1 回答 1

2

不是语法:after(:create) { this_runs_first }所以我想知道如果你这样做是否会起作用。

于 2012-09-19T01:06:35.090 回答