title: Bypass Rails validations when creating FactoryGirl objects
body: <p>I have two models (ModelA and ModelB), and FactoryGirl factories for each. I want the factory for ModelB to be able to (A) create test data, and to (B) build (without saving to database) sample data for display to customers. I am having trouble getting (A) to work due to Rails validations in my models.</p>
  
  <p>ModelA:</p>
  
  <pre><code>class ModelA &lt; ActiveRecord::Base
    belongs_to :model_b
    validates_presence_of :model_b
  end
  </code></pre>
  
  <p>Factory for ModelA:</p>
  
  <pre><code>FactoryGirl.define do
    factory :model_a do
      some_attr "hello"
      model_b { FactoryGirl.build :model_b }
    end
  end
  </code></pre>
  
  <p>ModelB</p>
  
  <pre><code>class ModelB &lt; ActiveRecord::Base
    has_one :model_a
  end
  </code></pre>
  
  <p>Factory for ModelB</p>
  
  <pre><code>FactoryGirl.define do
    factory :model_b do
      some_attr "goodbye"
    end
  end
  </code></pre>
  
  <p>I can't create objects from these factories without getting validation errors:</p>
  
  <pre><code> ruby&gt; FactoryGirl.create :model_a
   ActiveRecord::RecordInvalid: Validation failed: ModelB can't be blank
  </code></pre>
  
  <p>It appears that FactoryGirl is attempting to save the factory object before saving its assocations. I realize that I could have the factory for ModelB create its associated ModelA (rather than build it) - however, then I would lose the flexibility of being able to use the ModelA factory to either build sample data or save test data. Alternately, I could remove the validations; but then I wouldn't have validations.</p>
  
  <p>Any other options?</p>