我正在编写一些调用FG创建的测试,其特征是after_create,创建一个关联对象。有没有办法在制作FG时将参数发送到相关产品,或者之后是否需要设置它们?
答案 0 :(得分:9)
在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