创建默认为nil的Factory关联? [英] Creating a Factory association that defaults to nil?

查看:79
本文介绍了创建默认为nil的Factory关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用FactoryGirl gem在Factorys.rb文件中,如何使用默认为零的关联创建工厂?

Using the FactoryGirl gem, inside the factories.rb file, how can I create a factory with an association that defaults to nil?

我正在考虑以下方面的内容:

I am thinking something along these lines:

Factory.define :user do |factory|
  factory.association :post
  factory.association :comment, :default => nil
end

那是正确的做法吗?

推荐答案

Factory.define :user do |factory|
  factory.association :post
  factory.comment_id  nil
end

这篇关于创建默认为nil的Factory关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆