]> git.openstreetmap.org Git - rails.git/commitdiff
Check old element state instead of responses in unredaction tests
authorAnton Khorev <tony29@yandex.ru>
Mon, 10 Feb 2025 15:44:05 +0000 (18:44 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 10 Feb 2025 23:08:28 +0000 (02:08 +0300)
test/controllers/api/old_nodes_controller_test.rb
test/controllers/api/old_relations_controller_test.rb
test/controllers/api/old_ways_controller_test.rb

index bddc6bc24920d2a5109184e0c8f9e15b90c71120..0f7227287adc2b5e02cb0051b534cdc67830f4f2 100644 (file)
@@ -269,10 +269,13 @@ module Api
     def test_unredact_node_unauthorised
       node = create(:node, :with_history, :version => 2)
       node_v1 = node.old_nodes.find_by(:version => 1)
-      node_v1.redact!(create(:redaction))
+      redaction = create(:redaction)
+      node_v1.redact!(redaction)
 
       post node_version_redact_path(node_v1.node_id, node_v1.version)
+
       assert_response :unauthorized, "should need to be authenticated to unredact."
+      assert_equal redaction, node_v1.reload.redaction
     end
 
     ##
@@ -282,12 +285,14 @@ module Api
       user = create(:user)
       node = create(:node, :with_history, :version => 2)
       node_v1 = node.old_nodes.find_by(:version => 1)
-      node_v1.redact!(create(:redaction))
-
+      redaction = create(:redaction)
+      node_v1.redact!(redaction)
       auth_header = bearer_authorization_header user
 
       post node_version_redact_path(node_v1.node_id, node_v1.version), :headers => auth_header
+
       assert_response :forbidden, "should need to be moderator to unredact."
+      assert_equal redaction, node_v1.reload.redaction
     end
 
     ##
@@ -298,34 +303,12 @@ module Api
       node = create(:node, :with_history, :version => 2)
       node_v1 = node.old_nodes.find_by(:version => 1)
       node_v1.redact!(create(:redaction))
-
       auth_header = bearer_authorization_header moderator_user
 
       post node_version_redact_path(node_v1.node_id, node_v1.version), :headers => auth_header
-      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 api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
-      assert_response :success, "After unredaction, node should not be gone for moderator."
-
-      # and when accessed via history
-      get api_node_versions_path(node)
-      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."
 
-      auth_header = bearer_authorization_header
-
-      # check normal user can now see the redacted data
-      get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
-      assert_response :success, "After unredaction, node should be visible to normal users."
-
-      # and when accessed via history
-      get api_node_versions_path(node)
-      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."
+      assert_response :success, "should be OK to unredact old version as moderator."
+      assert_nil node_v1.reload.redaction
     end
 
     private
index d7aa923ec485a57581ddf4d092dabeca6ebc1377..a874232bdd3b4a28fcf4af7148a0235f55ad796e 100644 (file)
@@ -260,10 +260,13 @@ module Api
     def test_unredact_relation_unauthorised
       relation = create(:relation, :with_history, :version => 2)
       relation_v1 = relation.old_relations.find_by(:version => 1)
-      relation_v1.redact!(create(:redaction))
+      redaction = create(:redaction)
+      relation_v1.redact!(redaction)
 
       post relation_version_redact_path(relation_v1.relation_id, relation_v1.version)
+
       assert_response :unauthorized, "should need to be authenticated to unredact."
+      assert_equal redaction, relation_v1.reload.redaction
     end
 
     ##
@@ -272,12 +275,14 @@ module Api
     def test_unredact_relation_normal_user
       relation = create(:relation, :with_history, :version => 2)
       relation_v1 = relation.old_relations.find_by(:version => 1)
-      relation_v1.redact!(create(:redaction))
-
+      redaction = create(:redaction)
+      relation_v1.redact!(redaction)
       auth_header = bearer_authorization_header
 
       post relation_version_redact_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
+
       assert_response :forbidden, "should need to be moderator to unredact."
+      assert_equal redaction, relation_v1.reload.redaction
     end
 
     ##
@@ -287,34 +292,12 @@ module Api
       relation = create(:relation, :with_history, :version => 2)
       relation_v1 = relation.old_relations.find_by(:version => 1)
       relation_v1.redact!(create(:redaction))
-
       auth_header = bearer_authorization_header create(:moderator_user)
 
       post relation_version_redact_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
-      assert_response :success, "should be OK to unredact old version as moderator."
-
-      # check moderator can still see the redacted data, without passing
-      # the appropriate flag
-      get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
-      assert_response :success, "After unredaction, relation should not be gone for moderator."
 
-      # and when accessed via history
-      get api_relation_versions_path(relation), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
-                    "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
-
-      auth_header = bearer_authorization_header
-
-      # check normal user can now see the redacted data
-      get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
-      assert_response :success, "After redaction, node should not be gone for normal user."
-
-      # and when accessed via history
-      get api_relation_versions_path(relation), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1,
-                    "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
+      assert_response :success, "should be OK to unredact old version as moderator."
+      assert_nil relation_v1.reload.redaction
     end
 
     private
index d7e6091ca5917b0689cc365b49b0ced088dfc255..5dc1c9cfc56ed7ae7b650fca60b258e8b4be4fe4 100644 (file)
@@ -271,10 +271,13 @@ module Api
     def test_unredact_way_unauthorised
       way = create(:way, :with_history, :version => 2)
       way_v1 = way.old_ways.find_by(:version => 1)
-      way_v1.redact!(create(:redaction))
+      redaction = create(:redaction)
+      way_v1.redact!(redaction)
 
       post way_version_redact_path(way_v1.way_id, way_v1.version)
+
       assert_response :unauthorized, "should need to be authenticated to unredact."
+      assert_equal redaction, way_v1.reload.redaction
     end
 
     ##
@@ -283,12 +286,14 @@ module Api
     def test_unredact_way_normal_user
       way = create(:way, :with_history, :version => 2)
       way_v1 = way.old_ways.find_by(:version => 1)
-      way_v1.redact!(create(:redaction))
-
+      redaction = create(:redaction)
+      way_v1.redact!(redaction)
       auth_header = bearer_authorization_header
 
       post way_version_redact_path(way_v1.way_id, way_v1.version), :headers => auth_header
+
       assert_response :forbidden, "should need to be moderator to unredact."
+      assert_equal redaction, way_v1.reload.redaction
     end
 
     ##
@@ -299,34 +304,12 @@ module Api
       way = create(:way, :with_history, :version => 2)
       way_v1 = way.old_ways.find_by(:version => 1)
       way_v1.redact!(create(:redaction))
-
       auth_header = bearer_authorization_header moderator_user
 
       post way_version_redact_path(way_v1.way_id, way_v1.version), :headers => auth_header
-      assert_response :success, "should be OK to unredact old version as moderator."
 
-      # check moderator can still see the unredacted data, without passing
-      # the appropriate flag
-      get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
-      assert_response :success, "After unredaction, node should not be gone for moderator."
-
-      # and when accessed via history
-      get api_way_versions_path(way), :headers => auth_header
-      assert_response :success, "Unredaction shouldn't have stopped history working."
-      assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
-                    "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
-
-      auth_header = bearer_authorization_header
-
-      # check normal user can now see the unredacted data
-      get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
-      assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
-
-      # and when accessed via history
-      get api_way_versions_path(way), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1,
-                    "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
+      assert_response :success, "should be OK to unredact old version as moderator."
+      assert_nil way_v1.reload.redaction
     end
 
     private