简体   繁体   中英

factory_girl create vs build and associations

I am having some trouble with factory_girl's associations:

Factory.define :account do |f|
  f.sequence(:email) {|n| "john#{n}@example.com" }
  f.password "secret"
  f.confirmed_at 2.days.ago.to_s(:db)
  f.name "John Doe"
  f.seller false
  f.admin false
end

Factory.define :request do |f|
  f.association :account
  f.message 'Test message.'
end

And here's the problem:

When I do a = Factory(:request), a.account => nil but when I do a = Factory.build(:request), a.account is correct.

Any idea why this might be?

Thanks

Factory(:request) calls for default strategy, did you changed that somewhere?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM