]> git.openstreetmap.org Git - rails.git/commitdiff
Fix tests to cope with stricter route enforcement in rails 2.3.6
authorTom Hughes <tom@compton.nu>
Mon, 18 Jun 2012 12:03:03 +0000 (13:03 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 18 Jun 2012 12:03:03 +0000 (13:03 +0100)
test/functional/browse_controller_test.rb
test/functional/changeset_controller_test.rb
test/functional/diary_entry_controller_test.rb
test/functional/message_controller_test.rb
test/functional/old_node_controller_test.rb
test/functional/user_blocks_controller_test.rb

index df0bb0e41e047480ae1deb616279a045fe735b42..4cc19b2d66aa58ebaa6510cd59d91b0acb767591 100644 (file)
@@ -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) 
   # 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
     get type, {:id => id}
     assert_response :success
     assert_template type
index 59cabca5ec8d12be647fd60cbf0efa05e248a385..21cae1f000a9359aae37ccdf381f0727e6d7eef1 100644 (file)
@@ -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|
   # 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
   
     end
   end
   
@@ -234,15 +238,23 @@ class ChangesetControllerTest < ActionController::TestCase
     
     # First try to do it with no auth
     cs_ids.each do |id|
     
     # 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|
     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
 
     end
   end
 
index 0fa9ea97f276c9810dc41d262e78f750de203e26..88c2aeb9a4a2fd1612c8adc9741ef0d69efe0fa5 100644 (file)
@@ -235,7 +235,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
   def test_edit_diary_entry_i18n
     @request.cookies["_osm_username"] = users(:normal_user).display_name
 
   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
     assert_response :success
     assert_select "span[class=translation_missing]", false, "Missing translation in edit diary entry"
   end
index d673a812609a7681d1d92becab3426e891d70bd7..8cb00c048bc1fd2cf4a80b3b6e00d74e2a2ba216 100644 (file)
@@ -90,12 +90,6 @@ class MessageControllerTest < ActionController::TestCase
     assert_equal "Test message body", m.body
     assert_equal "markdown", m.body_format
 
     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
     # 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
     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
 
     # 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
     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
 
     # 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
     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
 
     # 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
     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
 
     # Asking to delete a message with a bogus ID should fail
     post :delete, :message_id => 99999
index ff776d67f48cf07529c755a4e33cf901d2bb1322..44edc06a2f7c6dc822a1530e3a37c1285f45227a 100644 (file)
@@ -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
   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
   
   ##
   end
   
   ##
index e3b786795f65ddf9889a858651ef48017c0d327a..29724592954b0814c2c5b6c361877ecf5765f05d 100644 (file)
@@ -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
   # 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
 
     # 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
     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
 
     # 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
   # 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
     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
     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
     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
     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
 
     # 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
     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
 
     # 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
   # 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"
 
     # 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
   # 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"
 
     # Asking for a list of blocks with a bogus user name should fail
     get :blocks_by, :display_name => "non_existent_user"