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?
How do I send params to a FactoryGirl trait?
Asked Answered
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
ignore is deprecated and will be removed in FactoryGirl 5.0 you can use transient instead of ignore source –
Lapsus
© 2022 - 2024 — McMap. All rights reserved.
after_create
block in the trait. – Calcium