4

如何将 :subscriber 工厂中的 'email' 属性值传递给它的关联 :authentication

例如:

factory :subscriber, :class => Subscriber do                                                                                                   
  sequence(:name) { |n| "test_user_#{n}" }                                                                                                     
  sequence(:email) { |n| "test_user_#{n}@example.com"}                                                                                                                   
  association :authentication, factory: :authentication, email: email       
end

factory :authentication do
  sequence(:email) { |n| "test_user_#{n}@example.com"} 
  password 'pass'
end

给我错误

ArgumentError:
   Trait not registered: email
4

1 回答 1

0

我认为您需要使您的关联调用动态化,因为电子邮件变量可能会发生变化:

authentication {association :authentication, email: email}
于 2014-11-25T02:51:47.117 回答