使用 Factory Girl 为 Thread 和 Thread Participations 创建工厂
有人可以提供一个示例或指出我可以在哪里学习如何进行 Factory Girl 嵌套模型关联吗?
一个线程必须至少有一个 ThreadParticipation
现在我的线程位于factories.rb 中,如下所示:
Factory.define :thread do |thread|
thread.title "mythread"
end
然后如何创建一个 ThreadParticipation?
谢谢
can someone provide an example or point me to where I can learn how to do Factory Girl nested model associations?
A Thread has to have at least one ThreadParticipation
Right now I have my thread in factories.rb as follows:
Factory.define :thread do |thread|
thread.title "mythread"
end
How do I then create a ThreadParticipation?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Factory_girl 源中的入门文件包含有关关联的信息。
因此,在您的实例中,我想像这样:
如果您使用集合而不是
has_one
/belongs_to
关联,那么您可以这样创建一个数组:The Getting Started file in the factory_girl source has info on associations.
So, in your instance, I would imagine something like this would do:
If you're using a collection instead of a
has_one
/belongs_to
association, you can create an array as such: