Can someone tell me if I\'m just going about the setup the wrong way?
I have the following models that have has_many.through associations:
class List
You could use trait:
FactoryGirl.define do
factory :listing do
...
trait :with_features do
features { build_list :feature, 3 }
end
end
end
With callback, if you need DB creation:
...
trait :with_features do
after(:create) do |listing|
create_list(:feature, 3, listing: listing)
end
end
Use in your specs like this:
let(:listing) { create(:listing, :with_features) }
This will remove duplication in your factories and be more reusable.
https://robots.thoughtbot.com/remove-duplication-with-factorygirls-traits