-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Description
I'm trying to figure out how to solve an issue with circular dependencies. For example, I want to create a factory that accepts one of three associations. Whichever association is not provided would be created and associated with the one that was provided.
# pseudo example
factory :person do
parent { create :parent }
child { create :child, parent: parent }
something { create :something, parent: parent }
end
# usage
create(:person, parent: parent)
create(:person, child: child)
create(:person, something: something)
The problem I'm running into is not knowing which of these values was passed originally in the call to create. It's also valid to pass nil in order to instantiate the model with a missing association.
I've tried doing this in after(:build), but I have no way of knowing if the association was nil or if it was created because it wasn't specified.
If there was some way to access the original arguments, then I could know which one was provided. Is there already a way to do this?
Metadata
Metadata
Assignees
Labels
No labels