title: Rspec Mocking: ActiveRecord::AssociationTypeMismatch
body: <p>I'm new to Rspec and trying to set up a test for a User Profile. Profile belongs_to User.</p>
  
  <p>Now, I have an API integration with a third party site that works through the User Model, but some of the information for that API link is contained in Profile, so I have an "after_update" filter on Profile that tells the parent user to save, which triggers an update of the API.</p>
  
  <p>I'm trying to write a test for this, and I'm getting an ActiveRecord::AssociationTypeMismatch. The reason is I'm using a mock user, but I'm trying to test that when Profile is updated it sends :save to User. Plus, the User model has an email confirmation process and the afformentioned API calls in it's create process, so it really isn't ideal to actually create a user just to test this out.</p>
  
  <p>Here's my test:</p>
  
  <pre><code>it "should save the parent user object after it is saved" do
      user = double('user', :save =&gt; true )
      profile = Profile.create( :first_name =&gt; 'John', :last_name =&gt; 'Doe' )
      profile.user = user
  
      user.should_receive(:save)
  end
  </code></pre>
  
  <p>So, clearly the ActiveRecord error is being caused by trying to associate a mock user with a profile that expects a real user to be associated.</p>
  
  <p>My question is, how do you avoid this kind of problem in writing rails tests? All I want this test to do is make sure Profile calls :save on it's parent User. Is there a smarter way to do this, or a workaround for the ActiveRecord error?</p>
  
  <p>Thanks!</p>