file 1 . user.rb
factory :user do
name "test"
end
factory :admin_user, :parent => user do
role "admin"
end
file 2. manager.rb
factory :manager do
association :admin_user
description "manager"
end
and while run FactoryGirl.create(:manager), it will show NoMethodError:
undefined method `admin_user=' for #<Manager ....
答案 0 :(得分:4)
瞥了一眼工厂女wiki,我觉得你需要将manager.rb代码更改为:
factory :manager do
association :user, :factory => :admin_user
description "manager"
end