From 0745557d6b925e970ec2a4ccd45818f39d5b1102 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 4 Jul 2025 19:25:08 +0300 Subject: [PATCH] Move changeset bbox test to integration tests --- .../api/changesets_controller_test.rb | 74 ------------------ test/integration/changeset_bbox_test.rb | 78 +++++++++++++++++++ 2 files changed, 78 insertions(+), 74 deletions(-) create mode 100644 test/integration/changeset_bbox_test.rb diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index 716a66a34..1825c0b6e 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -658,67 +658,6 @@ module Api end end - ## - # check that the bounding box of a changeset gets updated correctly - # FIXME: This should really be moded to a integration test due to the with_controller - def test_changeset_bbox - way = create(:way) - create(:way_node, :way => way, :node => create(:node, :lat => 0.3, :lon => 0.3)) - - auth_header = bearer_authorization_header - - # create a new changeset - xml = "" - post api_changesets_path, :params => xml, :headers => auth_header - assert_response :success, "Creating of changeset failed." - changeset_id = @response.body.to_i - - # add a single node to it - with_controller(NodesController.new) do - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - assert_response :success, "Couldn't create node." - end - - # get the bounding box back from the changeset - get api_changeset_path(changeset_id) - assert_response :success, "Couldn't read back changeset." - assert_select "osm>changeset[min_lon='0.1000000']", 1 - assert_select "osm>changeset[max_lon='0.1000000']", 1 - assert_select "osm>changeset[min_lat='0.2000000']", 1 - assert_select "osm>changeset[max_lat='0.2000000']", 1 - - # add another node to it - with_controller(NodesController.new) do - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - assert_response :success, "Couldn't create second node." - end - - # get the bounding box back from the changeset - get api_changeset_path(changeset_id) - assert_response :success, "Couldn't read back changeset for the second time." - assert_select "osm>changeset[min_lon='0.1000000']", 1 - assert_select "osm>changeset[max_lon='0.2000000']", 1 - assert_select "osm>changeset[min_lat='0.1000000']", 1 - assert_select "osm>changeset[max_lat='0.2000000']", 1 - - # add (delete) a way to it, which contains a point at (3,3) - with_controller(WaysController.new) do - xml = update_changeset(xml_for_way(way), changeset_id) - delete api_way_path(way), :params => xml.to_s, :headers => auth_header - assert_response :success, "Couldn't delete a way." - end - - # get the bounding box back from the changeset - get api_changeset_path(changeset_id) - assert_response :success, "Couldn't read back changeset for the third time." - assert_select "osm>changeset[min_lon='0.1000000']", 1 - assert_select "osm>changeset[max_lon='0.3000000']", 1 - assert_select "osm>changeset[min_lat='0.1000000']", 1 - assert_select "osm>changeset[max_lat='0.3000000']", 1 - end - ## # check updating tags on a changeset def test_changeset_update @@ -899,19 +838,6 @@ module Api end end - ## - # update the changeset_id of a way element - def update_changeset(xml, changeset_id) - xml_attr_rewrite(xml, "changeset", changeset_id) - end - - ## - # update an attribute in a way element - def xml_attr_rewrite(xml, name, value) - xml.find("//osm/way").first[name] = value.to_s - xml - end - ## # build XML for changesets def create_changeset_xml(user: nil, id: nil) diff --git a/test/integration/changeset_bbox_test.rb b/test/integration/changeset_bbox_test.rb new file mode 100644 index 000000000..4774fe5e3 --- /dev/null +++ b/test/integration/changeset_bbox_test.rb @@ -0,0 +1,78 @@ +require "test_helper" + +class ChangesetBboxTest < ActionDispatch::IntegrationTest + ## + # check that the bounding box of a changeset gets updated correctly + def test_changeset_bbox + way = create(:way) + create(:way_node, :way => way, :node => create(:node, :lat => 0.3, :lon => 0.3)) + + auth_header = bearer_authorization_header + + # create a new changeset + xml = "" + post api_changesets_path, :params => xml, :headers => auth_header + assert_response :success, "Creating of changeset failed." + changeset_id = @response.body.to_i + + # add a single node to it + with_controller(NodesController.new) do + xml = "" + post api_nodes_path, :params => xml, :headers => auth_header + assert_response :success, "Couldn't create node." + end + + # get the bounding box back from the changeset + get api_changeset_path(changeset_id) + assert_response :success, "Couldn't read back changeset." + assert_dom "osm>changeset[min_lon='0.1000000']", 1 + assert_dom "osm>changeset[max_lon='0.1000000']", 1 + assert_dom "osm>changeset[min_lat='0.2000000']", 1 + assert_dom "osm>changeset[max_lat='0.2000000']", 1 + + # add another node to it + with_controller(NodesController.new) do + xml = "" + post api_nodes_path, :params => xml, :headers => auth_header + assert_response :success, "Couldn't create second node." + end + + # get the bounding box back from the changeset + get api_changeset_path(changeset_id) + assert_response :success, "Couldn't read back changeset for the second time." + assert_dom "osm>changeset[min_lon='0.1000000']", 1 + assert_dom "osm>changeset[max_lon='0.2000000']", 1 + assert_dom "osm>changeset[min_lat='0.1000000']", 1 + assert_dom "osm>changeset[max_lat='0.2000000']", 1 + + # add (delete) a way to it, which contains a point at (3,3) + with_controller(WaysController.new) do + xml = update_changeset(xml_for_way(way), changeset_id) + delete api_way_path(way), :params => xml.to_s, :headers => auth_header + assert_response :success, "Couldn't delete a way." + end + + # get the bounding box back from the changeset + get api_changeset_path(changeset_id) + assert_response :success, "Couldn't read back changeset for the third time." + assert_dom "osm>changeset[min_lon='0.1000000']", 1 + assert_dom "osm>changeset[max_lon='0.3000000']", 1 + assert_dom "osm>changeset[min_lat='0.1000000']", 1 + assert_dom "osm>changeset[max_lat='0.3000000']", 1 + end + + private + + ## + # update the changeset_id of a way element + def update_changeset(xml, changeset_id) + xml_attr_rewrite(xml, "changeset", changeset_id) + end + + ## + # update an attribute in a way element + def xml_attr_rewrite(xml, name, value) + xml.find("//osm/way").first[name] = value.to_s + xml + end +end -- 2.39.5