We have a fairly simple model that appears to be throwing an error
when using unit tests, but we don’t know why. Seems to work well
enough from our controllers just throws the error in test.
We have a table that contains a field called user_id that holds the ID
of the user who created the post. The definition is:
t.column “user_id”, :integer, :null => false
The post model belongs to :user and user has_many :posts
This works fine except for unit tests, for some bizzare reason. When
we perform a simple unit test like
post = Post.create(:user => users(:spanogebob)) assert !post.valid?
which should assert to true since the body of the post will be blank,
which is not allowed. However, what we get is a MySQL error:
Field ‘user_id’ doesn’t have a default value: Insert into
‘posts’ (‘id’) values (2)
Anyone have any idea why this is happening.
Thanks in advance