title: How to test a model with a has_one association with FactoryGirl when I am already creating the association in the model
body: <p>I have a User model which has_one Profile. The Profile is automatically created when I create the User like so;</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_one :profile, dependent: :destroy
    after_create :create_profile
  end
  
  class Profile &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  
  <p>This all works nicely and a default profile is created with every user.</p>
  
  <p>I want to do some testing of my user model though and this is where I am struggling.</p>
  
  <p>I am using FactoryGirl and want to create a user like so</p>
  
  <pre><code>FactoryGirl.define do
    factory :user do
      sequence(:email) {|n| "user_#{n}@example.com"}
      sequence(:username) {|n| "user_#{n}"}
      password "secret"
      factory :activated_user do
        before(:create) {|user| user.activated = true}
        association :profile, factory: :profile_for_activated_user
      end
    end
  end
  
  FactoryGirl.define do
    factory :profile do
      factory :profile_for_activated_user do
        first_name "Johnny"
        last_name "User"
      end
    end
  end
  </code></pre>
  
  <p>This is where things go wrong for me. The after_create callback (which I want) overrides the association created by FactoryGirl (on <code>FactoryGirl.create :activated_user</code>) so I end up with a blank profile and failed tests. Do I need to change the way I am creating the association in the model (which I shouldn't have to - I shouldn't have to modify my code to suit my testing tools) or is there a way of managing this in FactoryGirl? Should I just manually assign the profile attributes in my test after creating the User in FactoryGirl?</p>