paulelliott / fabrication

This project has moved to GitLab! Please check there for the latest updates.
https://gitlab.com/fabrication-gem/fabrication
MIT License
998 stars 97 forks source link

ActiveRecord::AssociationTypeMismatch Rails 5.0.0.1 #283

Closed arowan closed 8 years ago

arowan commented 8 years ago

My fabricator

Fabricator(:message) do
  user
  subject { Faker::Lorem.sentence }
  body { Faker::Lorem.paragraph }
end
let(:message_attributes) { Fabricate.attributes_for(:message, user: nil) }

I'm setting user to nil and it's throwing this error:

ActiveRecord::AssociationTypeMismatch:
       User(#70254248807040) expected, got String(#70254193623120)
<ActionController::Parameters {"message"=>{"body"=>"Odit consectetur est exercitationem delectus placeat corrupti. Commodi ut et suscipit.", "subject"=>"Porro odio voluptates.", "user"=>""}, "format"=>"json", "controller"=>"internal/messages", "action"=>"create"} permitted: false>

It looks like it's returning user as a blank string. Maybe I'm going about this the wrong way?

arowan commented 8 years ago

The Fabrication gem is working properly and returning a nil value. It's something else, so I've closed this issue.