X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6e5240e1987a429e29d230e811af9176772a8228..21683db838d66d5b14da08dd5fd467fae09515d4:/test/controllers/old_node_controller_test.rb?ds=inline diff --git a/test/controllers/old_node_controller_test.rb b/test/controllers/old_node_controller_test.rb index 0fcc46310..e08fbb65e 100644 --- a/test/controllers/old_node_controller_test.rb +++ b/test/controllers/old_node_controller_test.rb @@ -2,8 +2,6 @@ require "test_helper" require "old_node_controller" class OldNodeControllerTest < ActionController::TestCase - api_fixtures - # # TODO: test history # @@ -42,7 +40,7 @@ class OldNodeControllerTest < ActionController::TestCase propagate_tags(node, node.old_nodes.last) ## First try this with a non-public user - basic_authorization(private_user.email, "test") + basic_authorization private_user.email, "test" # setup a simple XML node xml_doc = private_node.to_xml @@ -63,7 +61,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_node["lon"] = precision(rand * 360 - 180).to_s with_controller(NodeController.new) do content xml_doc - put :update, :id => nodeid + put :update, :params => { :id => nodeid } assert_response :forbidden, "Should have rejected node update" xml_node["version"] = @response.body.to_s end @@ -79,7 +77,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_node << xml_tag with_controller(NodeController.new) do content xml_doc - put :update, :id => nodeid + put :update, :params => { :id => nodeid } assert_response :forbidden, "should have rejected node #{nodeid} (#{@response.body}) with forbidden" xml_node["version"] = @response.body.to_s @@ -91,7 +89,7 @@ class OldNodeControllerTest < ActionController::TestCase # probably should check that they didn't get written to the database ## Now do it with the public user - basic_authorization(user.email, "test") + basic_authorization user.email, "test" # setup a simple XML node @@ -113,7 +111,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_node["lon"] = precision(rand * 360 - 180).to_s with_controller(NodeController.new) do content xml_doc - put :update, :id => nodeid + put :update, :params => { :id => nodeid } assert_response :success xml_node["version"] = @response.body.to_s end @@ -129,7 +127,7 @@ class OldNodeControllerTest < ActionController::TestCase xml_node << xml_tag with_controller(NodeController.new) do content xml_doc - put :update, :id => nodeid + put :update, :params => { :id => nodeid } assert_response :success, "couldn't update node #{nodeid} (#{@response.body})" xml_node["version"] = @response.body.to_s @@ -139,8 +137,8 @@ class OldNodeControllerTest < ActionController::TestCase end # check all the versions - versions.keys.each do |key| - get :version, :id => nodeid, :version => key.to_i + versions.each_key do |key| + get :version, :params => { :id => nodeid, :version => key.to_i } assert_response :success, "couldn't get version #{key.to_i} of node #{nodeid}" @@ -160,7 +158,7 @@ class OldNodeControllerTest < ActionController::TestCase end def check_not_found_id_version(id, version) - get :version, :id => id, :version => version + get :version, :params => { :id => id, :version => version } assert_response :not_found rescue ActionController::UrlGenerationError => ex assert_match /No route matches/, ex.to_s @@ -208,7 +206,7 @@ class OldNodeControllerTest < ActionController::TestCase # test the redaction of an old version of a node, while being # authorised as a normal user. def test_redact_node_normal_user - basic_authorization(create(:user).email, "test") + basic_authorization create(:user).email, "test" node = create(:node, :with_history, :version => 4) node_v3 = node.old_nodes.find_by(:version => 3) @@ -222,7 +220,7 @@ class OldNodeControllerTest < ActionController::TestCase # test that, even as moderator, the current version of a node # can't be redacted. def test_redact_node_current_version - basic_authorization(create(:moderator_user).email, "test") + basic_authorization create(:moderator_user).email, "test" node = create(:node, :with_history, :version => 4) node_v4 = node.old_nodes.find_by(:version => 4) @@ -240,12 +238,12 @@ class OldNodeControllerTest < ActionController::TestCase node_v1 = node.old_nodes.find_by(:version => 1) node_v1.redact!(create(:redaction)) - get :version, :id => node_v1.node_id, :version => node_v1.version + get :version, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :forbidden, "Redacted node shouldn't be visible via the version API." # not even to a logged-in user - basic_authorization(create(:user).email, "test") - get :version, :id => node_v1.node_id, :version => node_v1.version + basic_authorization create(:user).email, "test" + get :version, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in." end @@ -256,13 +254,13 @@ class OldNodeControllerTest < ActionController::TestCase node_v1 = node.old_nodes.find_by(:version => 1) node_v1.redact!(create(:redaction)) - get :history, :id => node_v1.node_id + get :history, :params => { :id => node_v1.node_id } assert_response :success, "Redaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history." # not even to a logged-in user - basic_authorization(create(:user).email, "test") - get :history, :id => node_v1.node_id + basic_authorization create(:user).email, "test" + get :history, :params => { :id => node_v1.node_id } assert_response :success, "Redaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in." end @@ -273,23 +271,23 @@ class OldNodeControllerTest < ActionController::TestCase def test_redact_node_moderator node = create(:node, :with_history, :version => 4) node_v3 = node.old_nodes.find_by(:version => 3) - basic_authorization(create(:moderator_user).email, "test") + basic_authorization create(:moderator_user).email, "test" do_redact_node(node_v3, create(:redaction)) assert_response :success, "should be OK to redact old version as moderator." # check moderator can still see the redacted data, when passing # the appropriate flag - get :version, :id => node_v3.node_id, :version => node_v3.version + get :version, :params => { :id => node_v3.node_id, :version => node_v3.version } assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed." - get :version, :id => node_v3.node_id, :version => node_v3.version, :show_redactions => "true" + get :version, :params => { :id => node_v3.node_id, :version => node_v3.version, :show_redactions => "true" } assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." # and when accessed via history - get :history, :id => node_v3.node_id + get :history, :params => { :id => node_v3.node_id } assert_response :success, "Redaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag." - get :history, :id => node_v3.node_id, :show_redactions => "true" + get :history, :params => { :id => node_v3.node_id, :show_redactions => "true" } assert_response :success, "Redaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1, "node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag." end @@ -299,20 +297,20 @@ class OldNodeControllerTest < ActionController::TestCase def test_redact_node_is_redacted node = create(:node, :with_history, :version => 4) node_v3 = node.old_nodes.find_by(:version => 3) - basic_authorization(create(:moderator_user).email, "test") + basic_authorization create(:moderator_user).email, "test" do_redact_node(node_v3, create(:redaction)) assert_response :success, "should be OK to redact old version as moderator." # re-auth as non-moderator - basic_authorization(create(:user).email, "test") + basic_authorization create(:user).email, "test" # check can't see the redacted data - get :version, :id => node_v3.node_id, :version => node_v3.version + get :version, :params => { :id => node_v3.node_id, :version => node_v3.version } assert_response :forbidden, "Redacted node shouldn't be visible via the version API." # and when accessed via history - get :history, :id => node_v3.node_id + get :history, :params => { :id => node_v3.node_id } assert_response :success, "Redaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history." end @@ -325,7 +323,7 @@ class OldNodeControllerTest < ActionController::TestCase node_v1 = node.old_nodes.find_by(:version => 1) node_v1.redact!(create(:redaction)) - post :redact, :id => node_v1.node_id, :version => node_v1.version + post :redact, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :unauthorized, "should need to be authenticated to unredact." end @@ -338,9 +336,9 @@ class OldNodeControllerTest < ActionController::TestCase node_v1 = node.old_nodes.find_by(:version => 1) node_v1.redact!(create(:redaction)) - basic_authorization(user.email, "test") + basic_authorization user.email, "test" - post :redact, :id => node_v1.node_id, :version => node_v1.version + post :redact, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :forbidden, "should need to be moderator to unredact." end @@ -353,29 +351,29 @@ class OldNodeControllerTest < ActionController::TestCase node_v1 = node.old_nodes.find_by(:version => 1) node_v1.redact!(create(:redaction)) - basic_authorization(moderator_user.email, "test") + basic_authorization moderator_user.email, "test" - post :redact, :id => node_v1.node_id, :version => node_v1.version + post :redact, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :success, "should be OK to unredact old version as moderator." # check moderator can now see the redacted data, when not # passing the aspecial flag - get :version, :id => node_v1.node_id, :version => node_v1.version + get :version, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :success, "After unredaction, node should not be gone for moderator." # and when accessed via history - get :history, :id => node_v1.node_id + get :history, :params => { :id => node_v1.node_id } assert_response :success, "Unredaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag." - basic_authorization(create(:user).email, "test") + basic_authorization create(:user).email, "test" # check normal user can now see the redacted data - get :version, :id => node_v1.node_id, :version => node_v1.version + get :version, :params => { :id => node_v1.node_id, :version => node_v1.version } assert_response :success, "After unredaction, node should be visible to normal users." # and when accessed via history - get :history, :id => node_v1.node_id + get :history, :params => { :id => node_v1.node_id } assert_response :success, "Unredaction shouldn't have stopped history working." assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag." end @@ -383,24 +381,24 @@ class OldNodeControllerTest < ActionController::TestCase private def do_redact_node(node, redaction) - get :version, :id => node.node_id, :version => node.version + get :version, :params => { :id => node.node_id, :version => node.version } assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}." # now redact it - post :redact, :id => node.node_id, :version => node.version, :redaction => redaction.id + post :redact, :params => { :id => node.node_id, :version => node.version, :redaction => redaction.id } end def check_current_version(node_id) # get the current version of the node current_node = with_controller(NodeController.new) do - get :read, :id => node_id + get :read, :params => { :id => node_id } assert_response :success, "cant get current node #{node_id}" Node.from_xml(@response.body) end assert_not_nil current_node, "getting node #{node_id} returned nil" # get the "old" version of the node from the old_node interface - get :version, :id => node_id, :version => current_node.version + get :version, :params => { :id => node_id, :version => current_node.version } assert_response :success, "cant get old node #{node_id}, v#{current_node.version}" old_node = Node.from_xml(@response.body)