3 class ChangesetBboxTest < ActionDispatch::IntegrationTest
5 # check that the bounding box of a changeset gets updated correctly
6 def test_changeset_bbox
8 create(:way_node, :way => way, :node => create(:node, :lat => 0.3, :lon => 0.3))
10 auth_header = bearer_authorization_header
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
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."
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
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."
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
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."
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
67 # update the changeset_id of a way element
68 def update_changeset(xml, changeset_id)
69 xml_attr_rewrite(xml, "changeset", changeset_id)
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