Factory for model with associated upload file

3 views
Skip to first unread message

Les Nightingill

unread,
Mar 27, 2013, 6:40:28 PM3/27/13
to factor...@googlegroups.com
I have a factory for an ActiveRecord model that has an associated (uploaded) file. The file should be added to the filesystem when the factory object is "create"d but not for "build".

I can use the before(:create) callback to create the file in the filesystem. Works great. FactoryGirl.create(:qualdoc) creates the associated file.

But

The model (Qualdoc) "belongs_to" another model (Household). So the factory for Household has association :qualdoc, :strategy => :build. And the before(:create) callback for the Qualdoc factory is not called when the Household model is saved. 

I need a before(:save) callback. Is it possible to do that somehow?

thanks in advance for any pointers you can offer

Les
Reply all
Reply to author
Forward
0 new messages