Thursday, 5 September 2013

Rails error ActiveRecord::AssociationTypeMismatch: User(#65709220) expected, got String(#19934580)

Rails error ActiveRecord::AssociationTypeMismatch: User(#65709220)
expected, got String(#19934580)

Hi um using rspec in rails and um creating a valid user as follows
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
this test passes and works fine , but when I include this section um
getting an error
@batch = FactoryGirl.create(:batch, :file_name => "test_file",
:created_by=> @user)
and says ActiveRecord::AssociationTypeMismatch: User(#65709220) expected,
got String(#19934580) . I tried with created_by_id = @user.id.to_int this
also got failed.
schema
class Batch < ActiveRecord::Base
belongs_to :created_by, :class_name => "User", :foreign_key => :created_by
attr_accessible :created_by, :file_name
Can anyone tell how to overcome from this? created_by accepts a user

No comments:

Post a Comment