1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'changeset_controller'
4 class ChangesetControllerTest < ActionController::TestCase
7 def basic_authorization(user, pass)
8 @request.env["HTTP_AUTHORIZATION"] = "Basic %s" % Base64.encode64("#{user}:#{pass}")
12 @request.env["RAW_POST_DATA"] = c.to_s
15 # -----------------------
16 # Test simple changeset creation
17 # -----------------------
20 basic_authorization "test@openstreetmap.org", "test"
22 # Create the first user's changeset
23 content "<osm><changeset>" +
24 "<tag k='created_by' v='osm test suite checking changesets'/>" +
28 assert_response :success, "Creation of changeset did not return sucess status"
29 newid = @response.body.to_i
31 # check end time, should be an hour ahead of creation time
32 cs = Changeset.find(newid)
33 duration = cs.closed_at - cs.created_at
34 # the difference can either be a rational, or a floating point number
35 # of seconds, depending on the code path taken :-(
36 if duration.class == Rational
37 assert_equal Rational(1,24), duration , "initial idle timeout should be an hour (#{cs.created_at} -> #{cs.closed_at})"
39 # must be number of seconds...
40 assert_equal 3600.0, duration , "initial idle timeout should be an hour (#{cs.created_at} -> #{cs.closed_at})"
44 def test_create_invalid
45 basic_authorization "test@openstreetmap.org", "test"
46 content "<osm><changeset></osm>"
48 assert_response :bad_request, "creating a invalid changeset should fail"
52 # check that the changeset can be read and returns the correct
55 changeset_id = changesets(:normal_user_first_change).id
56 get :read, :id => changeset_id
57 assert_response :success, "cannot get first changeset"
59 assert_select "osm[version=#{API_VERSION}][generator=\"OpenStreetMap server\"]", 1
60 assert_select "osm>changeset[id=#{changeset_id}]", 1
64 # test that the user who opened a change can close it
66 basic_authorization "test@openstreetmap.org", "test"
68 put :close, :id => changesets(:normal_user_first_change).id
69 assert_response :success
73 # test that a different user can't close another user's changeset
74 def test_close_invalid
75 basic_authorization "test@example.com", "test"
77 put :close, :id => changesets(:normal_user_first_change).id
78 assert_response :conflict
79 assert_equal "The user doesn't own that changeset", @response.body
83 # upload something simple, but valid and check that it can
85 def test_upload_simple_valid
86 basic_authorization "test@openstreetmap.org", "test"
88 # simple diff to change a node, way and relation by removing
93 <node id='1' lon='0' lat='0' changeset='1' version='1'/>
94 <way id='1' changeset='1' version='1'>
99 <relation id='1' changeset='1' version='1'>
100 <member type='way' role='some' ref='3'/>
101 <member type='node' role='some' ref='5'/>
102 <member type='relation' role='some' ref='3'/>
110 post :upload, :id => 1
111 assert_response :success,
112 "can't upload a simple valid diff to changeset: #{@response.body}"
114 # check that the changes made it into the database
115 assert_equal 0, Node.find(1).tags.size, "node 1 should now have no tags"
116 assert_equal 0, Way.find(1).tags.size, "way 1 should now have no tags"
117 assert_equal 0, Relation.find(1).tags.size, "relation 1 should now have no tags"
121 # upload something which creates new objects using placeholders
122 def test_upload_create_valid
123 basic_authorization "test@openstreetmap.org", "test"
125 # simple diff to create a node way and relation using placeholders
129 <node id='-1' lon='0' lat='0' changeset='1'>
130 <tag k='foo' v='bar'/>
131 <tag k='baz' v='bat'/>
133 <way id='-1' changeset='1'>
138 <relation id='-1' changeset='1'>
139 <member type='way' role='some' ref='3'/>
140 <member type='node' role='some' ref='5'/>
141 <member type='relation' role='some' ref='3'/>
149 post :upload, :id => 1
150 assert_response :success,
151 "can't upload a simple valid creation to changeset: #{@response.body}"
153 # check the returned payload
154 assert_select "diffResult[version=#{API_VERSION}][generator=\"OpenStreetMap server\"]", 1
155 assert_select "diffResult>node", 1
156 assert_select "diffresult>way", 1
157 assert_select "diffResult>relation", 1
159 # inspect the response to find out what the new element IDs are
160 doc = XML::Parser.string(@response.body).parse
161 new_node_id = doc.find("//diffResult/node").first["new_id"].to_i
162 new_way_id = doc.find("//diffResult/way").first["new_id"].to_i
163 new_rel_id = doc.find("//diffResult/relation").first["new_id"].to_i
165 # check the old IDs are all present and negative one
166 assert_equal -1, doc.find("//diffResult/node").first["old_id"].to_i
167 assert_equal -1, doc.find("//diffResult/way").first["old_id"].to_i
168 assert_equal -1, doc.find("//diffResult/relation").first["old_id"].to_i
170 # check the versions are present and equal one
171 assert_equal 1, doc.find("//diffResult/node").first["new_version"].to_i
172 assert_equal 1, doc.find("//diffResult/way").first["new_version"].to_i
173 assert_equal 1, doc.find("//diffResult/relation").first["new_version"].to_i
175 # check that the changes made it into the database
176 assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
177 assert_equal 0, Way.find(new_way_id).tags.size, "new way should have no tags"
178 assert_equal 0, Relation.find(new_rel_id).tags.size, "new relation should have no tags"
182 # test a complex delete where we delete elements which rely on eachother
183 # in the same transaction.
184 def test_upload_delete
185 basic_authorization "test@openstreetmap.org", "test"
187 diff = XML::Document.new
188 diff.root = XML::Node.new "osmChange"
189 delete = XML::Node.new "delete"
191 delete << current_relations(:visible_relation).to_xml_node
192 delete << current_relations(:used_relation).to_xml_node
193 delete << current_ways(:used_way).to_xml_node
194 delete << current_nodes(:node_used_by_relationship).to_xml_node
198 post :upload, :id => 1
199 assert_response :success,
200 "can't upload a deletion diff to changeset: #{@response.body}"
202 # check that everything was deleted
203 assert_equal false, Node.find(current_nodes(:node_used_by_relationship).id).visible
204 assert_equal false, Way.find(current_ways(:used_way).id).visible
205 assert_equal false, Relation.find(current_relations(:visible_relation).id).visible
206 assert_equal false, Relation.find(current_relations(:used_relation).id).visible
210 # test that deleting stuff in a transaction doesn't bypass the checks
211 # to ensure that used elements are not deleted.
212 def test_upload_delete_invalid
213 basic_authorization "test@openstreetmap.org", "test"
215 diff = XML::Document.new
216 diff.root = XML::Node.new "osmChange"
217 delete = XML::Node.new "delete"
219 delete << current_relations(:visible_relation).to_xml_node
220 delete << current_ways(:used_way).to_xml_node
221 delete << current_nodes(:node_used_by_relationship).to_xml_node
225 post :upload, :id => 1
226 assert_response :precondition_failed,
227 "shouldn't be able to upload a invalid deletion diff: #{@response.body}"
229 # check that nothing was, in fact, deleted
230 assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
231 assert_equal true, Way.find(current_ways(:used_way).id).visible
232 assert_equal true, Relation.find(current_relations(:visible_relation).id).visible
236 # upload something which creates new objects and inserts them into
237 # existing containers using placeholders.
238 def test_upload_complex
239 basic_authorization "test@openstreetmap.org", "test"
241 # simple diff to create a node way and relation using placeholders
245 <node id='-1' lon='0' lat='0' changeset='1'>
246 <tag k='foo' v='bar'/>
247 <tag k='baz' v='bat'/>
251 <way id='1' changeset='1' version='1'>
255 <relation id='1' changeset='1' version='1'>
256 <member type='way' role='some' ref='3'/>
257 <member type='node' role='some' ref='-1'/>
258 <member type='relation' role='some' ref='3'/>
266 post :upload, :id => 1
267 assert_response :success,
268 "can't upload a complex diff to changeset: #{@response.body}"
270 # check the returned payload
271 assert_select "diffResult[version=#{API_VERSION}][generator=\"#{GENERATOR}\"]", 1
272 assert_select "diffResult>node", 1
273 assert_select "diffResult>way", 1
274 assert_select "diffResult>relation", 1
276 # inspect the response to find out what the new element IDs are
277 doc = XML::Parser.string(@response.body).parse
278 new_node_id = doc.find("//diffResult/node").first["new_id"].to_i
280 # check that the changes made it into the database
281 assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
282 assert_equal [new_node_id, 3], Way.find(1).nds, "way nodes should match"
283 Relation.find(1).members.each do |type,id,role|
285 assert_equal new_node_id, id, "relation should contain new node"
291 # create a diff which references several changesets, which should cause
292 # a rollback and none of the diff gets committed
293 def test_upload_invalid_changesets
294 basic_authorization "test@openstreetmap.org", "test"
296 # simple diff to create a node way and relation using placeholders
300 <node id='1' lon='0' lat='0' changeset='1' version='1'/>
301 <way id='1' changeset='1' version='1'>
306 <relation id='1' changeset='1' version='1'>
307 <member type='way' role='some' ref='3'/>
308 <member type='node' role='some' ref='5'/>
309 <member type='relation' role='some' ref='3'/>
313 <node id='-1' changeset='4'>
314 <tag k='foo' v='bar'/>
315 <tag k='baz' v='bat'/>
320 # cache the objects before uploading them
321 node = current_nodes(:visible_node)
322 way = current_ways(:visible_way)
323 rel = current_relations(:visible_relation)
327 post :upload, :id => 1
328 assert_response :conflict,
329 "uploading a diff with multiple changsets should have failed"
331 # check that objects are unmodified
332 assert_nodes_are_equal(node, Node.find(1))
333 assert_ways_are_equal(way, Way.find(1))
337 # upload multiple versions of the same element in the same diff.
338 def test_upload_multiple_valid
339 basic_authorization "test@openstreetmap.org", "test"
341 # change the location of a node multiple times, each time referencing
342 # the last version. doesn't this depend on version numbers being
347 <node id='1' lon='0' lat='0' changeset='1' version='1'/>
348 <node id='1' lon='1' lat='0' changeset='1' version='2'/>
349 <node id='1' lon='1' lat='1' changeset='1' version='3'/>
350 <node id='1' lon='1' lat='2' changeset='1' version='4'/>
351 <node id='1' lon='2' lat='2' changeset='1' version='5'/>
352 <node id='1' lon='3' lat='2' changeset='1' version='6'/>
353 <node id='1' lon='3' lat='3' changeset='1' version='7'/>
354 <node id='1' lon='9' lat='9' changeset='1' version='8'/>
361 post :upload, :id => 1
362 assert_response :success,
363 "can't upload multiple versions of an element in a diff: #{@response.body}"
367 # upload multiple versions of the same element in the same diff, but
368 # keep the version numbers the same.
369 def test_upload_multiple_duplicate
370 basic_authorization "test@openstreetmap.org", "test"
375 <node id='1' lon='0' lat='0' changeset='1' version='1'/>
376 <node id='1' lon='1' lat='1' changeset='1' version='1'/>
383 post :upload, :id => 1
384 assert_response :conflict,
385 "shouldn't be able to upload the same element twice in a diff: #{@response.body}"
389 # try to upload some elements without specifying the version
390 def test_upload_missing_version
391 basic_authorization "test@openstreetmap.org", "test"
396 <node id='1' lon='1' lat='1' changeset='1'/>
403 post :upload, :id => 1
404 assert_response :bad_request,
405 "shouldn't be able to upload an element without version: #{@response.body}"
409 # try to upload with commands other than create, modify, or delete
410 def test_action_upload_invalid
411 basic_authorization "test@openstreetmap.org", "test"
416 <node id='1' lon='1' lat='1' changeset='1' />
421 post :upload, :id => 1
422 assert_response :bad_request, "Shouldn't be able to upload a diff with the action ping"
423 assert_equal @response.body, "Unknown action ping, choices are create, modify, delete."
427 # when we make some simple changes we get the same changes back from the
429 def test_diff_download_simple
430 basic_authorization(users(:normal_user).email, "test")
432 # create a temporary changeset
433 content "<osm><changeset>" +
434 "<tag k='created_by' v='osm test suite checking changesets'/>" +
437 assert_response :success
438 changeset_id = @response.body.to_i
444 <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
445 <node id='1' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
446 <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
447 <node id='1' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
448 <node id='1' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
449 <node id='1' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
450 <node id='1' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
451 <node id='1' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
458 post :upload, :id => changeset_id
459 assert_response :success,
460 "can't upload multiple versions of an element in a diff: #{@response.body}"
462 get :download, :id => changeset_id
463 assert_response :success
465 assert_select "osmChange", 1
466 assert_select "osmChange>modify", 8
467 assert_select "osmChange>modify>node", 8
471 # culled this from josm to ensure that nothing in the way that josm
472 # is formatting the request is causing it to fail.
474 # NOTE: the error turned out to be something else completely!
476 basic_authorization(users(:normal_user).email, "test")
478 # create a temporary changeset
479 content "<osm><changeset>" +
480 "<tag k='created_by' v='osm test suite checking changesets'/>" +
483 assert_response :success
484 changeset_id = @response.body.to_i
487 <osmChange version="0.6" generator="JOSM">
488 <create version="0.6" generator="JOSM">
489 <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
490 <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
491 <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
492 <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
493 <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
494 <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
495 <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
496 <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
497 <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
498 <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
508 <tag k='highway' v='residential' />
509 <tag k='name' v='Foobar Street' />
517 post :upload, :id => changeset_id
518 assert_response :success,
519 "can't upload a diff from JOSM: #{@response.body}"
521 get :download, :id => changeset_id
522 assert_response :success
524 assert_select "osmChange", 1
525 assert_select "osmChange>create>node", 9
526 assert_select "osmChange>create>way", 1
527 assert_select "osmChange>create>way>nd", 9
528 assert_select "osmChange>create>way>tag", 2
532 # when we make some complex changes we get the same changes back from the
534 def test_diff_download_complex
535 basic_authorization(users(:normal_user).email, "test")
537 # create a temporary changeset
538 content "<osm><changeset>" +
539 "<tag k='created_by' v='osm test suite checking changesets'/>" +
542 assert_response :success
543 changeset_id = @response.body.to_i
549 <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
552 <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
553 <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
554 <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
557 <node id='3' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
558 <way id='1' changeset='#{changeset_id}' version='1'>
570 post :upload, :id => changeset_id
571 assert_response :success,
572 "can't upload multiple versions of an element in a diff: #{@response.body}"
574 get :download, :id => changeset_id
575 assert_response :success
577 assert_select "osmChange", 1
578 assert_select "osmChange>create", 3
579 assert_select "osmChange>delete", 1
580 assert_select "osmChange>modify", 2
581 assert_select "osmChange>create>node", 3
582 assert_select "osmChange>delete>node", 1
583 assert_select "osmChange>modify>node", 1
584 assert_select "osmChange>modify>way", 1
588 # check that the bounding box of a changeset gets updated correctly
589 def test_changeset_bbox
590 basic_authorization "test@openstreetmap.org", "test"
592 # create a new changeset
593 content "<osm><changeset/></osm>"
595 assert_response :success, "Creating of changeset failed."
596 changeset_id = @response.body.to_i
598 # add a single node to it
599 with_controller(NodeController.new) do
600 content "<osm><node lon='1' lat='2' changeset='#{changeset_id}'/></osm>"
602 assert_response :success, "Couldn't create node."
605 # get the bounding box back from the changeset
606 get :read, :id => changeset_id
607 assert_response :success, "Couldn't read back changeset."
608 assert_select "osm>changeset[min_lon=1.0]", 1
609 assert_select "osm>changeset[max_lon=1.0]", 1
610 assert_select "osm>changeset[min_lat=2.0]", 1
611 assert_select "osm>changeset[max_lat=2.0]", 1
613 # add another node to it
614 with_controller(NodeController.new) do
615 content "<osm><node lon='2' lat='1' changeset='#{changeset_id}'/></osm>"
617 assert_response :success, "Couldn't create second node."
620 # get the bounding box back from the changeset
621 get :read, :id => changeset_id
622 assert_response :success, "Couldn't read back changeset for the second time."
623 assert_select "osm>changeset[min_lon=1.0]", 1
624 assert_select "osm>changeset[max_lon=2.0]", 1
625 assert_select "osm>changeset[min_lat=1.0]", 1
626 assert_select "osm>changeset[max_lat=2.0]", 1
628 # add (delete) a way to it
629 with_controller(WayController.new) do
630 content update_changeset(current_ways(:visible_way).to_xml,
632 put :delete, :id => current_ways(:visible_way).id
633 assert_response :success, "Couldn't delete a way."
636 # get the bounding box back from the changeset
637 get :read, :id => changeset_id
638 assert_response :success, "Couldn't read back changeset for the third time."
639 assert_select "osm>changeset[min_lon=1.0]", 1
640 assert_select "osm>changeset[max_lon=3.1]", 1
641 assert_select "osm>changeset[min_lat=1.0]", 1
642 assert_select "osm>changeset[max_lat=3.1]", 1
646 # test that the changeset :include method works as it should
647 def test_changeset_include
648 basic_authorization "test@openstreetmap.org", "test"
650 # create a new changeset
651 content "<osm><changeset/></osm>"
653 assert_response :success, "Creating of changeset failed."
654 changeset_id = @response.body.to_i
656 # NOTE: the include method doesn't over-expand, like inserting
657 # a real method does. this is because we expect the client to
658 # know what it is doing!
659 check_after_include(changeset_id, 1, 1, [ 1, 1, 1, 1])
660 check_after_include(changeset_id, 3, 3, [ 1, 1, 3, 3])
661 check_after_include(changeset_id, 4, 2, [ 1, 1, 4, 3])
662 check_after_include(changeset_id, 2, 2, [ 1, 1, 4, 3])
663 check_after_include(changeset_id, -1, -1, [-1, -1, 4, 3])
664 check_after_include(changeset_id, -2, 5, [-2, -1, 4, 5])
668 # test the query functionality of changesets
670 get :query, :bbox => "-10,-10, 10, 10"
671 assert_response :success, "can't get changesets in bbox"
672 assert_changesets [1,4]
674 get :query, :bbox => "4.5,4.5,4.6,4.6"
675 assert_response :success, "can't get changesets in bbox"
676 assert_changesets [1]
678 # can't get changesets of user 1 without authenticating
679 get :query, :user => users(:normal_user).id
680 assert_response :not_found, "shouldn't be able to get changesets by non-public user"
682 # but this should work
683 basic_authorization "test@openstreetmap.org", "test"
684 get :query, :user => users(:normal_user).id
685 assert_response :success, "can't get changesets by user"
686 assert_changesets [1,3,4]
688 get :query, :user => users(:normal_user).id, :open => true
689 assert_response :success, "can't get changesets by user and open"
690 assert_changesets [1,4]
692 get :query, :time => '2007-12-31'
693 assert_response :success, "can't get changesets by time-since"
694 assert_changesets [1,2,4,5]
696 get :query, :time => '2008-01-01T12:34Z'
697 assert_response :success, "can't get changesets by time-since with hour"
698 assert_changesets [1,2,4,5]
700 get :query, :time => '2007-12-31T23:59Z,2008-01-01T00:01Z'
701 assert_response :success, "can't get changesets by time-range"
702 assert_changesets [1,4,5]
704 get :query, :open => 'true'
705 assert_response :success, "can't get changesets by open-ness"
706 assert_changesets [1,2,4]
710 # check that errors are returned if garbage is inserted
712 def test_query_invalid
717 get :query, :bbox => bbox
718 assert_response :bad_request, "'#{bbox}' isn't a bbox"
723 ";drop table users;",
727 get :query, :time => time
728 assert_response :bad_request, "'#{time}' isn't a valid time range"
736 get :query, :user => uid
737 assert_response :bad_request, "'#{uid}' isn't a valid user ID"
742 # check updating tags on a changeset
743 def test_changeset_update
744 changeset = changesets(:normal_user_first_change)
745 new_changeset = changeset.to_xml
746 new_tag = XML::Node.new "tag"
747 new_tag['k'] = "tagtesting"
748 new_tag['v'] = "valuetesting"
749 new_changeset.find("//osm/changeset").first << new_tag
750 content new_changeset
752 # try without any authorization
753 put :update, :id => changeset.id
754 assert_response :unauthorized
756 # try with the wrong authorization
757 basic_authorization "test@example.com", "test"
758 put :update, :id => changeset.id
759 assert_response :conflict
761 # now this should work...
762 basic_authorization "test@openstreetmap.org", "test"
763 put :update, :id => changeset.id
764 assert_response :success
766 assert_select "osm>changeset[id=#{changeset.id}]", 1
767 assert_select "osm>changeset>tag", 2
768 assert_select "osm>changeset>tag[k=tagtesting][v=valuetesting]", 1
772 # check that a user different from the one who opened the changeset
774 def test_changeset_update_invalid
775 basic_authorization "test@example.com", "test"
777 changeset = changesets(:normal_user_first_change)
778 new_changeset = changeset.to_xml
779 new_tag = XML::Node.new "tag"
780 new_tag['k'] = "testing"
781 new_tag['v'] = "testing"
782 new_changeset.find("//osm/changeset").first << new_tag
784 content new_changeset
785 put :update, :id => changeset.id
786 assert_response :conflict
790 # check that a changeset can contain a certain max number of changes.
791 def test_changeset_limits
792 basic_authorization "test@openstreetmap.org", "test"
794 # open a new changeset
795 content "<osm><changeset/></osm>"
797 assert_response :success, "can't create a new changeset"
798 cs_id = @response.body.to_i
800 # start the counter just short of where the changeset should finish.
802 # alter the database to set the counter on the changeset directly,
803 # otherwise it takes about 6 minutes to fill all of them.
804 changeset = Changeset.find(cs_id)
805 changeset.num_changes = Changeset::MAX_ELEMENTS - offset
808 with_controller(NodeController.new) do
810 content "<osm><node changeset='#{cs_id}' lat='0.0' lon='0.0'/></osm>"
812 assert_response :success, "can't create a new node"
813 node_id = @response.body.to_i
815 get :read, :id => node_id
816 assert_response :success, "can't read back new node"
817 node_doc = XML::Parser.string(@response.body).parse
818 node_xml = node_doc.find("//osm/node").first
820 # loop until we fill the changeset with nodes
822 node_xml['lat'] = rand.to_s
823 node_xml['lon'] = rand.to_s
824 node_xml['version'] = (i+1).to_s
827 put :update, :id => node_id
828 assert_response :success, "attempt #{i} should have succeeded"
831 # trying again should fail
832 node_xml['lat'] = rand.to_s
833 node_xml['lon'] = rand.to_s
834 node_xml['version'] = offset.to_s
837 put :update, :id => node_id
838 assert_response :conflict, "final attempt should have failed"
841 changeset = Changeset.find(cs_id)
842 assert_equal Changeset::MAX_ELEMENTS + 1, changeset.num_changes
845 #------------------------------------------------------------
847 #------------------------------------------------------------
850 # boilerplate for checking that certain changesets exist in the
852 def assert_changesets(ids)
853 assert_select "osm>changeset", ids.size
855 assert_select "osm>changeset[id=#{id}]", 1
860 # call the include method and assert properties of the bbox
861 def check_after_include(changeset_id, lon, lat, bbox)
862 content "<osm><node lon='#{lon}' lat='#{lat}'/></osm>"
863 post :expand_bbox, :id => changeset_id
864 assert_response :success, "Setting include of changeset failed: #{@response.body}"
866 # check exactly one changeset
867 assert_select "osm>changeset", 1
868 assert_select "osm>changeset[id=#{changeset_id}]", 1
871 doc = XML::Parser.string(@response.body).parse
872 changeset = doc.find("//osm/changeset").first
873 assert_equal bbox[0], changeset['min_lon'].to_f, "min lon"
874 assert_equal bbox[1], changeset['min_lat'].to_f, "min lat"
875 assert_equal bbox[2], changeset['max_lon'].to_f, "max lon"
876 assert_equal bbox[3], changeset['max_lat'].to_f, "max lat"
880 # update the changeset_id of a way element
881 def update_changeset(xml, changeset_id)
882 xml_attr_rewrite(xml, 'changeset', changeset_id)
886 # update an attribute in a way element
887 def xml_attr_rewrite(xml, name, value)
888 xml.find("//osm/way").first[name] = value.to_s