]> git.openstreetmap.org Git - rails.git/blob - test/integration/changeset_bbox_test.rb
Merge remote-tracking branch 'upstream/pull/6168'
[rails.git] / test / integration / changeset_bbox_test.rb
1 require "test_helper"
2
3 class ChangesetBboxTest < ActionDispatch::IntegrationTest
4   ##
5   # check that the bounding box of a changeset gets updated correctly
6   def test_changeset_bbox
7     way = create(:way)
8     create(:way_node, :way => way, :node => create(:node, :lat => 0.3, :lon => 0.3))
9
10     auth_header = bearer_authorization_header
11
12     # create a new changeset
13     xml = "<osm><changeset/></osm>"
14     post api_changesets_path, :params => xml, :headers => auth_header
15     assert_response :success, "Creating of changeset failed."
16     changeset_id = @response.body.to_i
17
18     # add a single node to it
19     with_controller(NodesController.new) do
20       xml = "<osm><node lon='0.1' lat='0.2' changeset='#{changeset_id}'/></osm>"
21       post api_nodes_path, :params => xml, :headers => auth_header
22       assert_response :success, "Couldn't create node."
23     end
24
25     # get the bounding box back from the changeset
26     get api_changeset_path(changeset_id)
27     assert_response :success, "Couldn't read back changeset."
28     assert_dom "osm>changeset[min_lon='0.1000000']", 1
29     assert_dom "osm>changeset[max_lon='0.1000000']", 1
30     assert_dom "osm>changeset[min_lat='0.2000000']", 1
31     assert_dom "osm>changeset[max_lat='0.2000000']", 1
32
33     # add another node to it
34     with_controller(NodesController.new) do
35       xml = "<osm><node lon='0.2' lat='0.1' changeset='#{changeset_id}'/></osm>"
36       post api_nodes_path, :params => xml, :headers => auth_header
37       assert_response :success, "Couldn't create second node."
38     end
39
40     # get the bounding box back from the changeset
41     get api_changeset_path(changeset_id)
42     assert_response :success, "Couldn't read back changeset for the second time."
43     assert_dom "osm>changeset[min_lon='0.1000000']", 1
44     assert_dom "osm>changeset[max_lon='0.2000000']", 1
45     assert_dom "osm>changeset[min_lat='0.1000000']", 1
46     assert_dom "osm>changeset[max_lat='0.2000000']", 1
47
48     # add (delete) a way to it, which contains a point at (3,3)
49     with_controller(WaysController.new) do
50       xml = update_changeset(xml_for_way(way), changeset_id)
51       delete api_way_path(way), :params => xml.to_s, :headers => auth_header
52       assert_response :success, "Couldn't delete a way."
53     end
54
55     # get the bounding box back from the changeset
56     get api_changeset_path(changeset_id)
57     assert_response :success, "Couldn't read back changeset for the third time."
58     assert_dom "osm>changeset[min_lon='0.1000000']", 1
59     assert_dom "osm>changeset[max_lon='0.3000000']", 1
60     assert_dom "osm>changeset[min_lat='0.1000000']", 1
61     assert_dom "osm>changeset[max_lat='0.3000000']", 1
62   end
63
64   private
65
66   ##
67   # update the changeset_id of a way element
68   def update_changeset(xml, changeset_id)
69     xml_attr_rewrite(xml, "changeset", changeset_id)
70   end
71
72   ##
73   # update an attribute in a way element
74   def xml_attr_rewrite(xml, name, value)
75     xml.find("//osm/way").first[name] = value.to_s
76     xml
77   end
78 end