I'm writing some tests that call a FG create with a trait that after_create, makes an associated object. Is there a way to send parameters to that associated product when I make the FG, or do I need to set them afterwards?
Add that parameter in ignore:
FactoryGirl.define do
trait :my_trait do
ignore do
associated_attributes nil
end
after_create do |object, evaluator|
# Use the ignored associated_attributes when creating the associated object
associated_object = AssociatedModel.new(evaluator.associated_attributes)
end
end
end
And this page has a lot more tricks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With