I have the following code in a micropost_spec.rb:
before(:each) do
@user = Factory :user
@attr = { :paragraphs => 4, :characters => 1000, :summary => "Recap of Event" }
end
it "should create a new instance given valid attributes" do
@user.microposts.create!(@attr)
end
And when I run my tests, I get the following error:
Failure/Error: @user.microposts.create!(@attr)
ActiveRecord::RecordInvalid:
Validation failed: Id can't be blank
Is it possible to see if the id is set inside the rails console?
Your model is probably trying to validate that
idis present with something likevalidates_presence_of :idorvalidates :id, :presence => true. You shouldn’t do that, as validations on new records are always run before the record is saved to the database and assigned an id.