title: Rails error ActiveRecord::AssociationTypeMismatch: User(#65709220) expected, got String(#19934580)
body: <p>Hi um using rspec in rails and um creating a valid user as follows</p>
  
  <pre><code>it "should create a valid user" do
      @user = User.find_or_create_machine_user("test@dllo.no","test_first",     "test_last").should be_an_instance_of User
    end
  </code></pre>
  
  <p>this test passes and works fine , but when I include this section um getting an error </p>
  
  <pre><code> @batch = FactoryGirl.create(:batch, :file_name =&gt; "test_file",
                                    :created_by=&gt; @user)
  </code></pre>
  
  <p>and says <code>ActiveRecord::AssociationTypeMismatch:
         User(#65709220) expected, got String(#19934580)</code> . I tried with created_by_id = @user.id.to_int this also got failed.</p>
  
  <p>schema</p>
  
  <pre><code>class Batch &lt; ActiveRecord::Base
    belongs_to :created_by, :class_name =&gt; "User", :foreign_key =&gt; :created_by
    attr_accessible :created_by, :file_name
  </code></pre>
  
  <p>Can anyone tell how to overcome from this? created_by accepts a user</p>