I'm looking to DRY up my test suite. Trying to create a trait that represents specific values of a has_many relationship on the parent factory. Ideally these values would be created from a separate factory.
I want to do something like this:
factory :room do
trait :bathroom do
type :bathroom
end
end
factory :house do
trait :one_bathroom do
association, :rooms, factory: [:room, :bathroom]
end
end
The above should work if the relationship between house and room was 1 to 1. But House and Room has a One to Many relationship, so a House holds an array of Rooms. Working off this example I would be looking to create a house that had an array of rooms with just one bathroom.
Any ideas?