You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a case where two models depend on each other, i.e. one cannot exist without the other and the relationship can never be nil. As you can see below, this is also a polymorphic relationship.
In my Lander and Offer factories I am creating the Destination since Destination will never be directly created in the application. When linting factories, FactoryGirl's implementation calls build on each factory. This causes an issue since when building Lander and Offer factories, Destinations are created with a nil destinationable association. This is because both Lander and Offer are built, not saved to the database, and do not have an id when linted
This causes two issues
Destination should never exist in the database with a nil destinationable association
Gives a unique validation error since it tries to create multiple destinationables with nil
defcalculate_invalid_factoriesfactories_to_lint.selectdo |factory|
built_factory=FactoryGirl.create(factory.name)#<< this lineifbuilt_factory.respond_to?(:valid?)
!built_factory.valid?endendend
Any ideas for how to handle this issue? Do you think it would be a good idea to allow the option tocreate instead of build on linting? I think this would be an issue whenever you try and build two dependent models that must be created together to exist.
The text was updated successfully, but these errors were encountered:
I have a case where two models depend on each other, i.e. one cannot exist without the other and the relationship can never be nil. As you can see below, this is also a polymorphic relationship.
Models
In my Lander and Offer factories I am creating the Destination since Destination will never be directly created in the application. When linting factories, FactoryGirl's implementation calls
build
on each factory. This causes an issue since when building Lander and Offer factories, Destinations are created with anil
destinationable association. This is because both Lander and Offer are built, not saved to the database, and do not have an id when lintedThis causes two issues
My factories are linted without errors when I override calculate_invalid_factories to call create instead of build: https://github.com/thoughtbot/factory_girl/blob/master/lib/factory_girl/linter.rb#L24
Any ideas for how to handle this issue? Do you think it would be a good idea to allow the option to
create
instead ofbuild
on linting? I think this would be an issue whenever you try and build two dependent models that must be created together to exist.The text was updated successfully, but these errors were encountered: