From 9586232006af4124f8365387d8dbb8b2c174b20d Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 6 Jul 2025 19:51:26 +0300 Subject: [PATCH] Split update way with new tags tests --- test/controllers/api/ways_controller_test.rb | 67 ++++++++------------ 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 3d2ca687a..f5bbb46b7 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -848,54 +848,41 @@ module Api end end - # ------------------------------------------------------------ - # test tags handling - # ------------------------------------------------------------ - - ## - # Try adding a new tag to a way - def test_add_tags - private_user = create(:user, :data_public => false) - private_way = create(:way_with_nodes, :nodes_count => 2, :changeset => create(:changeset, :user => private_user)) - user = create(:user) - way = create(:way_with_nodes, :nodes_count => 2, :changeset => create(:changeset, :user => user)) + def test_update_with_new_tags_by_private_user + with_unchanging(:way_with_nodes, :nodes_count => 2) do |way| + with_unchanging_request([:data_public => false]) do |headers, changeset| + tag_xml = XML::Node.new("tag") + tag_xml["k"] = "new" + tag_xml["v"] = "yes" - ## Try with the non-public user - # setup auth - auth_header = bearer_authorization_header private_user + osm_xml = xml_for_way way + osm_xml.find("//osm/way").first << tag_xml + osm_xml = update_changeset osm_xml, changeset.id - # add an identical tag to the way - tag_xml = XML::Node.new("tag") - tag_xml["k"] = "new" - tag_xml["v"] = "yes" + put api_way_path(way), :params => osm_xml.to_s, :headers => headers - # add the tag into the existing xml - way_xml = xml_for_way(private_way) - way_xml.find("//osm/way").first << tag_xml + assert_response :forbidden, "adding a tag to a way for a non-public should fail with 'forbidden'" + end + end + end - # try and upload it - put api_way_path(private_way), :params => way_xml.to_s, :headers => auth_header - assert_response :forbidden, - "adding a duplicate tag to a way for a non-public should fail with 'forbidden'" + def test_update_with_new_tags + way = create(:way_with_nodes, :nodes_count => 2) - ## Now try with the public user - # setup auth - auth_header = bearer_authorization_header user + with_request do |headers, changeset| + tag_xml = XML::Node.new("tag") + tag_xml["k"] = "new" + tag_xml["v"] = "yes" - # add an identical tag to the way - tag_xml = XML::Node.new("tag") - tag_xml["k"] = "new" - tag_xml["v"] = "yes" + osm_xml = xml_for_way way + osm_xml.find("//osm/way").first << tag_xml + osm_xml = update_changeset osm_xml, changeset.id - # add the tag into the existing xml - way_xml = xml_for_way(way) - way_xml.find("//osm/way").first << 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 :success, - "adding a new tag to a way should succeed" - assert_equal way.version + 1, @response.body.to_i + assert_response :success, "adding a new tag to a way should succeed" + assert_equal way.version + 1, @response.body.to_i + end end ## -- 2.39.5