使用FactoryGirl,如何将accepts_nested_attributes_for 子属性插入到我正在创建的对象中?
factory :payment_object do
company_id 1
user_id 1
delivery_date (Date.today + 1)
payment_terms 'CBD'
vendor 'Apple'
currency 'USD'
# item
# name "Macbook"
# quantity 1
# price 1000
# item
# name "Magic Mouse"
# quantity 1
# price 65
end
factory :payment_object do
company_id 1
user_id 1
delivery_date (Date.today + 1)
payment_terms 'CBD'
vendor 'Apple'
currency 'USD'
# item
# name "Macbook"
# quantity 1
# price 1000
# item
# name "Magic Mouse"
# quantity 1
# price 65
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种可以在您的规格内完成此操作的方法。
Here's a way you can do it inside your specs.
这是不直观的,但 Factory_girl 文档说明了当您搜索“has_many”时如何:
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md基本上
,首先,创建另一个工厂:
然后在代码中使用它,如下所示:
It's unintuitive, but the factory_girl docs states how, when you search for 'has_many':
https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md
Basically, first, make another factory:
Then use that within your code, like this: