2012-08-28 77 views
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

在factorygirl wiki掃視了一眼,它看起來像你對我需要改變你的manager.rb代碼:

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

它的作品!謝謝! –