From 2606f2e71937afb5bdd6a994dee93a76d57ef3ac Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 6 Jul 2025 20:20:52 +0300 Subject: [PATCH] Split update way with new duplicate tags tests --- test/controllers/api/ways_controller_test.rb | 69 ++++++++------------ 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 44f628f59..3d5da8690 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -926,54 +926,41 @@ module Api end end - ## - # Try adding a new duplicate tags to a way - def test_new_duplicate_tags - private_user = create(:user, :data_public => false) - private_way = create(:way, :changeset => create(:changeset, :user => private_user)) - user = create(:user) - way = create(:way, :changeset => create(:changeset, :user => user)) - - ## First test with the non-public user so should be rejected - # setup auth - auth_header = bearer_authorization_header private_user - - # create duplicate tag - tag_xml = XML::Node.new("tag") - tag_xml["k"] = "i_am_a_duplicate" - tag_xml["v"] = "foobar" - - # add the tag into the existing xml - way_xml = xml_for_way(private_way) + def test_update_with_new_duplicate_tags_by_private_user + with_unchanging(:way_with_nodes) do |way| + with_unchanging_request([:data_public => false]) do |headers, changeset| + tag_xml = XML::Node.new("tag") + tag_xml["k"] = "i_am_a_duplicate" + tag_xml["v"] = "foobar" - # add two copies of the tag - way_xml.find("//osm/way").first << tag_xml.copy(true) << tag_xml + osm_xml = xml_for_way way + osm_xml.find("//osm/way").first << tag_xml.copy(true) << tag_xml + osm_xml = update_changeset osm_xml, changeset.id - # try and upload it - put api_way_path(private_way), :params => way_xml.to_s, :headers => auth_header - assert_response :forbidden, - "adding new duplicate tags to a way using a non-public user should fail with 'forbidden'" + put api_way_path(way), :params => osm_xml.to_s, :headers => headers - ## Now test with the public user - # setup auth - auth_header = bearer_authorization_header user + assert_response :forbidden, "adding new duplicate tags to a way using a non-public user should fail with 'forbidden'" + end + end + end - # create duplicate tag - tag_xml = XML::Node.new("tag") - tag_xml["k"] = "i_am_a_duplicate" - tag_xml["v"] = "foobar" + def test_update_with_new_duplicate_tags + with_unchanging(:way_with_nodes) do |way| + with_unchanging_request do |headers, changeset| + tag_xml = XML::Node.new("tag") + tag_xml["k"] = "i_am_a_duplicate" + tag_xml["v"] = "foobar" - # add the tag into the existing xml - way_xml = xml_for_way(way) + osm_xml = xml_for_way way + osm_xml.find("//osm/way").first << tag_xml.copy(true) << tag_xml + osm_xml = update_changeset osm_xml, changeset.id - # add two copies of the tag - way_xml.find("//osm/way").first << tag_xml.copy(true) << tag_xml + put api_way_path(way), :params => osm_xml.to_s, :headers => headers - # try and upload it - put api_way_path(way), :params => way_xml.to_s, :headers => auth_header - assert_response :bad_request, - "adding new duplicate tags to a way should fail with 'bad request'" - assert_equal "Element way/#{way.id} has duplicate tags with key i_am_a_duplicate", @response.body + assert_response :bad_request, "adding new duplicate tags to a way should fail with 'bad request'" + assert_equal "Element way/#{way.id} has duplicate tags with key i_am_a_duplicate", @response.body + end + end end ## -- 2.39.5