+
+ def test_not_found_version
+ check_not_found_id_version(70000,312344)
+ check_not_found_id_version(-1, -13)
+ check_not_found_id_version(nodes(:visible_node).id, 24354)
+ check_not_found_id_version(24356, nodes(:visible_node).version)
+ end
+
+ def check_not_found_id_version(id, version)
+ get :version, :id => id, :version => version
+ assert_response :not_found
+ end
+
+ ##
+ # Test that getting the current version is identical to picking
+ # that version with the version URI call.
+ def test_current_version
+ check_current_version(current_nodes(:visible_node))
+ check_current_version(current_nodes(:used_node_1))
+ check_current_version(current_nodes(:used_node_2))
+ check_current_version(current_nodes(:node_used_by_relationship))
+ check_current_version(current_nodes(:node_with_versions))
+ end
+
+ ##
+ # test the redaction of an old version of a node, while not being
+ # authorised.
+ def test_redact_node_unauthorised
+ do_redact_node(nodes(:node_with_versions_v3),
+ redactions(:example))
+ assert_response :unauthorized, "should need to be authenticated to redact."
+ end
+
+ ##
+ # 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(users(:public_user).email, "test")
+
+ do_redact_node(nodes(:node_with_versions_v3),
+ redactions(:example))
+ assert_response :forbidden, "should need to be moderator to redact."
+ end
+
+ ##
+ # test that, even as moderator, the current version of a node
+ # can't be redacted.
+ def test_redact_node_current_version
+ basic_authorization(users(:moderator_user).email, "test")
+
+ do_redact_node(nodes(:node_with_versions_v4),
+ redactions(:example))
+ assert_response :forbidden, "shouldn't be OK to redact current version as moderator."
+ end
+
+ ##
+ # test that redacted nodes aren't visible, regardless of
+ # authorisation except as moderator...
+ def test_version_redacted
+ node = nodes(:redacted_node_redacted_version)
+
+ get :version, :id => node.node_id, :version => node.version
+ assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
+
+ # not even to a logged-in user
+ basic_authorization(users(:public_user).email, "test")
+ get :version, :id => node.node_id, :version => node.version
+ assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
+ end
+
+ ##
+ # test that redacted nodes aren't visible in the history
+ def test_history_redacted
+ node = nodes(:redacted_node_redacted_version)
+
+ 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."
+
+ # not even to a logged-in user
+ basic_authorization(users(:public_user).email, "test")
+ get :version, :id => node.node_id, :version => node.version
+ 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, even when logged in."
+ end