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@example.com 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