Overriding Associations from Factory.create

278 views
Skip to first unread message

Chris Gardner

unread,
Sep 29, 2009, 8:20:28 PM9/29/09
to factory_girl
Is there a way to override an association through a call to
Factory.create?

Factory.define :foo do |f|
f.name = 'fowled up'
f.time = DateTime.now
f.status { |a| a.association(:somewhat_beyond_all_recognition)}
end

Factory.define :somewhat_ beyond_all_recognition, :class => Bar do |b|
b.status = 'a minor disaster'
b.time = DateTime.now
...
end

Factory.define :extremely_ beyond_all_recognition, :class => Bar do |
b|
b.status = 'a major disaster'
b.time = Time.new(2004, 1, 1)
...
end

So, I'd like to be able to change f.status association to
use :somewhat_beyond_all_recognition.

Factory.create(:foo, ?)

Mark Wilden

unread,
Sep 29, 2009, 8:55:50 PM9/29/09
to factor...@googlegroups.com

Well, you could always do Factory(:foo, :status =>
Factory(:somewhat_beyond_all_recognition))

///ark

Christopher Gardner

unread,
Sep 29, 2009, 9:37:18 PM9/29/09
to factor...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages