Vahagn Hayrapetyan
2008-Oct-27 10:33 UTC
Functional test behaving oddly in a manually working model
Hello all,- wondering if you can help me with a weird testing problem. I have a Newsletter model that has been developed and tested in a previous version (older branch) of my current project. Under that old project, all tests run perfectly with no failures. Moreover, in the current project Newsletter behaves perfectly with manual tests - ie creating, deleting, editing newsletters by hand. When I run rake test:functionals however, the tests don''t do what they are supposed to. Here''s a method from NewslettersControllerTest: def test_should_create_newsletter puts "TESTING CREATE" login_as(:admin_user) #method in test_helper.rb puts "I am " + users(:admin_user).id.to_s #loads correct user from fixture! puts "My email: " + users(:admin_user).email #same, correct user old_count = Newsletter.count puts "Old count: " + old_count.to_s #1 post :create, :newsletter => { :subject => ''testing creating newsletter'', :body => ''Test'' } puts "Old count after create: " + old_count.to_s #1 #assert_equal old_count+1, Newsletter.count #fails puts "Newsletter count after create: " + Newsletter.count.to_s #1 AGAIN! #assert_redirected_to newsletter_path(assigns(:newsletter)) end And here''s the console output: Started ....TESTING CREATE I am 2 My email: admin-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org Old count: 1 Old count after create: 1 Newsletter count after create: 1 .FFFFFF.................... Finished in 3.518293 seconds. 1) Failure: test_should_destroy_newsletter(NewslettersControllerTest) [/Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:43:in `assert_difference'' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/routing/route.rb:48:in `each_with_index'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in `each'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in `each_with_index'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in `assert_difference'' ./test/functional/newsletters_controller_test.rb:58:in `test_should_destroy_newsletter'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run'']: <0> expected but was <1>. Can anyone see what is wrong here? Many thanks, Vahagn -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-27 10:37 UTC
Re: Functional test behaving oddly in a manually working model
On Oct 27, 10:33 am, Vahagn Hayrapetyan <rails-mailing-l...@andreas- s.net> wrote:> Hello all,- > > wondering if you can help me with a weird testing problem. I have a > Newsletter model that has been developed and tested in a previous > version (older branch) of my current project. Under that old project, > all tests run perfectly with no failures. Moreover, in the current > project Newsletter behaves perfectly with manual tests - ie creating, > deleting, editing newsletters by hand. > > When I run rake test:functionals however, the tests don''t do what they > are supposed to. Here''s a method from NewslettersControllerTest:Have you tried looking a little closer at why its failing ? Eg stick a breakpoint in the action and see what happens. If the action doesn''t run at all because of some filter (eg authentication - are you sure your login_as method works ?) then there will be a note in test.log Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vahagn Hayrapetyan
2008-Oct-27 10:39 UTC
Re: Functional test behaving oddly in a manually working model
PS! The "Failure" console output above is for the wrong test (as the assertion was commented out in test_create_newsletter). Here''s the right output: 1) Failure: test_should_create_newsletter(NewslettersControllerTest) [./test/functional/newsletters_controller_test.rb:33:in `test_should_create_newsletter'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `__send__'' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in `run'']: <2> expected but was <1>. / Vahagn Vahagn Hayrapetyan wrote:> Hello all,- > > wondering if you can help me with a weird testing problem. I have a > Newsletter model that has been developed and tested in a previous > version (older branch) of my current project. Under that old project, > all tests run perfectly with no failures. Moreover, in the current > project Newsletter behaves perfectly with manual tests - ie creating, > deleting, editing newsletters by hand. > > When I run rake test:functionals however, the tests don''t do what they > are supposed to. Here''s a method from NewslettersControllerTest: > > def test_should_create_newsletter > puts "TESTING CREATE" > login_as(:admin_user) #method in test_helper.rb > puts "I am " + users(:admin_user).id.to_s #loads correct user from > fixture! > puts "My email: " + users(:admin_user).email #same, correct user > old_count = Newsletter.count > puts "Old count: " + old_count.to_s #1 > post :create, :newsletter => { :subject => ''testing creating > newsletter'', :body => ''Test'' } > puts "Old count after create: " + old_count.to_s #1 > #assert_equal old_count+1, Newsletter.count #fails > puts "Newsletter count after create: " + Newsletter.count.to_s #1 > AGAIN! > #assert_redirected_to newsletter_path(assigns(:newsletter)) > end > > And here''s the console output: > > Started > ....TESTING CREATE > I am 2 > My email: admin-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org > Old count: 1 > Old count after create: 1 > Newsletter count after create: 1 > .FFFFFF.................... > Finished in 3.518293 seconds. > > 1) Failure: > test_should_destroy_newsletter(NewslettersControllerTest) > [/Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:43:in > `assert_difference'' > /Library/Ruby/Gems/1.8/gems/actionpack-2.1.1/lib/action_controller/routing/route.rb:48:in > `each_with_index'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in > `each'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in > `each_with_index'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/core_ext/test/unit/assertions.rb:42:in > `assert_difference'' > ./test/functional/newsletters_controller_test.rb:58:in > `test_should_destroy_newsletter'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in > `__send__'' > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:33:in > `run'']: > <0> expected but was > <1>. > > > Can anyone see what is wrong here? > > Many thanks, Vahagn-- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Vahagn Hayrapetyan
2008-Oct-27 10:43 UTC
Re: Functional test behaving oddly in a manually working model
Hi Fred,- login_as works in all other tests! And I actually test it by the puts statements, it works because I can see the admin_user''s id is 2, and email is admin-hcDgGtZH8xPowKkBSvOlow@public.gmane.org This means that login_as works by loading that user from the fixture: admin_user: id: 2 username: admin email: admin-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org hashed_password: #very long hash created_at: <%= 1.days.ago.to_s(:db) %> / Vahagn Frederick Cheung wrote:> On Oct 27, 10:33�am, Vahagn Hayrapetyan <rails-mailing-l...@andreas- > s.net> wrote: >> are supposed to. Here''s a method from NewslettersControllerTest: > Have you tried looking a little closer at why its failing ? Eg stick a > breakpoint in the action and see what happens. If the action doesn''t > run at all because of some filter (eg authentication - are you sure > your login_as method works ?) then there will be a note in test.log > > Fred-- Posted via http://www.ruby-forum.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-27 11:14 UTC
Re: Functional test behaving oddly in a manually working model
On 27 Oct 2008, at 10:43, Vahagn Hayrapetyan wrote:> > Hi Fred,- > > login_as works in all other tests! And I actually test it by the puts > statements, it works because I can see the admin_user''s id is 2, and > email is admin-hcDgGtZH8xPowKkBSvOlow@public.gmane.org This means that login_as works by loading > that user from the fixture: >Fair enough (although you''re not actually testing that it works, just that that fixture exists, which is different from whether the session has been faked up properly or something like that). I''d still check your logs to see if some filter or something is stopping your action from running. Another possibility is a validation failure. Fred> admin_user: > id: 2 > username: admin > email: admin-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org > hashed_password: #very long hash > created_at: <%= 1.days.ago.to_s(:db) %> > > / Vahagn > > Frederick Cheung wrote: >> On Oct 27, 10:33�am, Vahagn Hayrapetyan <rails-mailing- >> l...@andreas- >> s.net> wrote: >>> are supposed to. Here''s a method from NewslettersControllerTest: >> Have you tried looking a little closer at why its failing ? Eg >> stick a >> breakpoint in the action and see what happens. If the action doesn''t >> run at all because of some filter (eg authentication - are you sure >> your login_as method works ?) then there will be a note in test.log >> >> Fred > > -- > Posted via http://www.ruby-forum.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 > -~----------~----~----~----~------~----~------~--~--- >
Vahagn Hayrapetyan
2008-Oct-27 11:33 UTC
Re: Functional test behaving oddly in a manually working model
SOLVED! Fred, thanks a ton. There was another fixture, roles_users, that I forgot to import from the old project. Which resulted in the test skipping the create method because of invalid user authentication. I arrived at that by placing a breakpoint in the controller (create), and by examining the test log (great tip, sure to become a habit!) All the best, Vahagn Frederick Cheung wrote:> On 27 Oct 2008, at 10:43, Vahagn Hayrapetyan wrote: > >> >> Hi Fred,- >> >> login_as works in all other tests! And I actually test it by the puts >> statements, it works because I can see the admin_user''s id is 2, and >> email is admin-hcDgGtZH8xPowKkBSvOlow@public.gmane.org This means that login_as works by loading >> that user from the fixture: >> > Fair enough (although you''re not actually testing that it works, just > that that fixture exists, which is different from whether the session > has been faked up properly or something like that). > I''d still check your logs to see if some filter or something is > stopping your action from running. Another possibility is a validation > failure. > > Fred-- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---