From: Tom Hughes Date: Mon, 18 Jun 2012 12:03:03 +0000 (+0100) Subject: Fix tests to cope with stricter route enforcement in rails 2.3.6 X-Git-Tag: live~6123 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/04017d0e7a827568f8124e92c0c53b265d23eb87 Fix tests to cope with stricter route enforcement in rails 2.3.6 --- diff --git a/test/functional/browse_controller_test.rb b/test/functional/browse_controller_test.rb index df0bb0e41..4cc19b2d6 100644 --- a/test/functional/browse_controller_test.rb +++ b/test/functional/browse_controller_test.rb @@ -124,12 +124,12 @@ class BrowseControllerTest < ActionController::TestCase # then we check that we get the correct 404 when a non-existant id is passed # then we check that it will get a successful response, when we do pass an id def browse_check(type, id) - get type - assert_response :not_found - assert_template 'not_found' - get type, {:id => -10} # we won't have an id that's negative - assert_response :not_found - assert_template 'not_found' + assert_raise ActionController::RoutingError do + get type + end + assert_raise ActionController::RoutingError do + get type, {:id => -10} # we won't have an id that's negative + end get type, {:id => id} assert_response :success assert_template type diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 59cabca5e..21cae1f00 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -172,8 +172,12 @@ class ChangesetControllerTest < ActionController::TestCase # check that a changeset that doesn't exist returns an appropriate message def test_read_not_found [0, -32, 233455644, "afg", "213"].each do |id| - get :read, :id => id - assert_response :not_found, "should get a not found" + begin + get :read, :id => id + assert_response :not_found, "should get a not found" + rescue ActionController::RoutingError => ex + assert_match /No route matches/, ex.to_s + end end end @@ -234,15 +238,23 @@ class ChangesetControllerTest < ActionController::TestCase # First try to do it with no auth cs_ids.each do |id| - put :close, :id => id - assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized" + begin + put :close, :id => id + assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized" + rescue ActionController::RoutingError => ex + assert_match /No route matches/, ex.to_s + end end # Now try with auth basic_authorization users(:public_user).email, "test" cs_ids.each do |id| - put :close, :id => id - assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed" + begin + put :close, :id => id + assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed" + rescue ActionController::RoutingError => ex + assert_match /No route matches/, ex.to_s + end end end diff --git a/test/functional/diary_entry_controller_test.rb b/test/functional/diary_entry_controller_test.rb index 0fa9ea97f..88c2aeb9a 100644 --- a/test/functional/diary_entry_controller_test.rb +++ b/test/functional/diary_entry_controller_test.rb @@ -235,7 +235,7 @@ class DiaryEntryControllerTest < ActionController::TestCase def test_edit_diary_entry_i18n @request.cookies["_osm_username"] = users(:normal_user).display_name - get(:edit, {:id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id}) + get :edit, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id}, {'user' => users(:normal_user).id} assert_response :success assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry" end diff --git a/test/functional/message_controller_test.rb b/test/functional/message_controller_test.rb index d673a8126..8cb00c048 100644 --- a/test/functional/message_controller_test.rb +++ b/test/functional/message_controller_test.rb @@ -90,12 +90,6 @@ class MessageControllerTest < ActionController::TestCase assert_equal "Test message body", m.body assert_equal "markdown", m.body_format - # Asking to send a message with no user name should fail - get :new - assert_response :not_found - assert_template "user/no_such_user" - assert_select "h2", "The user does not exist" - # Asking to send a message with a bogus user name should fail get :new, :display_name => "non_existent_user" assert_response :not_found @@ -135,9 +129,9 @@ class MessageControllerTest < ActionController::TestCase end # Asking to reply to a message with no ID should fail - get :reply - assert_response :not_found - assert_template "no_such_message" + assert_raise ActionController::RoutingError do + get :reply + end # Asking to reply to a message with a bogus ID should fail get :reply, :message_id => 99999 @@ -182,9 +176,9 @@ class MessageControllerTest < ActionController::TestCase assert_equal true, Message.find(messages(:unread_message).id).message_read # Asking to read a message with no ID should fail - get :read - assert_response :not_found - assert_template "no_such_message" + assert_raise ActionController::RoutingError do + get :read + end # Asking to read a message with a bogus ID should fail get :read, :message_id => 99999 @@ -285,9 +279,9 @@ class MessageControllerTest < ActionController::TestCase assert_equal false, Message.find(messages(:unread_message).id).message_read # Asking to mark a message with no ID should fail - post :mark - assert_response :not_found - assert_template "no_such_message" + assert_raise ActionController::RoutingError do + post :mark + end # Asking to mark a message with a bogus ID should fail post :mark, :message_id => 99999 @@ -332,9 +326,9 @@ class MessageControllerTest < ActionController::TestCase assert_equal true, m.to_user_visible # Asking to delete a message with no ID should fail - post :delete - assert_response :not_found - assert_template "no_such_message" + assert_raise ActionController::RoutingError do + post :delete + end # Asking to delete a message with a bogus ID should fail post :delete, :message_id => 99999 diff --git a/test/functional/old_node_controller_test.rb b/test/functional/old_node_controller_test.rb index ff776d67f..44edc06a2 100644 --- a/test/functional/old_node_controller_test.rb +++ b/test/functional/old_node_controller_test.rb @@ -156,6 +156,8 @@ class OldNodeControllerTest < ActionController::TestCase def check_not_found_id_version(id, version) get :version, :id => id, :version => version assert_response :not_found + rescue ActionController::RoutingError => ex + assert_match /No route matches/, ex.to_s end ## diff --git a/test/functional/user_blocks_controller_test.rb b/test/functional/user_blocks_controller_test.rb index e3b786795..297245929 100644 --- a/test/functional/user_blocks_controller_test.rb +++ b/test/functional/user_blocks_controller_test.rb @@ -76,10 +76,9 @@ class UserBlocksControllerTest < ActionController::TestCase # test the show action def test_show # Viewing a block should fail when no ID is given - get :show - assert_response :not_found - assert_template "not_found" - assert_select "p", "Sorry, the user block with ID could not be found." + assert_raise ActionController::RoutingError do + get :show + end # Viewing a block should fail when a bogus ID is given get :show, :id => 99999 @@ -185,10 +184,9 @@ class UserBlocksControllerTest < ActionController::TestCase end # We should get an error if no user is specified - get :edit - assert_response :not_found - assert_template "not_found" - assert_select "p", "Sorry, the user block with ID could not be found." + assert_raise ActionController::RoutingError do + get :edit + end # We should get an error if the user doesn't exist get :edit, :id => 99999 @@ -260,7 +258,7 @@ class UserBlocksControllerTest < ActionController::TestCase # test the update action def test_update # Not logged in yet, so updating a block should fail - put :update + put :update, :id => user_blocks(:active_block).id assert_response :forbidden # Login as a normal user @@ -268,7 +266,7 @@ class UserBlocksControllerTest < ActionController::TestCase cookies["_osm_username"] = users(:public_user).display_name # Check that normal users can't update blocks - put :update + put :update, :id => user_blocks(:active_block).id assert_response :forbidden # Login as the wrong moderator @@ -313,10 +311,9 @@ class UserBlocksControllerTest < ActionController::TestCase assert_equal "Vandalism", b.reason # We should get an error if no block ID is specified - put :update - assert_response :not_found - assert_template "not_found" - assert_select "p", "Sorry, the user block with ID could not be found." + assert_raise ActionController::RoutingError do + put :update + end # We should get an error if the block doesn't exist put :update, :id => 99999 @@ -361,10 +358,9 @@ class UserBlocksControllerTest < ActionController::TestCase assert_in_delta Time.now, b.ends_at, 1 # We should get an error if no block ID is specified - get :revoke - assert_response :not_found - assert_template "not_found" - assert_select "p", "Sorry, the user block with ID could not be found." + assert_raise ActionController::RoutingError do + get :revoke + end # We should get an error if the block doesn't exist get :revoke, :id => 99999 @@ -377,10 +373,9 @@ class UserBlocksControllerTest < ActionController::TestCase # test the blocks_on action def test_blocks_on # Asking for a list of blocks with no user name should fail - get :blocks_on - assert_response :not_found - assert_template "user/no_such_user" - assert_select "h2", "The user does not exist" + assert_raise ActionController::RoutingError do + get :blocks_on + end # Asking for a list of blocks with a bogus user name should fail get :blocks_on, :display_name => "non_existent_user" @@ -416,10 +411,9 @@ class UserBlocksControllerTest < ActionController::TestCase # test the blocks_by action def test_blocks_by # Asking for a list of blocks with no user name should fail - get :blocks_by - assert_response :not_found - assert_template "user/no_such_user" - assert_select "h2", "The user does not exist" + assert_raise ActionController::RoutingError do + get :blocks_by + end # Asking for a list of blocks with a bogus user name should fail get :blocks_by, :display_name => "non_existent_user"