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 def test_blank_post post = Post.create(:user => users(:spanogebob)) assert !post.valid? end 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 Dale --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Does post = Post.create(:user_id => users(:spanogebob).id) work for you? Jason On 5/16/07, PeteSalty <petesalty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 > > def test_blank_post > > post = Post.create(:user => users(:spanogebob)) > assert !post.valid? > > end > > 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 > Dale > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
No, unfortunately it''s the same if we do that. Dale On May 16, 1:56 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Does > > post = Post.create(:user_id => users(:spanogebob).id) > > work for you? > > Jason > > On 5/16/07, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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 > > > def test_blank_post > > > post = Post.create(:user => users(:spanogebob)) > > assert !post.valid? > > > end > > > 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 > > Dale--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wow, I''ve been on this for days now and can''t seem to work out where I''m going wrong. It must be something I''m doing wrong On May 16, 5:09 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No, unfortunately it''s the same if we do that. > > Dale > > On May 16, 1:56 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Does > > > post = Post.create(:user_id => users(:spanogebob).id) > > > work for you? > > > Jason > > > On 5/16/07, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 > > > > def test_blank_post > > > > post = Post.create(:user => users(:spanogebob)) > > > assert !post.valid? > > > > end > > > > 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 > > > Dale- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hmm. I guess you could write some tests proving that the has_many / belongs_to relationships exist and are working. Otherwise we''ll need to see code to help you out. Jason On 5/17/07, PeteSalty <petesalty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Wow, I''ve been on this for days now and can''t seem to work out where > I''m going wrong. > It must be something I''m doing wrong > > > On May 16, 5:09 pm, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > No, unfortunately it''s the same if we do that. > > > > Dale > > > > On May 16, 1:56 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Does > > > > > post = Post.create(:user_id => users(:spanogebob).id) > > > > > work for you? > > > > > Jason > > > > > On 5/16/07, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > 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 > > > > > > def test_blank_post > > > > > > post = Post.create(:user => users(:spanogebob)) > > > > assert !post.valid? > > > > > > end > > > > > > 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 > > > > Dale- Hide quoted text - > > > > - Show quoted text - > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pete, > post = Post.create(:user => users(:spanogebob)) > we get is a MySQL error: What happens where you don''t use fixtures but real objects : # fixtures .... don''t load any fixture at all # spongebox = User.create( ...) post = Post.create(:user => spanogebob) Alain Ravet -------- http://blog.ravet.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---