Hi, I have a question about testing ... It''s controller test ... First I do something like this: xhr :get, :status, :id => homeworks(:one).id, :status => "done" The :status action sets homework''s length_done to length. So I do this: assert = homeworks(:one).length == homeworks(:one).length_done But this test doesn''t pass, while this one: assert assigns(:homework).length == assigns(:homework).length_done Passes. Why? If I do request - doesn''t the object from fixtures get updated? --~--~---------~--~----~------------~-------~--~----~ 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. Fixtures are fixed. Do this: original_homework = homeworks(:one) xhr :get, :status, :id => original_homework.id, :status => "done" changed_homework = assigns(:homework) # get it from the controller''s instance # now compare original_homework and changed_homework. I don''t know what you''re really trying to test here, but this sounds like business logic. The controller should pass parameters to a fully-tested model so your controller tests really should be testing for how the controller handles "it worked" vs "it didn''t work". The details of what gets set should be covered in a unit test. test "it should show a success message when created successfully do end test "it should show an error message when not created successfully" do end HTH -Brian On Wed, Feb 4, 2009 at 9:06 AM, zero0x <zero0xxx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I have a question about testing ... > > It''s controller test ... > > First I do something like this: > > xhr :get, :status, :id => homeworks(:one).id, :status => "done" > > The :status action sets homework''s length_done to length. > > So I do this: > > assert = homeworks(:one).length == homeworks(:one).length_done > > But this test doesn''t pass, while this one: > > assert assigns(:homework).length == assigns(:homework).length_done > > Passes. Why? > > If I do request - doesn''t the object from fixtures get updated? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, OK I see, I wanted something like should be done after setting it done But I see that''s enough by checking assigns. On 4. Feb, 16:26 h., Brian Hogan <bpho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No. > > Fixtures are fixed. > > Do this: > > original_homework = homeworks(:one) > xhr :get, :status, :id => original_homework.id, :status => "done" > > changed_homework = assigns(:homework) # get it from the controller''s instance > > # now compare original_homework and changed_homework. > > I don''t know what you''re really trying to test here, but this sounds > like business logic. The controller should pass parameters to a > fully-tested model so your controller tests really should be testing > for how the controller handles "it worked" vs "it didn''t work". The > details of what gets set should be covered in a unit test. > > test "it should show a success message when created successfully do > > end > > test "it should show an error message when not created successfully" do > > end > > HTH > -Brian > > On Wed, Feb 4, 2009 at 9:06 AM, zero0x <zero0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I have a question about testing ... > > > It''s controller test ... > > > First I do something like this: > > > xhr :get, :status, :id => homeworks(:one).id, :status => "done" > > > The :status action sets homework''s length_done to length. > > > So I do this: > > > assert = homeworks(:one).length == homeworks(:one).length_done > > > But this test doesn''t pass, while this one: > > > assert assigns(:homework).length == assigns(:homework).length_done > > > Passes. Why? > > > If I do request - doesn''t the object from fixtures get updated?--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---