I'm trrying to fabricate a model that has multiple associations. because each association has different, specific, element I can't just do 2.times. Additionally because the parent model has an after_update statement I want to build it all at the same time rather than creating the associated model after the fact.
I have tried the following
it "builds multiple associations" do
customer_1 = Fabricate(:customer)
customer_2 = Fabricate(:customer)
trip_1 = Fabricate(:trip, date: Date.today) do
participations { [Fabricate(:participation, customer_id:
customer_1.id )] }
participations { [Fabricate(:participation, customer_id:
customer_1.id )] }
end
expect(Participation.where("trip_id =?",
trip_1.id).size).to eq 2
end
but this just builds one association, using the second line
I've tried using lines such as participations { [Fabricate(:participation, customer_id:
customer_1.id )], [Fabricate(:participation, customer_id:
customer_2.id )] }
but this just throws up an error. Any thoughts on how to achieve this?
Michael