New to Ruby and to Rails (but not to development or testing). Perhaps I''m going about this wrong, but I''m writing a functional test of my controller. The controller makes changes to the item being operated on and saves those changes to the database. My test code doesn''t detect these changes unless I reload from the database, e.g.: def test_something foo = foos(:my_test_foo) post :update, :id => foo.id, :bar => "Some Data" assert_equal("Some Data",foo.bar) # FAILS foo = Foo.find(foo.id) assert_equal("Some Data",foo.bar) # PASSES end I don''t necessarily have a problem with this, but it made me wonder if I''m approaching testing the wrong way. Am I? Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 16, 9:43 pm, davetron5000 <davetron5...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> New to Ruby and to Rails (but not to development or testing). Perhaps > I''m going about this wrong, but I''m writing a functional test of my > controller. The controller makes changes to the item being operated > on and saves those changes to the database. My test code doesn''t > detect these changes unless I reload from the database, e.g.: >That''s the way it is. the controller will have been handling a different instance of Foo (that happens to correspond to the same row in the database). The instance in your test is not aware of what has been done to the other instance. Fred> def test_something > foo = foos(:my_test_foo) > post :update, :id => foo.id, :bar => "Some Data" > > assert_equal("Some Data",foo.bar) # FAILS > foo = Foo.find(foo.id) > assert_equal("Some Data",foo.bar) # PASSES > end > > I don''t necessarily have a problem with this, but it made me wonder if > I''m approaching testing the wrong way. Am I? > > Dave--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fred is correct. A small suggestion to your code. Instead of foo = Foo.find(foo.id) simply use foo.reload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---