- # for some reason a==b is false, but there doesn't seem to be any
- # difference between the nodes, so i'm checking all the attributes
- # manually and blaming it on ActiveRecord
- def assert_nodes_are_equal(a, b)
- assert_equal a.id, b.id, "node IDs"
- assert_equal a.latitude, b.latitude, "latitude"
- assert_equal a.longitude, b.longitude, "longitude"
- assert_equal a.changeset_id, b.changeset_id, "changeset ID"
- assert_equal a.visible, b.visible, "visible"
- assert_equal a.version, b.version, "version"
- assert_equal a.tags, b.tags, "tags"
+ # test the redaction of an old version of a node, while being
+ # authorised as a moderator.
+ def test_redact_node_moderator
+ node = nodes(:node_with_versions_v3)
+ basic_authorization(users(:moderator_user).email, "test")
+
+ do_redact_node(node, redactions(:example))
+ 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.node_id, :version => node.version
+ assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
+ get :version, :id => node.node_id, :version => node.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.node_id
+ assert_response :success, "Redaction shouldn't have stopped history working."
+ assert_select "osm node[id=#{node.node_id}][version=#{node.version}]", 0, "node #{node.node_id} version #{node.version} should not be present in the history for moderators when not passing flag."
+ get :history, :id => node.node_id, :show_redactions => 'true'
+ assert_response :success, "Redaction shouldn't have stopped history working."
+ assert_select "osm node[id=#{node.node_id}][version=#{node.version}]", 1, "node #{node.node_id} version #{node.version} should still be present in the history for moderators when passing flag."
+ end
+
+ # testing that if the moderator drops auth, he can't see the
+ # redacted stuff any more.
+ def test_redact_node_is_redacted
+ node = nodes(:node_with_versions_v3)
+ basic_authorization(users(:moderator_user).email, "test")
+
+ do_redact_node(node, redactions(:example))
+ assert_response :success, "should be OK to redact old version as moderator."
+
+ # re-auth as non-moderator
+ basic_authorization(users(:public_user).email, "test")
+
+ # check can't see the redacted data
+ get :version, :id => node.node_id, :version => node.version
+ assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
+
+ # and when accessed via history
+ get :history, :id => node.node_id
+ assert_response :success, "Redaction shouldn't have stopped history working."
+ assert_select "osm node[id=#{node.node_id}][version=#{node.version}]", 0, "redacted node #{node.node_id} version #{node.version} shouldn't be present in the history."
+ end
+
+ def do_redact_node(node, redaction)
+ get :version, :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
+ 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
+ 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
+ assert_response :success, "cant get old node #{node_id}, v#{current_node.version}"
+ old_node = Node.from_xml(@response.body)
+
+ # check the nodes are the same
+ assert_nodes_are_equal current_node, old_node