How can I create another factory from within a factory that is is not associated with?

5 views
Skip to first unread message

wha...@gmail.com

unread,
Mar 1, 2013, 4:27:19 PM3/1/13
to factor...@googlegroups.com
I was originally using after(:build) to create a different instance of a model that is needed but is not actually associated with the factory being created. The problem with this is it seems to create a database object that is not deleted by my transaction database cleaner.

Ex:

factory :order do
  factory :particular_order do
    after(:build) do |order, evaluator|
      create(:product, name: "Fake Product")
    end
  end
end

Running build(:particular_order) in my tests will create product in my database and not allow the cleaner to remove it after the test is done, tho the database cleaner works on everything else i use that doesn't have after(:build) calls.

I am trying to avoid having to use truncation to clean the database after just these runs.

I've tried A LOT to get this working.

Any ideas?
Reply all
Reply to author
Forward
0 new messages