- # Test that getting the current version is identical to picking
- # that version with the version URI call.
- def test_current_version
- node = create(:node, :with_history)
- used_node = create(:node, :with_history)
- create(:way_node, :node => used_node)
- node_used_by_relationship = create(:node, :with_history)
- create(:relation_member, :member => node_used_by_relationship)
- node_with_versions = create(:node, :with_history, :version => 4)
-
- create(:node_tag, :node => node)
- create(:node_tag, :node => used_node)
- create(:node_tag, :node => node_used_by_relationship)
- create(:node_tag, :node => node_with_versions)
- propagate_tags(node, node.old_nodes.last)
- propagate_tags(used_node, used_node.old_nodes.last)
- propagate_tags(node_used_by_relationship, node_used_by_relationship.old_nodes.last)
- propagate_tags(node_with_versions, node_with_versions.old_nodes.last)
-
- check_current_version(node)
- check_current_version(used_node)
- check_current_version(node_used_by_relationship)
- check_current_version(node_with_versions)
- end
-
- # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
- def test_lat_lon_xml_format
- old_node = create(:old_node, :latitude => (0.00004 * OldNode::SCALE).to_i, :longitude => (0.00008 * OldNode::SCALE).to_i)
-
- get api_node_history_path(old_node.node_id)
- assert_match(/lat="0.0000400"/, response.body)
- assert_match(/lon="0.0000800"/, response.body)
- end
-
- ##
- # 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 => 4)
- node_v3 = node.old_nodes.find_by(:version => 3)
-
- do_redact_node(node_v3,
- create(:redaction))
- 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
- auth_header = bearer_authorization_header
-
- node = create(:node, :with_history, :version => 4)
- node_v3 = node.old_nodes.find_by(:version => 3)
-
- do_redact_node(node_v3,
- create(:redaction),
- auth_header)
- 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
- auth_header = bearer_authorization_header create(:moderator_user)
-
- node = create(:node, :with_history, :version => 4)
- node_v4 = node.old_nodes.find_by(:version => 4)
-
- do_redact_node(node_v4,
- create(:redaction),
- auth_header)
- assert_response :bad_request, "shouldn't be OK to redact current version as moderator."
- end
-
- def test_redact_node_by_regular_with_read_prefs_scope
- auth_header = create_bearer_auth_header(create(:user), %w[read_prefs])
- do_redact_redactable_node(auth_header)
- assert_response :forbidden, "should need to be moderator to redact."
- end
-
- def test_redact_node_by_regular_with_write_api_scope
- auth_header = create_bearer_auth_header(create(:user), %w[write_api])
- do_redact_redactable_node(auth_header)
- assert_response :forbidden, "should need to be moderator to redact."
- end