]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/old_nodes_controller_test.rb
Merge remote-tracking branch 'upstream/pull/5666'
[rails.git] / test / controllers / api / old_nodes_controller_test.rb
index fb1ee16bc6058014dd5c8d7f9b778df209ec231f..0c5faa9f9c0be4f834fc269830631e731d0b67ba 100644 (file)
@@ -194,31 +194,31 @@ module Api
     end
 
     ##
     end
 
     ##
-    # test the redaction of an old version of a node, while not being
-    # authorised.
-    def test_redact_node_unauthorised
+    # test that, even as moderator, the current version of a node
+    # can't be redacted.
+    def test_redact_node_current_version
       node = create(:node, :with_history, :version => 2)
       node = create(:node, :with_history, :version => 2)
-      old_node = node.old_nodes.find_by(:version => 1)
+      old_node = node.old_nodes.find_by(:version => 2)
       redaction = create(:redaction)
       redaction = create(:redaction)
+      auth_header = bearer_authorization_header create(:moderator_user)
 
 
-      post node_version_redact_path(*old_node.id), :params => { :redaction => redaction.id }
+      post node_version_redact_path(*old_node.id), :params => { :redaction => redaction.id }, :headers => auth_header
 
 
-      assert_response :unauthorized, "should need to be authenticated to redact."
+      assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
       assert_nil old_node.reload.redaction
     end
 
     ##
       assert_nil old_node.reload.redaction
     end
 
     ##
-    # test that, even as moderator, the current version of a node
-    # can't be redacted.
-    def test_redact_node_current_version
+    # test the redaction of an old version of a node, while not being
+    # authorised.
+    def test_redact_node_unauthorised
       node = create(:node, :with_history, :version => 2)
       node = create(:node, :with_history, :version => 2)
-      old_node = node.old_nodes.find_by(:version => 2)
+      old_node = node.old_nodes.find_by(:version => 1)
       redaction = create(:redaction)
       redaction = create(:redaction)
-      auth_header = bearer_authorization_header create(:moderator_user)
 
 
-      post node_version_redact_path(*old_node.id), :params => { :redaction => redaction.id }, :headers => auth_header
+      post node_version_redact_path(*old_node.id), :params => { :redaction => redaction.id }
 
 
-      assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
+      assert_response :unauthorized, "should need to be authenticated to redact."
       assert_nil old_node.reload.redaction
     end
 
       assert_nil old_node.reload.redaction
     end
 
@@ -289,12 +289,11 @@ module Api
     # test the unredaction of an old version of a node, while being
     # authorised as a normal user.
     def test_unredact_node_normal_user
     # test the unredaction of an old version of a node, while being
     # authorised as a normal user.
     def test_unredact_node_normal_user
-      user = create(:user)
       node = create(:node, :with_history, :version => 2)
       old_node = node.old_nodes.find_by(:version => 1)
       redaction = create(:redaction)
       old_node.redact!(redaction)
       node = create(:node, :with_history, :version => 2)
       old_node = node.old_nodes.find_by(:version => 1)
       redaction = create(:redaction)
       old_node.redact!(redaction)
-      auth_header = bearer_authorization_header user
+      auth_header = bearer_authorization_header
 
       post node_version_redact_path(*old_node.id), :headers => auth_header
 
 
       post node_version_redact_path(*old_node.id), :headers => auth_header
 
@@ -306,11 +305,10 @@ module Api
     # test the unredaction of an old version of a node, while being
     # authorised as a moderator.
     def test_unredact_node_moderator
     # test the unredaction of an old version of a node, while being
     # authorised as a moderator.
     def test_unredact_node_moderator
-      moderator_user = create(:moderator_user)
       node = create(:node, :with_history, :version => 2)
       old_node = node.old_nodes.find_by(:version => 1)
       old_node.redact!(create(:redaction))
       node = create(:node, :with_history, :version => 2)
       old_node = node.old_nodes.find_by(:version => 1)
       old_node.redact!(create(:redaction))
-      auth_header = bearer_authorization_header moderator_user
+      auth_header = bearer_authorization_header create(:moderator_user)
 
       post node_version_redact_path(*old_node.id), :headers => auth_header
 
 
       post node_version_redact_path(*old_node.id), :headers => auth_header