Search code examples
ruby-on-railsfactory-botfactories

Creating a Factory association that defaults to nil?


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

Would that be right and would that be ok to do?


Solution

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