工厂女孩协会与儿童班,显示nomethoderror:未定义的方法

时间:2012-08-28 08:20:35

标签: associations factory-bot nomethoderror

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 ....

1 个答案:

答案 0 :(得分:4)

瞥了一眼工厂女wiki,我觉得你需要将manager.rb代码更改为:

factory :manager do
  association :user, :factory => :admin_user
  description "manager"
end