Factory Girl 对象图的公共根
invitation ------> event
\ \
\/ \/
responder(person) ---->account
\ /\
\ /
group-------------
我有上面的关联图。 以及下面的工厂代码:
Factory.define :invitation do |i|
i.association :event
i.association :responder, :factory => :person
end
Factory.define :event do |e|
e.association :account
end
Factory.define :person do |p|
p.association :account
p.association :group
end
Factory.define :group do |g|
g.association :account
end
如果我想使用“Factory :invitation”创建邀请,那么该帐户将被创建多次。并且第二次尝试已经占用了帐户的唯一字段。 有什么聪明又好的收据吗?
invitation ------> event
\ \
\/ \/
responder(person) ---->account
\ /\
\ /
group-------------
I have the above association graph.
And the below factory code:
Factory.define :invitation do |i|
i.association :event
i.association :responder, :factory => :person
end
Factory.define :event do |e|
e.association :account
end
Factory.define :person do |p|
p.association :account
p.association :group
end
Factory.define :group do |g|
g.association :account
end
If I want to create an invitation with "Factory :invitation" then the account would be created more than once. And the unique fields for account are already taken by the second attempt.
Is there any clever and nice receipt for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
after_create
(或after_build
)回调中重用事件帐户。您必须以类似的方式修改组工厂。
You can reuse the account of event in the
after_create
(orafter_build
) callback.You'll have to modify the group factory in a similar way.