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

1 回答 1

4

浏览 factorygirl wiki,在我看来您需要将 manager.rb 代码更改为:

factory :manager do
  association :user, :factory => :admin_user
  description "manager"
end
于 2012-08-28T08:34:06.600 回答