Factory_girl 中有没有办法获取 attribute_for 并为同一实例元素创建?
如果我想使用“create”构建策略创建和实例,然后想使用“attributes_for”构建策略进行验证,可以吗?如果我在工厂使用序列呢?机械师宝石中可能吗?
If I want to create and instance using "create" build strategy and then want to use "attributes_for" build strategy for verification, is it possible to do? And if I use sequences in the factory? Is it possible in Machinist gem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不太确定我完全理解。而且我不是机械师的用户。但听起来你只是想做这样的事情。
Not quite sure I fully understand. And I'm not a user of machinist. But it sounds like you just want to do something like this.
John Hinnegan 建议的解决方案是合理的,但您最好使用对象的
FactoryGirl.create
方法初始化,因为它通常会给你一个有效的对象。例如,如果您使用MyObject.new
,则不会调用after(:create)
。The solution John Hinnegan suggest is sound, but you better use the
FactoryGirl.create
method for object initialization, because it will usually give you a valid Object. For example aafter(:create)
won't be called if you useMyObject.new
.感谢这篇文章,只是想补充一下,这个班级是 FactoryGirl
Thanks for this post, just wanted to add that the class is FactoryGirl