2 require "changeset_controller"
4 class ChangesetControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/api/0.6/changeset/create", :method => :put },
12 { :controller => "changeset", :action => "create" }
15 { :path => "/api/0.6/changeset/1/upload", :method => :post },
16 { :controller => "changeset", :action => "upload", :id => "1" }
19 { :path => "/api/0.6/changeset/1/download", :method => :get },
20 { :controller => "changeset", :action => "download", :id => "1" }
23 { :path => "/api/0.6/changeset/1/expand_bbox", :method => :post },
24 { :controller => "changeset", :action => "expand_bbox", :id => "1" }
27 { :path => "/api/0.6/changeset/1", :method => :get },
28 { :controller => "changeset", :action => "read", :id => "1" }
31 { :path => "/api/0.6/changeset/1/subscribe", :method => :post },
32 { :controller => "changeset", :action => "subscribe", :id => "1" }
35 { :path => "/api/0.6/changeset/1/unsubscribe", :method => :post },
36 { :controller => "changeset", :action => "unsubscribe", :id => "1" }
39 { :path => "/api/0.6/changeset/1", :method => :put },
40 { :controller => "changeset", :action => "update", :id => "1" }
43 { :path => "/api/0.6/changeset/1/close", :method => :put },
44 { :controller => "changeset", :action => "close", :id => "1" }
47 { :path => "/api/0.6/changeset/1/comment", :method => :post },
48 { :controller => "changeset", :action => "comment", :id => "1" }
51 { :path => "/api/0.6/changeset/comment/1/hide", :method => :post },
52 { :controller => "changeset", :action => "hide_comment", :id => "1" }
55 { :path => "/api/0.6/changeset/comment/1/unhide", :method => :post },
56 { :controller => "changeset", :action => "unhide_comment", :id => "1" }
59 { :path => "/api/0.6/changesets", :method => :get },
60 { :controller => "changeset", :action => "query" }
63 { :path => "/changeset/1/comments/feed", :method => :get },
64 { :controller => "changeset", :action => "comments_feed", :id => "1", :format => "rss" }
67 { :path => "/user/name/history", :method => :get },
68 { :controller => "changeset", :action => "list", :display_name => "name" }
71 { :path => "/user/name/history/feed", :method => :get },
72 { :controller => "changeset", :action => "feed", :display_name => "name", :format => :atom }
75 { :path => "/history/friends", :method => :get },
76 { :controller => "changeset", :action => "list", :friends => true, :format => :html }
79 { :path => "/history/nearby", :method => :get },
80 { :controller => "changeset", :action => "list", :nearby => true, :format => :html }
83 { :path => "/history", :method => :get },
84 { :controller => "changeset", :action => "list" }
87 { :path => "/history/feed", :method => :get },
88 { :controller => "changeset", :action => "feed", :format => :atom }
91 { :path => "/history/comments/feed", :method => :get },
92 { :controller => "changeset", :action => "comments_feed", :format => "rss" }
96 # -----------------------
97 # Test simple changeset creation
98 # -----------------------
101 basic_authorization create(:user, :data_public => false).email, "test"
102 # Create the first user's changeset
103 content "<osm><changeset>" +
104 "<tag k='created_by' v='osm test suite checking changesets'/>" +
107 assert_require_public_data
109 basic_authorization create(:user).email, "test"
110 # Create the first user's changeset
111 content "<osm><changeset>" +
112 "<tag k='created_by' v='osm test suite checking changesets'/>" +
116 assert_response :success, "Creation of changeset did not return sucess status"
117 newid = @response.body.to_i
119 # check end time, should be an hour ahead of creation time
120 cs = Changeset.find(newid)
121 duration = cs.closed_at - cs.created_at
122 # the difference can either be a rational, or a floating point number
123 # of seconds, depending on the code path taken :-(
124 if duration.class == Rational
125 assert_equal Rational(1, 24), duration, "initial idle timeout should be an hour (#{cs.created_at} -> #{cs.closed_at})"
127 # must be number of seconds...
128 assert_equal 3600, duration.round, "initial idle timeout should be an hour (#{cs.created_at} -> #{cs.closed_at})"
131 # checks if uploader was subscribed
132 assert_equal 1, cs.subscribers.length
135 def test_create_invalid
136 basic_authorization create(:user, :data_public => false).email, "test"
137 content "<osm><changeset></osm>"
139 assert_require_public_data
141 ## Try the public user
142 basic_authorization create(:user).email, "test"
143 content "<osm><changeset></osm>"
145 assert_response :bad_request, "creating a invalid changeset should fail"
148 def test_create_invalid_no_content
149 ## First check with no auth
151 assert_response :unauthorized, "shouldn't be able to create a changeset with no auth"
153 ## Now try to with a non-public user
154 basic_authorization create(:user, :data_public => false).email, "test"
156 assert_require_public_data
158 ## Try an inactive user
159 basic_authorization create(:user, :pending).email, "test"
163 ## Now try to use a normal user
164 basic_authorization create(:user).email, "test"
166 assert_response :bad_request, "creating a changeset with no content should fail"
169 def test_create_wrong_method
170 basic_authorization create(:user).email, "test"
172 assert_response :method_not_allowed
174 assert_response :method_not_allowed
178 # check that the changeset can be read and returns the correct
179 # document structure.
181 changeset_id = create(:changeset).id
183 get :read, :id => changeset_id
184 assert_response :success, "cannot get first changeset"
186 assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
187 assert_select "osm>changeset[id='#{changeset_id}']", 1
188 assert_select "osm>changeset>discussion", 0
190 get :read, :id => changeset_id, :include_discussion => true
191 assert_response :success, "cannot get first changeset with comments"
193 assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
194 assert_select "osm>changeset[id='#{changeset_id}']", 1
195 assert_select "osm>changeset>discussion", 1
196 assert_select "osm>changeset>discussion>comment", 0
198 changeset_id = create(:changeset, :closed).id
199 create_list(:changeset_comment, 3, :changeset_id => changeset_id)
201 get :read, :id => changeset_id, :include_discussion => true
202 assert_response :success, "cannot get closed changeset with comments"
204 assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
205 assert_select "osm>changeset[id='#{changeset_id}']", 1
206 assert_select "osm>changeset>discussion", 1
207 assert_select "osm>changeset>discussion>comment", 3
211 # check that a changeset that doesn't exist returns an appropriate message
212 def test_read_not_found
213 [0, -32, 233455644, "afg", "213"].each do |id|
216 assert_response :not_found, "should get a not found"
217 rescue ActionController::UrlGenerationError => ex
218 assert_match /No route matches/, ex.to_s
224 # test that the user who opened a change can close it
226 private_user = create(:user, :data_public => false)
227 private_changeset = create(:changeset, :user => private_user)
229 changeset = create(:changeset, :user => user)
231 ## Try without authentication
232 put :close, :id => changeset.id
233 assert_response :unauthorized
235 ## Try using the non-public user
236 basic_authorization private_user.email, "test"
237 put :close, :id => private_changeset.id
238 assert_require_public_data
240 ## The try with the public user
241 basic_authorization user.email, "test"
244 put :close, :id => cs_id
245 assert_response :success
247 # test that it really is closed now
248 cs = Changeset.find(cs_id)
250 "changeset should be closed now (#{cs.closed_at} > #{Time.now.getutc}.")
254 # test that a different user can't close another user's changeset
255 def test_close_invalid
257 changeset = create(:changeset)
259 basic_authorization user.email, "test"
261 put :close, :id => changeset.id
262 assert_response :conflict
263 assert_equal "The user doesn't own that changeset", @response.body
267 # test that you can't close using another method
268 def test_close_method_invalid
270 changeset = create(:changeset, :user => user)
272 basic_authorization user.email, "test"
274 get :close, :id => changeset.id
275 assert_response :method_not_allowed
277 post :close, :id => changeset.id
278 assert_response :method_not_allowed
282 # check that you can't close a changeset that isn't found
283 def test_close_not_found
284 cs_ids = [0, -132, "123"]
286 # First try to do it with no auth
289 put :close, :id => id
290 assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
291 rescue ActionController::UrlGenerationError => ex
292 assert_match /No route matches/, ex.to_s
297 basic_authorization create(:user).email, "test"
300 put :close, :id => id
301 assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
302 rescue ActionController::UrlGenerationError => ex
303 assert_match /No route matches/, ex.to_s
309 # upload something simple, but valid and check that it can
311 # Also try without auth and another user.
312 def test_upload_simple_valid
313 private_user = create(:user, :data_public => false)
314 private_changeset = create(:changeset, :user => private_user)
316 changeset = create(:changeset, :user => user)
320 relation = create(:relation)
321 other_relation = create(:relation)
322 # create some tags, since we test that they are removed later
323 create(:node_tag, :node => node)
324 create(:way_tag, :way => way)
325 create(:relation_tag, :relation => relation)
328 changeset_id = changeset.id
330 # simple diff to change a node, way and relation by removing
335 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
336 <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
337 <nd ref='#{node.id}'/>
341 <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
342 <member type='way' role='some' ref='#{way.id}'/>
343 <member type='node' role='some' ref='#{node.id}'/>
344 <member type='relation' role='some' ref='#{other_relation.id}'/>
352 post :upload, :id => changeset_id
353 assert_response :unauthorized,
354 "shouldn't be able to upload a simple valid diff to changeset: #{@response.body}"
356 ## Now try with a private user
357 basic_authorization private_user.email, "test"
358 changeset_id = private_changeset.id
360 # simple diff to change a node, way and relation by removing
365 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
366 <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
367 <nd ref='#{node.id}'/>
371 <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
372 <member type='way' role='some' ref='#{way.id}'/>
373 <member type='node' role='some' ref='#{node.id}'/>
374 <member type='relation' role='some' ref='#{other_relation.id}'/>
382 post :upload, :id => changeset_id
383 assert_response :forbidden,
384 "can't upload a simple valid diff to changeset: #{@response.body}"
386 ## Now try with the public user
387 basic_authorization user.email, "test"
388 changeset_id = changeset.id
390 # simple diff to change a node, way and relation by removing
395 <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
396 <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
397 <nd ref='#{node.id}'/>
401 <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
402 <member type='way' role='some' ref='#{way.id}'/>
403 <member type='node' role='some' ref='#{node.id}'/>
404 <member type='relation' role='some' ref='#{other_relation.id}'/>
412 post :upload, :id => changeset_id
413 assert_response :success,
414 "can't upload a simple valid diff to changeset: #{@response.body}"
416 # check that the changes made it into the database
417 assert_equal 0, Node.find(node.id).tags.size, "node #{node.id} should now have no tags"
418 assert_equal 0, Way.find(way.id).tags.size, "way #{way.id} should now have no tags"
419 assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags"
423 # upload something which creates new objects using placeholders
424 def test_upload_create_valid
426 changeset = create(:changeset, :user => user)
428 basic_authorization user.email, "test"
430 # simple diff to create a node way and relation using placeholders
434 <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
435 <tag k='foo' v='bar'/>
436 <tag k='baz' v='bat'/>
438 <way id='-1' changeset='#{changeset.id}'>
443 <relation id='-1' changeset='#{changeset.id}'>
444 <member type='way' role='some' ref='3'/>
445 <member type='node' role='some' ref='5'/>
446 <member type='relation' role='some' ref='3'/>
454 post :upload, :id => changeset.id
455 assert_response :success,
456 "can't upload a simple valid creation to changeset: #{@response.body}"
458 # check the returned payload
459 assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
460 assert_select "diffResult>node", 1
461 assert_select "diffResult>way", 1
462 assert_select "diffResult>relation", 1
464 # inspect the response to find out what the new element IDs are
465 doc = XML::Parser.string(@response.body).parse
466 new_node_id = doc.find("//diffResult/node").first["new_id"].to_i
467 new_way_id = doc.find("//diffResult/way").first["new_id"].to_i
468 new_rel_id = doc.find("//diffResult/relation").first["new_id"].to_i
470 # check the old IDs are all present and negative one
471 assert_equal -1, doc.find("//diffResult/node").first["old_id"].to_i
472 assert_equal -1, doc.find("//diffResult/way").first["old_id"].to_i
473 assert_equal -1, doc.find("//diffResult/relation").first["old_id"].to_i
475 # check the versions are present and equal one
476 assert_equal 1, doc.find("//diffResult/node").first["new_version"].to_i
477 assert_equal 1, doc.find("//diffResult/way").first["new_version"].to_i
478 assert_equal 1, doc.find("//diffResult/relation").first["new_version"].to_i
480 # check that the changes made it into the database
481 assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
482 assert_equal 0, Way.find(new_way_id).tags.size, "new way should have no tags"
483 assert_equal 0, Relation.find(new_rel_id).tags.size, "new relation should have no tags"
487 # test a complex delete where we delete elements which rely on eachother
488 # in the same transaction.
489 def test_upload_delete
490 basic_authorization changesets(:public_user_first_change).user.display_name, "test"
492 diff = XML::Document.new
493 diff.root = XML::Node.new "osmChange"
494 delete = XML::Node.new "delete"
496 delete << current_relations(:visible_relation).to_xml_node
497 delete << current_relations(:used_relation).to_xml_node
498 delete << current_ways(:used_way).to_xml_node
499 delete << current_nodes(:node_used_by_relationship).to_xml_node
501 # update the changeset to one that this user owns
502 changeset_id = changesets(:public_user_first_change).id
503 %w(node way relation).each do |type|
504 delete.find("//osmChange/delete/#{type}").each do |n|
505 n["changeset"] = changeset_id.to_s
511 post :upload, :id => changeset_id
512 assert_response :success,
513 "can't upload a deletion diff to changeset: #{@response.body}"
515 # check the response is well-formed
516 assert_select "diffResult>node", 1
517 assert_select "diffResult>way", 1
518 assert_select "diffResult>relation", 2
520 # check that everything was deleted
521 assert_equal false, Node.find(current_nodes(:node_used_by_relationship).id).visible
522 assert_equal false, Way.find(current_ways(:used_way).id).visible
523 assert_equal false, Relation.find(current_relations(:visible_relation).id).visible
524 assert_equal false, Relation.find(current_relations(:used_relation).id).visible
528 # test uploading a delete with no lat/lon, as they are optional in
529 # the osmChange spec.
530 def test_upload_nolatlon_delete
531 basic_authorization changesets(:public_user_first_change).user.display_name, "test"
533 node = current_nodes(:public_visible_node)
534 cs = changesets(:public_user_first_change)
535 diff = "<osmChange><delete><node id='#{node.id}' version='#{node.version}' changeset='#{cs.id}'/></delete></osmChange>"
539 post :upload, :id => cs.id
540 assert_response :success,
541 "can't upload a deletion diff to changeset: #{@response.body}"
543 # check the response is well-formed
544 assert_select "diffResult>node", 1
546 # check that everything was deleted
547 assert_equal false, Node.find(node.id).visible
550 def test_repeated_changeset_create
552 basic_authorization create(:user).email, "test"
554 # create a temporary changeset
555 content "<osm><changeset>" +
556 "<tag k='created_by' v='osm test suite checking changesets'/>" +
558 assert_difference "Changeset.count", 1 do
561 assert_response :success
565 def test_upload_large_changeset
566 basic_authorization create(:user).email, "test"
569 content "<osm><changeset/></osm>"
571 assert_response :success, "Should be able to create a changeset: #{@response.body}"
572 changeset_id = @response.body.to_i
574 # upload some widely-spaced nodes, spiralling positive and negative to cause
575 # largest bbox over-expansion possible.
579 <node id='-1' lon='-20' lat='-10' changeset='#{changeset_id}'/>
580 <node id='-10' lon='20' lat='10' changeset='#{changeset_id}'/>
581 <node id='-2' lon='-40' lat='-20' changeset='#{changeset_id}'/>
582 <node id='-11' lon='40' lat='20' changeset='#{changeset_id}'/>
583 <node id='-3' lon='-60' lat='-30' changeset='#{changeset_id}'/>
584 <node id='-12' lon='60' lat='30' changeset='#{changeset_id}'/>
585 <node id='-4' lon='-80' lat='-40' changeset='#{changeset_id}'/>
586 <node id='-13' lon='80' lat='40' changeset='#{changeset_id}'/>
587 <node id='-5' lon='-100' lat='-50' changeset='#{changeset_id}'/>
588 <node id='-14' lon='100' lat='50' changeset='#{changeset_id}'/>
589 <node id='-6' lon='-120' lat='-60' changeset='#{changeset_id}'/>
590 <node id='-15' lon='120' lat='60' changeset='#{changeset_id}'/>
591 <node id='-7' lon='-140' lat='-70' changeset='#{changeset_id}'/>
592 <node id='-16' lon='140' lat='70' changeset='#{changeset_id}'/>
593 <node id='-8' lon='-160' lat='-80' changeset='#{changeset_id}'/>
594 <node id='-17' lon='160' lat='80' changeset='#{changeset_id}'/>
595 <node id='-9' lon='-179.9' lat='-89.9' changeset='#{changeset_id}'/>
596 <node id='-18' lon='179.9' lat='89.9' changeset='#{changeset_id}'/>
601 # upload it, which used to cause an error like "PGError: ERROR:
602 # integer out of range" (bug #2152). but shouldn't any more.
604 post :upload, :id => changeset_id
605 assert_response :success,
606 "can't upload a spatially-large diff to changeset: #{@response.body}"
608 # check that the changeset bbox is within bounds
609 cs = Changeset.find(changeset_id)
610 assert cs.min_lon >= -180 * GeoRecord::SCALE, "Minimum longitude (#{cs.min_lon / GeoRecord::SCALE}) should be >= -180 to be valid."
611 assert cs.max_lon <= 180 * GeoRecord::SCALE, "Maximum longitude (#{cs.max_lon / GeoRecord::SCALE}) should be <= 180 to be valid."
612 assert cs.min_lat >= -90 * GeoRecord::SCALE, "Minimum latitude (#{cs.min_lat / GeoRecord::SCALE}) should be >= -90 to be valid."
613 assert cs.max_lat >= 90 * GeoRecord::SCALE, "Maximum latitude (#{cs.max_lat / GeoRecord::SCALE}) should be <= 90 to be valid."
617 # test that deleting stuff in a transaction doesn't bypass the checks
618 # to ensure that used elements are not deleted.
619 def test_upload_delete_invalid
620 basic_authorization changesets(:public_user_first_change).user.email, "test"
621 cs = changesets(:public_user_first_change)
623 diff = XML::Document.new
624 diff.root = XML::Node.new "osmChange"
625 delete = XML::Node.new "delete"
627 delete << current_relations(:public_visible_relation).to_xml_node
628 delete << current_ways(:used_way).to_xml_node
629 delete << current_nodes(:node_used_by_relationship).to_xml_node
633 post :upload, :id => cs.id
634 assert_response :precondition_failed,
635 "shouldn't be able to upload a invalid deletion diff: #{@response.body}"
636 assert_equal "Precondition failed: Way 3 is still used by relations 1.", @response.body
638 # check that nothing was, in fact, deleted
639 assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
640 assert_equal true, Way.find(current_ways(:used_way).id).visible
641 assert_equal true, Relation.find(current_relations(:visible_relation).id).visible
645 # test that a conditional delete of an in use object works.
646 def test_upload_delete_if_unused
647 basic_authorization changesets(:public_user_first_change).user.email, "test"
648 cs = changesets(:public_user_first_change)
650 diff = XML::Document.new
651 diff.root = XML::Node.new "osmChange"
652 delete = XML::Node.new "delete"
654 delete["if-unused"] = ""
655 delete << current_relations(:public_used_relation).to_xml_node
656 delete << current_ways(:used_way).to_xml_node
657 delete << current_nodes(:node_used_by_relationship).to_xml_node
661 post :upload, :id => cs.id
662 assert_response :success,
663 "can't do a conditional delete of in use objects: #{@response.body}"
665 # check the returned payload
666 assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
667 assert_select "diffResult>node", 1
668 assert_select "diffResult>way", 1
669 assert_select "diffResult>relation", 1
672 doc = XML::Parser.string(@response.body).parse
674 # check the old IDs are all present and what we expect
675 assert_equal current_nodes(:node_used_by_relationship).id, doc.find("//diffResult/node").first["old_id"].to_i
676 assert_equal current_ways(:used_way).id, doc.find("//diffResult/way").first["old_id"].to_i
677 assert_equal current_relations(:public_used_relation).id, doc.find("//diffResult/relation").first["old_id"].to_i
679 # check the new IDs are all present and unchanged
680 assert_equal current_nodes(:node_used_by_relationship).id, doc.find("//diffResult/node").first["new_id"].to_i
681 assert_equal current_ways(:used_way).id, doc.find("//diffResult/way").first["new_id"].to_i
682 assert_equal current_relations(:public_used_relation).id, doc.find("//diffResult/relation").first["new_id"].to_i
684 # check the new versions are all present and unchanged
685 assert_equal current_nodes(:node_used_by_relationship).version, doc.find("//diffResult/node").first["new_version"].to_i
686 assert_equal current_ways(:used_way).version, doc.find("//diffResult/way").first["new_version"].to_i
687 assert_equal current_relations(:public_used_relation).version, doc.find("//diffResult/relation").first["new_version"].to_i
689 # check that nothing was, in fact, deleted
690 assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible
691 assert_equal true, Way.find(current_ways(:used_way).id).visible
692 assert_equal true, Relation.find(current_relations(:public_used_relation).id).visible
696 # upload an element with a really long tag value
697 def test_upload_invalid_too_long_tag
698 basic_authorization changesets(:public_user_first_change).user.email, "test"
699 cs_id = changesets(:public_user_first_change).id
701 # simple diff to create a node way and relation using placeholders
705 <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
706 <tag k='foo' v='#{'x' * 256}'/>
714 post :upload, :id => cs_id
715 assert_response :bad_request,
716 "shoudln't be able to upload too long a tag to changeset: #{@response.body}"
720 # upload something which creates new objects and inserts them into
721 # existing containers using placeholders.
722 def test_upload_complex
723 basic_authorization changesets(:public_user_first_change).user.email, "test"
724 cs_id = changesets(:public_user_first_change).id
726 # simple diff to create a node way and relation using placeholders
730 <node id='-1' lon='0' lat='0' changeset='#{cs_id}'>
731 <tag k='foo' v='bar'/>
732 <tag k='baz' v='bat'/>
736 <way id='1' changeset='#{cs_id}' version='1'>
740 <relation id='1' changeset='#{cs_id}' version='1'>
741 <member type='way' role='some' ref='3'/>
742 <member type='node' role='some' ref='-1'/>
743 <member type='relation' role='some' ref='3'/>
751 post :upload, :id => cs_id
752 assert_response :success,
753 "can't upload a complex diff to changeset: #{@response.body}"
755 # check the returned payload
756 assert_select "diffResult[version='#{API_VERSION}'][generator='#{GENERATOR}']", 1
757 assert_select "diffResult>node", 1
758 assert_select "diffResult>way", 1
759 assert_select "diffResult>relation", 1
761 # inspect the response to find out what the new element IDs are
762 doc = XML::Parser.string(@response.body).parse
763 new_node_id = doc.find("//diffResult/node").first["new_id"].to_i
765 # check that the changes made it into the database
766 assert_equal 2, Node.find(new_node_id).tags.size, "new node should have two tags"
767 assert_equal [new_node_id, 3], Way.find(1).nds, "way nodes should match"
768 Relation.find(1).members.each do |type, id, _role|
770 assert_equal new_node_id, id, "relation should contain new node"
776 # create a diff which references several changesets, which should cause
777 # a rollback and none of the diff gets committed
778 def test_upload_invalid_changesets
779 basic_authorization changesets(:public_user_first_change).user.email, "test"
780 cs_id = changesets(:public_user_first_change).id
782 # simple diff to create a node way and relation using placeholders
786 <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
787 <way id='1' changeset='#{cs_id}' version='1'>
792 <relation id='1' changeset='#{cs_id}' version='1'>
793 <member type='way' role='some' ref='3'/>
794 <member type='node' role='some' ref='5'/>
795 <member type='relation' role='some' ref='3'/>
799 <node id='-1' lon='0' lat='0' changeset='4'>
800 <tag k='foo' v='bar'/>
801 <tag k='baz' v='bat'/>
806 # cache the objects before uploading them
807 node = current_nodes(:visible_node)
808 way = current_ways(:visible_way)
809 rel = current_relations(:visible_relation)
813 post :upload, :id => cs_id
814 assert_response :conflict,
815 "uploading a diff with multiple changsets should have failed"
817 # check that objects are unmodified
818 assert_nodes_are_equal(node, Node.find(1))
819 assert_ways_are_equal(way, Way.find(1))
820 assert_relations_are_equal(rel, Relation.find(1))
824 # upload multiple versions of the same element in the same diff.
825 def test_upload_multiple_valid
826 basic_authorization changesets(:public_user_first_change).user.email, "test"
827 cs_id = changesets(:public_user_first_change).id
829 # change the location of a node multiple times, each time referencing
830 # the last version. doesn't this depend on version numbers being
835 <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
836 <node id='1' lon='1' lat='0' changeset='#{cs_id}' version='2'/>
837 <node id='1' lon='1' lat='1' changeset='#{cs_id}' version='3'/>
838 <node id='1' lon='1' lat='2' changeset='#{cs_id}' version='4'/>
839 <node id='1' lon='2' lat='2' changeset='#{cs_id}' version='5'/>
840 <node id='1' lon='3' lat='2' changeset='#{cs_id}' version='6'/>
841 <node id='1' lon='3' lat='3' changeset='#{cs_id}' version='7'/>
842 <node id='1' lon='9' lat='9' changeset='#{cs_id}' version='8'/>
849 post :upload, :id => cs_id
850 assert_response :success,
851 "can't upload multiple versions of an element in a diff: #{@response.body}"
853 # check the response is well-formed. its counter-intuitive, but the
854 # API will return multiple elements with the same ID and different
855 # version numbers for each change we made.
856 assert_select "diffResult>node", 8
860 # upload multiple versions of the same element in the same diff, but
861 # keep the version numbers the same.
862 def test_upload_multiple_duplicate
863 basic_authorization changesets(:public_user_first_change).user.email, "test"
864 cs_id = changesets(:public_user_first_change).id
869 <node id='1' lon='0' lat='0' changeset='#{cs_id}' version='1'/>
870 <node id='1' lon='1' lat='1' changeset='#{cs_id}' version='1'/>
877 post :upload, :id => cs_id
878 assert_response :conflict,
879 "shouldn't be able to upload the same element twice in a diff: #{@response.body}"
883 # try to upload some elements without specifying the version
884 def test_upload_missing_version
885 basic_authorization changesets(:public_user_first_change).user.email, "test"
886 cs_id = changesets(:public_user_first_change).id
891 <node id='1' lon='1' lat='1' changeset='cs_id'/>
898 post :upload, :id => cs_id
899 assert_response :bad_request,
900 "shouldn't be able to upload an element without version: #{@response.body}"
904 # try to upload with commands other than create, modify, or delete
905 def test_action_upload_invalid
906 basic_authorization changesets(:public_user_first_change).user.email, "test"
907 cs_id = changesets(:public_user_first_change).id
912 <node id='1' lon='1' lat='1' changeset='#{cs_id}' />
917 post :upload, :id => cs_id
918 assert_response :bad_request, "Shouldn't be able to upload a diff with the action ping"
919 assert_equal @response.body, "Unknown action ping, choices are create, modify, delete"
923 # upload a valid changeset which has a mixture of whitespace
924 # to check a bug reported by ivansanchez (#1565).
925 def test_upload_whitespace_valid
926 basic_authorization changesets(:public_user_first_change).user.email, "test"
927 changeset_id = changesets(:public_user_first_change).id
931 <modify><node id='1' lon='0' lat='0' changeset='#{changeset_id}'
933 <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='2'><tag k='k' v='v'/></node></modify>
935 <relation id='1' changeset='#{changeset_id}' version='1'><member
936 type='way' role='some' ref='3'/><member
937 type='node' role='some' ref='5'/>
938 <member type='relation' role='some' ref='3'/>
940 </modify></osmChange>
945 post :upload, :id => changeset_id
946 assert_response :success,
947 "can't upload a valid diff with whitespace variations to changeset: #{@response.body}"
949 # check the response is well-formed
950 assert_select "diffResult>node", 2
951 assert_select "diffResult>relation", 1
953 # check that the changes made it into the database
954 assert_equal 1, Node.find(1).tags.size, "node 1 should now have one tag"
955 assert_equal 0, Relation.find(1).tags.size, "relation 1 should now have no tags"
959 # upload a valid changeset which has a mixture of whitespace
960 # to check a bug reported by ivansanchez.
961 def test_upload_reuse_placeholder_valid
962 basic_authorization changesets(:public_user_first_change).user.email, "test"
963 changeset_id = changesets(:public_user_first_change).id
968 <node id='-1' lon='0' lat='0' changeset='#{changeset_id}'>
969 <tag k="foo" v="bar"/>
973 <node id='-1' lon='1' lat='1' changeset='#{changeset_id}' version='1'/>
976 <node id='-1' lon='2' lat='2' changeset='#{changeset_id}' version='2'/>
983 post :upload, :id => changeset_id
984 assert_response :success,
985 "can't upload a valid diff with re-used placeholders to changeset: #{@response.body}"
987 # check the response is well-formed
988 assert_select "diffResult>node", 3
989 assert_select "diffResult>node[old_id='-1']", 3
993 # test what happens if a diff upload re-uses placeholder IDs in an
995 def test_upload_placeholder_invalid
996 basic_authorization changesets(:public_user_first_change).user.email, "test"
997 changeset_id = changesets(:public_user_first_change).id
1002 <node id='-1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
1003 <node id='-1' lon='1' lat='1' changeset='#{changeset_id}' version='1'/>
1004 <node id='-1' lon='2' lat='2' changeset='#{changeset_id}' version='2'/>
1011 post :upload, :id => changeset_id
1012 assert_response :bad_request,
1013 "shouldn't be able to re-use placeholder IDs"
1017 # test that uploading a way referencing invalid placeholders gives a
1018 # proper error, not a 500.
1019 def test_upload_placeholder_invalid_way
1020 basic_authorization changesets(:public_user_first_change).user.email, "test"
1021 changeset_id = changesets(:public_user_first_change).id
1026 <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
1027 <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
1028 <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
1029 <way id="-1" changeset="#{changeset_id}" version="1">
1041 post :upload, :id => changeset_id
1042 assert_response :bad_request,
1043 "shouldn't be able to use invalid placeholder IDs"
1044 assert_equal "Placeholder node not found for reference -4 in way -1", @response.body
1046 # the same again, but this time use an existing way
1050 <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
1051 <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
1052 <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
1053 <way id="1" changeset="#{changeset_id}" version="1">
1065 post :upload, :id => changeset_id
1066 assert_response :bad_request,
1067 "shouldn't be able to use invalid placeholder IDs"
1068 assert_equal "Placeholder node not found for reference -4 in way 1", @response.body
1072 # test that uploading a relation referencing invalid placeholders gives a
1073 # proper error, not a 500.
1074 def test_upload_placeholder_invalid_relation
1075 basic_authorization changesets(:public_user_first_change).user.email, "test"
1076 changeset_id = changesets(:public_user_first_change).id
1081 <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
1082 <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
1083 <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
1084 <relation id="-1" changeset="#{changeset_id}" version="1">
1085 <member type="node" role="foo" ref="-1"/>
1086 <member type="node" role="foo" ref="-2"/>
1087 <member type="node" role="foo" ref="-3"/>
1088 <member type="node" role="foo" ref="-4"/>
1096 post :upload, :id => changeset_id
1097 assert_response :bad_request,
1098 "shouldn't be able to use invalid placeholder IDs"
1099 assert_equal "Placeholder Node not found for reference -4 in relation -1.", @response.body
1101 # the same again, but this time use an existing way
1105 <node id="-1" lon="0" lat="0" changeset="#{changeset_id}" version="1"/>
1106 <node id="-2" lon="1" lat="1" changeset="#{changeset_id}" version="1"/>
1107 <node id="-3" lon="2" lat="2" changeset="#{changeset_id}" version="1"/>
1108 <relation id="1" changeset="#{changeset_id}" version="1">
1109 <member type="node" role="foo" ref="-1"/>
1110 <member type="node" role="foo" ref="-2"/>
1111 <member type="node" role="foo" ref="-3"/>
1112 <member type="way" role="bar" ref="-1"/>
1120 post :upload, :id => changeset_id
1121 assert_response :bad_request,
1122 "shouldn't be able to use invalid placeholder IDs"
1123 assert_equal "Placeholder Way not found for reference -1 in relation 1.", @response.body
1127 # test what happens if a diff is uploaded containing only a node
1129 def test_upload_node_move
1130 basic_authorization create(:user).email, "test"
1132 content "<osm><changeset>" +
1133 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1134 "</changeset></osm>"
1136 assert_response :success
1137 changeset_id = @response.body.to_i
1139 old_node = current_nodes(:visible_node)
1141 diff = XML::Document.new
1142 diff.root = XML::Node.new "osmChange"
1143 modify = XML::Node.new "modify"
1144 xml_old_node = old_node.to_xml_node
1145 xml_old_node["lat"] = 2.0.to_s
1146 xml_old_node["lon"] = 2.0.to_s
1147 xml_old_node["changeset"] = changeset_id.to_s
1148 modify << xml_old_node
1153 post :upload, :id => changeset_id
1154 assert_response :success,
1155 "diff should have uploaded OK"
1158 changeset = Changeset.find(changeset_id)
1159 assert_equal 1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 1 degree"
1160 assert_equal 2 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 2 degrees"
1161 assert_equal 1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1 degree"
1162 assert_equal 2 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 2 degrees"
1166 # test what happens if a diff is uploaded adding a node to a way.
1167 def test_upload_way_extend
1168 basic_authorization create(:user).email, "test"
1170 content "<osm><changeset>" +
1171 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1172 "</changeset></osm>"
1174 assert_response :success
1175 changeset_id = @response.body.to_i
1177 old_way = current_ways(:visible_way)
1179 diff = XML::Document.new
1180 diff.root = XML::Node.new "osmChange"
1181 modify = XML::Node.new "modify"
1182 xml_old_way = old_way.to_xml_node
1183 nd_ref = XML::Node.new "nd"
1184 nd_ref["ref"] = current_nodes(:visible_node).id.to_s
1185 xml_old_way << nd_ref
1186 xml_old_way["changeset"] = changeset_id.to_s
1187 modify << xml_old_way
1192 post :upload, :id => changeset_id
1193 assert_response :success,
1194 "diff should have uploaded OK"
1197 changeset = Changeset.find(changeset_id)
1198 assert_equal 1 * GeoRecord::SCALE, changeset.min_lon, "min_lon should be 1 degree"
1199 assert_equal 3 * GeoRecord::SCALE, changeset.max_lon, "max_lon should be 3 degrees"
1200 assert_equal 1 * GeoRecord::SCALE, changeset.min_lat, "min_lat should be 1 degree"
1201 assert_equal 3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 3 degrees"
1205 # test for more issues in #1568
1206 def test_upload_empty_invalid
1207 basic_authorization changesets(:public_user_first_change).user.email, "test"
1210 "<osmChange></osmChange>",
1211 "<osmChange><modify/></osmChange>",
1212 "<osmChange><modify></modify></osmChange>"].each do |diff|
1215 post :upload, :id => changesets(:public_user_first_change).id
1216 assert_response(:success, "should be able to upload " +
1217 "empty changeset: " + diff)
1222 # test that the X-Error-Format header works to request XML errors
1223 def test_upload_xml_errors
1224 basic_authorization changesets(:public_user_first_change).user.email, "test"
1225 cs = changesets(:public_user_first_change)
1227 # try and delete a node that is in use
1228 diff = XML::Document.new
1229 diff.root = XML::Node.new "osmChange"
1230 delete = XML::Node.new "delete"
1232 delete << current_nodes(:node_used_by_relationship).to_xml_node
1237 post :upload, :id => cs.id
1238 assert_response :success,
1239 "failed to return error in XML format"
1241 # check the returned payload
1242 assert_select "osmError[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
1243 assert_select "osmError>status", 1
1244 assert_select "osmError>message", 1
1248 # when we make some simple changes we get the same changes back from the
1250 def test_diff_download_simple
1251 ## First try with a non-public user, which should get a forbidden
1252 basic_authorization(create(:user, :data_public => false).email, "test")
1254 # create a temporary changeset
1255 content "<osm><changeset>" +
1256 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1257 "</changeset></osm>"
1259 assert_response :forbidden
1261 ## Now try with a normal user
1262 basic_authorization(create(:user).email, "test")
1264 # create a temporary changeset
1265 content "<osm><changeset>" +
1266 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1267 "</changeset></osm>"
1269 assert_response :success
1270 changeset_id = @response.body.to_i
1276 <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
1277 <node id='1' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
1278 <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
1279 <node id='1' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
1280 <node id='1' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
1281 <node id='1' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
1282 <node id='1' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
1283 <node id='1' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
1290 post :upload, :id => changeset_id
1291 assert_response :success,
1292 "can't upload multiple versions of an element in a diff: #{@response.body}"
1294 get :download, :id => changeset_id
1295 assert_response :success
1297 assert_select "osmChange", 1
1298 assert_select "osmChange>modify", 8
1299 assert_select "osmChange>modify>node", 8
1303 # culled this from josm to ensure that nothing in the way that josm
1304 # is formatting the request is causing it to fail.
1306 # NOTE: the error turned out to be something else completely!
1307 def test_josm_upload
1308 basic_authorization(create(:user).email, "test")
1310 # create a temporary changeset
1311 content "<osm><changeset>" +
1312 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1313 "</changeset></osm>"
1315 assert_response :success
1316 changeset_id = @response.body.to_i
1319 <osmChange version="0.6" generator="JOSM">
1320 <create version="0.6" generator="JOSM">
1321 <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
1322 <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
1323 <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
1324 <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
1325 <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
1326 <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
1327 <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
1328 <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
1329 <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
1330 <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
1340 <tag k='highway' v='residential' />
1341 <tag k='name' v='Foobar Street' />
1349 post :upload, :id => changeset_id
1350 assert_response :success,
1351 "can't upload a diff from JOSM: #{@response.body}"
1353 get :download, :id => changeset_id
1354 assert_response :success
1356 assert_select "osmChange", 1
1357 assert_select "osmChange>create>node", 9
1358 assert_select "osmChange>create>way", 1
1359 assert_select "osmChange>create>way>nd", 9
1360 assert_select "osmChange>create>way>tag", 2
1364 # when we make some complex changes we get the same changes back from the
1366 def test_diff_download_complex
1367 basic_authorization(create(:user).email, "test")
1369 # create a temporary changeset
1370 content "<osm><changeset>" +
1371 "<tag k='created_by' v='osm test suite checking changesets'/>" +
1372 "</changeset></osm>"
1374 assert_response :success
1375 changeset_id = @response.body.to_i
1381 <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
1384 <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
1385 <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
1386 <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
1389 <node id='3' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
1390 <way id='1' changeset='#{changeset_id}' version='1'>
1402 post :upload, :id => changeset_id
1403 assert_response :success,
1404 "can't upload multiple versions of an element in a diff: #{@response.body}"
1406 get :download, :id => changeset_id
1407 assert_response :success
1409 assert_select "osmChange", 1
1410 assert_select "osmChange>create", 3
1411 assert_select "osmChange>delete", 1
1412 assert_select "osmChange>modify", 2
1413 assert_select "osmChange>create>node", 3
1414 assert_select "osmChange>delete>node", 1
1415 assert_select "osmChange>modify>node", 1
1416 assert_select "osmChange>modify>way", 1
1419 def test_changeset_download
1420 tag = create(:old_node_tag, :old_node => nodes(:used_node_2))
1422 get :download, :id => changesets(:normal_user_first_change).id
1424 assert_response :success
1426 # print @response.body
1427 # FIXME: needs more assert_select tests
1428 assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
1429 assert_select "create", :count => 5
1430 assert_select "create>node[id='#{nodes(:used_node_2).node_id}'][visible='#{nodes(:used_node_2).visible?}'][version='#{nodes(:used_node_2).version}']" do
1431 assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
1433 assert_select "create>node[id='#{nodes(:visible_node).node_id}']"
1438 # check that the bounding box of a changeset gets updated correctly
1439 # FIXME: This should really be moded to a integration test due to the with_controller
1440 def test_changeset_bbox
1441 basic_authorization create(:user).email, "test"
1443 # create a new changeset
1444 content "<osm><changeset/></osm>"
1446 assert_response :success, "Creating of changeset failed."
1447 changeset_id = @response.body.to_i
1449 # add a single node to it
1450 with_controller(NodeController.new) do
1451 content "<osm><node lon='1' lat='2' changeset='#{changeset_id}'/></osm>"
1453 assert_response :success, "Couldn't create node."
1456 # get the bounding box back from the changeset
1457 get :read, :id => changeset_id
1458 assert_response :success, "Couldn't read back changeset."
1459 assert_select "osm>changeset[min_lon='1.0']", 1
1460 assert_select "osm>changeset[max_lon='1.0']", 1
1461 assert_select "osm>changeset[min_lat='2.0']", 1
1462 assert_select "osm>changeset[max_lat='2.0']", 1
1464 # add another node to it
1465 with_controller(NodeController.new) do
1466 content "<osm><node lon='2' lat='1' changeset='#{changeset_id}'/></osm>"
1468 assert_response :success, "Couldn't create second node."
1471 # get the bounding box back from the changeset
1472 get :read, :id => changeset_id
1473 assert_response :success, "Couldn't read back changeset for the second time."
1474 assert_select "osm>changeset[min_lon='1.0']", 1
1475 assert_select "osm>changeset[max_lon='2.0']", 1
1476 assert_select "osm>changeset[min_lat='1.0']", 1
1477 assert_select "osm>changeset[max_lat='2.0']", 1
1479 # add (delete) a way to it, which contains a point at (3,3)
1480 with_controller(WayController.new) do
1481 content update_changeset(current_ways(:visible_way).to_xml,
1483 put :delete, :id => current_ways(:visible_way).id
1484 assert_response :success, "Couldn't delete a way."
1487 # get the bounding box back from the changeset
1488 get :read, :id => changeset_id
1489 assert_response :success, "Couldn't read back changeset for the third time."
1490 # note that the 3.1 here is because of the bbox overexpansion
1491 assert_select "osm>changeset[min_lon='1.0']", 1
1492 assert_select "osm>changeset[max_lon='3.1']", 1
1493 assert_select "osm>changeset[min_lat='1.0']", 1
1494 assert_select "osm>changeset[max_lat='3.1']", 1
1498 # test that the changeset :include method works as it should
1499 def test_changeset_include
1500 basic_authorization create(:user).display_name, "test"
1502 # create a new changeset
1503 content "<osm><changeset/></osm>"
1505 assert_response :success, "Creating of changeset failed."
1506 changeset_id = @response.body.to_i
1508 # NOTE: the include method doesn't over-expand, like inserting
1509 # a real method does. this is because we expect the client to
1510 # know what it is doing!
1511 check_after_include(changeset_id, 1, 1, [1, 1, 1, 1])
1512 check_after_include(changeset_id, 3, 3, [1, 1, 3, 3])
1513 check_after_include(changeset_id, 4, 2, [1, 1, 4, 3])
1514 check_after_include(changeset_id, 2, 2, [1, 1, 4, 3])
1515 check_after_include(changeset_id, -1, -1, [-1, -1, 4, 3])
1516 check_after_include(changeset_id, -2, 5, [-2, -1, 4, 5])
1520 # test that a not found, wrong method with the expand bbox works as expected
1521 def test_changeset_expand_bbox_error
1522 basic_authorization create(:user).display_name, "test"
1524 # create a new changeset
1525 content "<osm><changeset/></osm>"
1527 assert_response :success, "Creating of changeset failed."
1528 changeset_id = @response.body.to_i
1534 content "<osm><node lon='#{lon}' lat='#{lat}'/></osm>"
1535 put :expand_bbox, :id => changeset_id
1536 assert_response :method_not_allowed, "shouldn't be able to put a bbox expand"
1538 # Try to get the update
1539 content "<osm><node lon='#{lon}' lat='#{lat}'/></osm>"
1540 get :expand_bbox, :id => changeset_id
1541 assert_response :method_not_allowed, "shouldn't be able to get a bbox expand"
1543 # Try to use a hopefully missing changeset
1544 content "<osm><node lon='#{lon}' lat='#{lat}'/></osm>"
1545 post :expand_bbox, :id => changeset_id + 13245
1546 assert_response :not_found, "shouldn't be able to do a bbox expand on a nonexistant changeset"
1550 # test the query functionality of changesets
1552 private_user = create(:user, :data_public => false)
1553 private_user_changeset = create(:changeset, :user => private_user)
1554 private_user_closed_changeset = create(:changeset, :closed, :user => private_user)
1555 user = create(:user)
1556 changeset = create(:changeset, :user => user)
1557 closed_changeset = create(:changeset, :closed, :user => user, :created_at => Time.utc(2008, 1, 1, 0, 0, 0), :closed_at => Time.utc(2008, 1, 2, 0, 0, 0))
1559 get :query, :bbox => "-10,-10, 10, 10"
1560 assert_response :success, "can't get changesets in bbox"
1561 assert_changesets [1, 4, 6]
1563 get :query, :bbox => "4.5,4.5,4.6,4.6"
1564 assert_response :success, "can't get changesets in bbox"
1565 assert_changesets [1]
1567 # not found when looking for changesets of non-existing users
1568 get :query, :user => User.maximum(:id) + 1
1569 assert_response :not_found
1570 get :query, :display_name => " "
1571 assert_response :not_found
1573 # can't get changesets of user 1 without authenticating
1574 get :query, :user => private_user.id
1575 assert_response :not_found, "shouldn't be able to get changesets by non-public user (ID)"
1576 get :query, :display_name => private_user.display_name
1577 assert_response :not_found, "shouldn't be able to get changesets by non-public user (name)"
1579 # but this should work
1580 basic_authorization private_user.email, "test"
1581 get :query, :user => private_user.id
1582 assert_response :success, "can't get changesets by user ID"
1583 assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
1585 get :query, :display_name => private_user.display_name
1586 assert_response :success, "can't get changesets by user name"
1587 assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
1589 # check that the correct error is given when we provide both UID and name
1590 get :query, :user => private_user.id, :display_name => private_user.display_name
1591 assert_response :bad_request, "should be a bad request to have both ID and name specified"
1593 get :query, :user => private_user.id, :open => true
1594 assert_response :success, "can't get changesets by user and open"
1595 assert_changesets [private_user_changeset.id]
1597 get :query, :time => "2007-12-31"
1598 assert_response :success, "can't get changesets by time-since"
1599 assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
1601 get :query, :time => "2008-01-01T12:34Z"
1602 assert_response :success, "can't get changesets by time-since with hour"
1603 assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
1605 get :query, :time => "2007-12-31T23:59Z,2008-01-02T00:01Z"
1606 assert_response :success, "can't get changesets by time-range"
1607 assert_changesets [1, 5, 6, closed_changeset.id]
1609 get :query, :open => "true"
1610 assert_response :success, "can't get changesets by open-ness"
1611 assert_changesets [1, 2, 4, private_user_changeset.id, changeset.id]
1613 get :query, :closed => "true"
1614 assert_response :success, "can't get changesets by closed-ness"
1615 assert_changesets [3, 5, 6, 7, 8, 9, private_user_closed_changeset.id, closed_changeset.id]
1617 get :query, :closed => "true", :user => private_user.id
1618 assert_response :success, "can't get changesets by closed-ness and user"
1619 assert_changesets [private_user_closed_changeset.id]
1621 get :query, :closed => "true", :user => user.id
1622 assert_response :success, "can't get changesets by closed-ness and user"
1623 assert_changesets [closed_changeset.id]
1625 get :query, :changesets => "#{private_user_changeset.id},#{changeset.id},#{closed_changeset.id}"
1626 assert_response :success, "can't get changesets by id (as comma-separated string)"
1627 assert_changesets [private_user_changeset.id, changeset.id, closed_changeset.id]
1629 get :query, :changesets => ""
1630 assert_response :bad_request, "should be a bad request since changesets is empty"
1634 # check that errors are returned if garbage is inserted
1635 # into query strings
1636 def test_query_invalid
1639 ";drop table users;"].each do |bbox|
1640 get :query, :bbox => bbox
1641 assert_response :bad_request, "'#{bbox}' isn't a bbox"
1646 ";drop table users;",
1648 "-,-"].each do |time|
1649 get :query, :time => time
1650 assert_response :bad_request, "'#{time}' isn't a valid time range"
1657 get :query, :user => uid
1658 assert_response :bad_request, "'#{uid}' isn't a valid user ID"
1663 # check updating tags on a changeset
1664 def test_changeset_update
1665 ## First try with a non-public user
1666 changeset = changesets(:normal_user_first_change)
1667 new_changeset = changeset.to_xml
1668 new_tag = XML::Node.new "tag"
1669 new_tag["k"] = "tagtesting"
1670 new_tag["v"] = "valuetesting"
1671 new_changeset.find("//osm/changeset").first << new_tag
1672 content new_changeset
1674 # try without any authorization
1675 put :update, :id => changeset.id
1676 assert_response :unauthorized
1678 # try with the wrong authorization
1679 basic_authorization create(:user).email, "test"
1680 put :update, :id => changeset.id
1681 assert_response :conflict
1683 # now this should get an unauthorized
1684 basic_authorization changeset.user.email, "test"
1685 put :update, :id => changeset.id
1686 assert_require_public_data "user with their data non-public, shouldn't be able to edit their changeset"
1688 ## Now try with the public user
1689 changeset = changesets(:public_user_first_change)
1690 create(:changeset_tag, :changeset => changeset)
1691 new_changeset = changeset.to_xml
1692 new_tag = XML::Node.new "tag"
1693 new_tag["k"] = "tagtesting"
1694 new_tag["v"] = "valuetesting"
1695 new_changeset.find("//osm/changeset").first << new_tag
1696 content new_changeset
1698 # try without any authorization
1699 @request.env["HTTP_AUTHORIZATION"] = nil
1700 put :update, :id => changeset.id
1701 assert_response :unauthorized
1703 # try with the wrong authorization
1704 basic_authorization create(:user).email, "test"
1705 put :update, :id => changeset.id
1706 assert_response :conflict
1708 # now this should work...
1709 basic_authorization changeset.user.email, "test"
1710 put :update, :id => changeset.id
1711 assert_response :success
1713 assert_select "osm>changeset[id='#{changeset.id}']", 1
1714 assert_select "osm>changeset>tag", 2
1715 assert_select "osm>changeset>tag[k='tagtesting'][v='valuetesting']", 1
1719 # check that a user different from the one who opened the changeset
1721 def test_changeset_update_invalid
1722 basic_authorization create(:user).email, "test"
1724 changeset = changesets(:normal_user_first_change)
1725 new_changeset = changeset.to_xml
1726 new_tag = XML::Node.new "tag"
1727 new_tag["k"] = "testing"
1728 new_tag["v"] = "testing"
1729 new_changeset.find("//osm/changeset").first << new_tag
1731 content new_changeset
1732 put :update, :id => changeset.id
1733 assert_response :conflict
1737 # check that a changeset can contain a certain max number of changes.
1738 ## FIXME should be changed to an integration test due to the with_controller
1739 def test_changeset_limits
1740 basic_authorization create(:user).email, "test"
1742 # open a new changeset
1743 content "<osm><changeset/></osm>"
1745 assert_response :success, "can't create a new changeset"
1746 cs_id = @response.body.to_i
1748 # start the counter just short of where the changeset should finish.
1750 # alter the database to set the counter on the changeset directly,
1751 # otherwise it takes about 6 minutes to fill all of them.
1752 changeset = Changeset.find(cs_id)
1753 changeset.num_changes = Changeset::MAX_ELEMENTS - offset
1756 with_controller(NodeController.new) do
1758 content "<osm><node changeset='#{cs_id}' lat='0.0' lon='0.0'/></osm>"
1760 assert_response :success, "can't create a new node"
1761 node_id = @response.body.to_i
1763 get :read, :id => node_id
1764 assert_response :success, "can't read back new node"
1765 node_doc = XML::Parser.string(@response.body).parse
1766 node_xml = node_doc.find("//osm/node").first
1768 # loop until we fill the changeset with nodes
1770 node_xml["lat"] = rand.to_s
1771 node_xml["lon"] = rand.to_s
1772 node_xml["version"] = (i + 1).to_s
1775 put :update, :id => node_id
1776 assert_response :success, "attempt #{i} should have succeeded"
1779 # trying again should fail
1780 node_xml["lat"] = rand.to_s
1781 node_xml["lon"] = rand.to_s
1782 node_xml["version"] = offset.to_s
1785 put :update, :id => node_id
1786 assert_response :conflict, "final attempt should have failed"
1789 changeset = Changeset.find(cs_id)
1790 assert_equal Changeset::MAX_ELEMENTS + 1, changeset.num_changes
1792 # check that the changeset is now closed as well
1793 assert(!changeset.is_open?,
1794 "changeset should have been auto-closed by exceeding " +
1799 # This should display the last 20 changesets closed
1801 get :list, :format => "html"
1802 assert_response :success
1803 assert_template "history"
1804 assert_template :layout => "map"
1805 assert_select "h2", :text => "Changesets", :count => 1
1807 xhr :get, :list, :format => "html", :list => "1"
1808 assert_response :success
1809 assert_template "list"
1811 check_list_result(Changeset.all)
1815 # This should display the last 20 changesets closed
1817 xhr :get, :list, :format => "html"
1818 assert_response :success
1819 assert_template "history"
1820 assert_template :layout => "xhr"
1821 assert_select "h2", :text => "Changesets", :count => 1
1823 xhr :get, :list, :format => "html", :list => "1"
1824 assert_response :success
1825 assert_template "list"
1827 check_list_result(Changeset.all)
1831 # This should display the last 20 changesets closed in a specific area
1833 get :list, :format => "html", :bbox => "4.5,4.5,5.5,5.5"
1834 assert_response :success
1835 assert_template "history"
1836 assert_template :layout => "map"
1837 assert_select "h2", :text => "Changesets", :count => 1
1839 xhr :get, :list, :format => "html", :bbox => "4.5,4.5,5.5,5.5", :list => "1"
1840 assert_response :success
1841 assert_template "list"
1843 check_list_result(Changeset.where("min_lon < 55000000 and max_lon > 45000000 and min_lat < 55000000 and max_lat > 45000000"))
1847 # Checks the display of the user changesets listing
1849 user = create(:user)
1850 create(:changeset, :user => user)
1851 create(:changeset, :closed, :user => user)
1853 get :list, :format => "html", :display_name => user.display_name
1854 assert_response :success
1855 assert_template "history"
1857 xhr :get, :list, :format => "html", :display_name => user.display_name, :list => "1"
1858 assert_response :success
1859 assert_template "list"
1861 check_list_result(user.changesets)
1865 # Checks the display of the user changesets listing for a private user
1866 def test_list_private_user
1867 private_user = create(:user, :data_public => false)
1868 create(:changeset, :user => private_user)
1869 create(:changeset, :closed, :user => private_user)
1871 get :list, :format => "html", :display_name => private_user.display_name
1872 assert_response :success
1873 assert_template "history"
1875 xhr :get, :list, :format => "html", :display_name => private_user.display_name, :list => "1"
1876 assert_response :success
1877 assert_template "list"
1879 check_list_result(Changeset.none)
1883 # Check the not found of the list user changesets
1884 def test_list_user_not_found
1885 get :list, :format => "html", :display_name => "Some random user"
1886 assert_response :not_found
1887 assert_template "user/no_such_user"
1889 xhr :get, :list, :format => "html", :display_name => "Some random user", :list => "1"
1890 assert_response :not_found
1891 assert_template "user/no_such_user"
1895 # Checks the display of the friends changesets listing
1896 def test_list_friends
1897 private_user = create(:user, :data_public => true)
1898 friend = create(:friend, :befriender => private_user)
1899 create(:changeset, :user => friend.befriendee)
1901 get :list, :friends => true
1902 assert_response :redirect
1903 assert_redirected_to :controller => :user, :action => :login, :referer => friend_changesets_path
1905 session[:user] = private_user.id
1907 get :list, :friends => true
1908 assert_response :success
1909 assert_template "history"
1911 xhr :get, :list, :friends => true, :list => "1"
1912 assert_response :success
1913 assert_template "list"
1915 check_list_result(Changeset.where(:user => private_user.friend_users.identifiable))
1919 # Checks the display of the nearby user changesets listing
1920 def test_list_nearby
1921 private_user = create(:user, :data_public => false, :home_lat => 51.1, :home_lon => 1.0)
1922 user = create(:user, :home_lat => 51.0, :home_lon => 1.0)
1923 create(:changeset, :user => user)
1925 get :list, :nearby => true
1926 assert_response :redirect
1927 assert_redirected_to :controller => :user, :action => :login, :referer => nearby_changesets_path
1929 session[:user] = private_user.id
1931 get :list, :nearby => true
1932 assert_response :success
1933 assert_template "history"
1935 xhr :get, :list, :nearby => true, :list => "1"
1936 assert_response :success
1937 assert_template "list"
1939 check_list_result(Changeset.where(:user => user.nearby))
1943 # Check that we can't request later pages of the changesets list
1944 def test_list_max_id
1945 xhr :get, :list, :format => "html", :max_id => 4
1946 assert_response :success
1947 assert_template "history"
1948 assert_template :layout => "xhr"
1949 assert_select "h2", :text => "Changesets", :count => 1
1951 xhr :get, :list, :format => "html", :list => "1", :max_id => 4
1952 assert_response :success
1953 assert_template "list"
1955 check_list_result(Changeset.where("id <= 4"))
1959 # This should display the last 20 changesets closed
1961 get :feed, :format => :atom
1962 assert_response :success
1963 assert_template "list"
1964 assert_equal "application/atom+xml", response.content_type
1966 check_feed_result(Changeset.all)
1970 # This should display the last 20 changesets closed in a specific area
1972 get :feed, :format => :atom, :bbox => "4.5,4.5,5.5,5.5"
1973 assert_response :success
1974 assert_template "list"
1975 assert_equal "application/atom+xml", response.content_type
1977 check_feed_result(Changeset.where("min_lon < 55000000 and max_lon > 45000000 and min_lat < 55000000 and max_lat > 45000000"))
1981 # Checks the display of the user changesets feed
1983 user = create(:user)
1984 create_list(:changeset, 3, :user => user, :num_changes => 4)
1986 get :feed, :format => :atom, :display_name => user.display_name
1987 assert_response :success
1988 assert_template "list"
1989 assert_equal "application/atom+xml", response.content_type
1991 check_feed_result(user.changesets)
1995 # Check the not found of the user changesets feed
1996 def test_feed_user_not_found
1997 get :feed, :format => "atom", :display_name => "Some random user"
1998 assert_response :not_found
2002 # Check that we can't request later pages of the changesets feed
2003 def test_feed_max_id
2004 get :feed, :format => "atom", :max_id => 100
2005 assert_response :redirect
2006 assert_redirected_to :action => :feed
2010 # check that the changeset download for a changeset with a redacted
2011 # element in it doesn't contain that element.
2012 def test_diff_download_redacted
2013 changeset_id = changesets(:public_user_first_change).id
2015 get :download, :id => changeset_id
2016 assert_response :success
2018 assert_select "osmChange", 1
2019 # this changeset contains node 17 in versions 1 & 2, but 1 should
2021 assert_select "osmChange node[id='17']", 1
2022 assert_select "osmChange node[id='17'][version='1']", 0
2026 # create comment success
2027 def test_create_comment_success
2028 user = create(:user)
2029 user2 = create(:user)
2030 private_user = create(:user, :data_public => false)
2031 suspended_user = create(:user, :suspended)
2032 deleted_user = create(:user, :deleted)
2033 private_user_closed_changeset = create(:changeset, :closed, :user => private_user)
2035 basic_authorization(user.email, "test")
2037 assert_difference "ChangesetComment.count", 1 do
2038 assert_no_difference "ActionMailer::Base.deliveries.size" do
2039 post :comment, :id => private_user_closed_changeset.id, :text => "This is a comment"
2042 assert_response :success
2044 changeset = create(:changeset, :closed, :user => private_user)
2045 changeset.subscribers.push(private_user)
2046 changeset.subscribers.push(user)
2047 changeset.subscribers.push(suspended_user)
2048 changeset.subscribers.push(deleted_user)
2050 assert_difference "ChangesetComment.count", 1 do
2051 assert_difference "ActionMailer::Base.deliveries.size", 1 do
2052 post :comment, :id => changeset.id, :text => "This is a comment"
2055 assert_response :success
2057 email = ActionMailer::Base.deliveries.first
2058 assert_equal 1, email.to.length
2059 assert_equal "[OpenStreetMap] #{user.display_name} has commented on one of your changesets", email.subject
2060 assert_equal private_user.email, email.to.first
2062 ActionMailer::Base.deliveries.clear
2064 basic_authorization(user2.email, "test")
2066 assert_difference "ChangesetComment.count", 1 do
2067 assert_difference "ActionMailer::Base.deliveries.size", 2 do
2068 post :comment, :id => changeset.id, :text => "This is a comment"
2071 assert_response :success
2073 email = ActionMailer::Base.deliveries.find { |e| e.to.first == private_user.email }
2074 assert_not_nil email
2075 assert_equal 1, email.to.length
2076 assert_equal "[OpenStreetMap] #{user2.display_name} has commented on one of your changesets", email.subject
2078 email = ActionMailer::Base.deliveries.find { |e| e.to.first == user.email }
2079 assert_not_nil email
2080 assert_equal 1, email.to.length
2081 assert_equal "[OpenStreetMap] #{user2.display_name} has commented on a changeset you are interested in", email.subject
2083 ActionMailer::Base.deliveries.clear
2087 # create comment fail
2088 def test_create_comment_fail
2090 post :comment, :id => changesets(:normal_user_closed_change).id, :text => "This is a comment"
2091 assert_response :unauthorized
2093 basic_authorization(create(:user).email, "test")
2096 assert_no_difference "ChangesetComment.count" do
2097 post :comment, :id => 999111, :text => "This is a comment"
2099 assert_response :not_found
2101 # not closed changeset
2102 assert_no_difference "ChangesetComment.count" do
2103 post :comment, :id => changesets(:normal_user_first_change).id, :text => "This is a comment"
2105 assert_response :conflict
2108 assert_no_difference "ChangesetComment.count" do
2109 post :comment, :id => changesets(:normal_user_closed_change).id
2111 assert_response :bad_request
2114 assert_no_difference "ChangesetComment.count" do
2115 post :comment, :id => changesets(:normal_user_closed_change).id, :text => ""
2117 assert_response :bad_request
2121 # test subscribe success
2122 def test_subscribe_success
2123 basic_authorization(create(:user).email, "test")
2124 changeset = changesets(:normal_user_closed_change)
2126 assert_difference "changeset.subscribers.count", 1 do
2127 post :subscribe, :id => changeset.id
2129 assert_response :success
2133 # test subscribe fail
2134 def test_subscribe_fail
2135 user = create(:user)
2138 changeset = changesets(:normal_user_closed_change)
2139 assert_no_difference "changeset.subscribers.count" do
2140 post :subscribe, :id => changeset.id
2142 assert_response :unauthorized
2144 basic_authorization(user.email, "test")
2147 assert_no_difference "changeset.subscribers.count" do
2148 post :subscribe, :id => 999111
2150 assert_response :not_found
2152 # not closed changeset
2153 changeset = changesets(:normal_user_first_change)
2154 assert_no_difference "changeset.subscribers.count" do
2155 post :subscribe, :id => changeset.id
2157 assert_response :conflict
2159 # trying to subscribe when already subscribed
2160 changeset = changesets(:normal_user_subscribed_change)
2161 changeset.subscribers.push(user)
2162 assert_no_difference "changeset.subscribers.count" do
2163 post :subscribe, :id => changeset.id
2165 assert_response :conflict
2169 # test unsubscribe success
2170 def test_unsubscribe_success
2171 user = create(:user)
2172 basic_authorization(user.email, "test")
2173 changeset = changesets(:normal_user_subscribed_change)
2174 changeset.subscribers.push(user)
2176 assert_difference "changeset.subscribers.count", -1 do
2177 post :unsubscribe, :id => changeset.id
2179 assert_response :success
2183 # test unsubscribe fail
2184 def test_unsubscribe_fail
2186 changeset = changesets(:normal_user_closed_change)
2187 assert_no_difference "changeset.subscribers.count" do
2188 post :unsubscribe, :id => changeset.id
2190 assert_response :unauthorized
2192 basic_authorization(create(:user).email, "test")
2195 assert_no_difference "changeset.subscribers.count" do
2196 post :unsubscribe, :id => 999111
2198 assert_response :not_found
2200 # not closed changeset
2201 changeset = changesets(:normal_user_first_change)
2202 assert_no_difference "changeset.subscribers.count" do
2203 post :unsubscribe, :id => changeset.id
2205 assert_response :conflict
2207 # trying to unsubscribe when not subscribed
2208 changeset = changesets(:normal_user_closed_change)
2209 assert_no_difference "changeset.subscribers.count" do
2210 post :unsubscribe, :id => changeset.id
2212 assert_response :not_found
2216 # test hide comment fail
2217 def test_hide_comment_fail
2219 comment = create(:changeset_comment)
2220 assert_equal true, comment.visible
2222 post :hide_comment, :id => comment.id
2223 assert_response :unauthorized
2224 assert_equal true, comment.reload.visible
2226 basic_authorization(create(:user).email, "test")
2229 post :hide_comment, :id => comment.id
2230 assert_response :forbidden
2231 assert_equal true, comment.reload.visible
2233 basic_authorization(create(:moderator_user).email, "test")
2236 post :hide_comment, :id => 999111
2237 assert_response :not_found
2238 assert_equal true, comment.reload.visible
2242 # test hide comment succes
2243 def test_hide_comment_success
2244 comment = create(:changeset_comment)
2245 assert_equal true, comment.visible
2247 basic_authorization(create(:moderator_user).email, "test")
2249 post :hide_comment, :id => comment.id
2250 assert_response :success
2251 assert_equal false, comment.reload.visible
2255 # test unhide comment fail
2256 def test_unhide_comment_fail
2258 comment = create(:changeset_comment, :visible => false)
2259 assert_equal false, comment.visible
2261 post :unhide_comment, :id => comment.id
2262 assert_response :unauthorized
2263 assert_equal false, comment.reload.visible
2265 basic_authorization(create(:user).email, "test")
2268 post :unhide_comment, :id => comment.id
2269 assert_response :forbidden
2270 assert_equal false, comment.reload.visible
2272 basic_authorization(create(:moderator_user).email, "test")
2275 post :unhide_comment, :id => 999111
2276 assert_response :not_found
2277 assert_equal false, comment.reload.visible
2281 # test unhide comment succes
2282 def test_unhide_comment_success
2283 comment = create(:changeset_comment, :visible => false)
2284 assert_equal false, comment.visible
2286 basic_authorization(create(:moderator_user).email, "test")
2288 post :unhide_comment, :id => comment.id
2289 assert_response :success
2290 assert_equal true, comment.reload.visible
2294 # test comments feed
2295 def test_comments_feed
2296 create_list(:changeset_comment, 3, :changeset_id => changesets(:normal_user_closed_change).id)
2298 get :comments_feed, :format => "rss"
2299 assert_response :success
2300 assert_equal "application/rss+xml", @response.content_type
2301 assert_select "rss", :count => 1 do
2302 assert_select "channel", :count => 1 do
2303 assert_select "item", :count => 3
2307 get :comments_feed, :format => "rss", :limit => 2
2308 assert_response :success
2309 assert_equal "application/rss+xml", @response.content_type
2310 assert_select "rss", :count => 1 do
2311 assert_select "channel", :count => 1 do
2312 assert_select "item", :count => 2
2316 get :comments_feed, :id => changesets(:normal_user_closed_change), :format => "rss"
2317 assert_response :success
2318 assert_equal "application/rss+xml", @response.content_type
2319 assert_select "rss", :count => 1 do
2320 assert_select "channel", :count => 1 do
2321 assert_select "item", :count => 3
2327 # test comments feed
2328 def test_comments_feed_bad_limit
2329 get :comments_feed, :format => "rss", :limit => 0
2330 assert_response :bad_request
2332 get :comments_feed, :format => "rss", :limit => 100001
2333 assert_response :bad_request
2339 # boilerplate for checking that certain changesets exist in the
2341 def assert_changesets(ids)
2342 assert_select "osm>changeset", ids.size
2344 assert_select "osm>changeset[id='#{id}']", 1
2349 # call the include method and assert properties of the bbox
2350 def check_after_include(changeset_id, lon, lat, bbox)
2351 content "<osm><node lon='#{lon}' lat='#{lat}'/></osm>"
2352 post :expand_bbox, :id => changeset_id
2353 assert_response :success, "Setting include of changeset failed: #{@response.body}"
2355 # check exactly one changeset
2356 assert_select "osm>changeset", 1
2357 assert_select "osm>changeset[id='#{changeset_id}']", 1
2360 doc = XML::Parser.string(@response.body).parse
2361 changeset = doc.find("//osm/changeset").first
2362 assert_equal bbox[0], changeset["min_lon"].to_f, "min lon"
2363 assert_equal bbox[1], changeset["min_lat"].to_f, "min lat"
2364 assert_equal bbox[2], changeset["max_lon"].to_f, "max lon"
2365 assert_equal bbox[3], changeset["max_lat"].to_f, "max lat"
2369 # update the changeset_id of a way element
2370 def update_changeset(xml, changeset_id)
2371 xml_attr_rewrite(xml, "changeset", changeset_id)
2375 # update an attribute in a way element
2376 def xml_attr_rewrite(xml, name, value)
2377 xml.find("//osm/way").first[name] = value.to_s
2382 # check the result of a list
2383 def check_list_result(changesets)
2384 changesets = changesets.where("num_changes > 0")
2385 .order(:created_at => :desc)
2387 assert changesets.size <= 20
2389 assert_select "ol.changesets", :count => [changesets.size, 1].min do
2390 assert_select "li", :count => changesets.size
2392 changesets.each do |changeset|
2393 assert_select "li#changeset_#{changeset.id}", :count => 1
2399 # check the result of a feed
2400 def check_feed_result(changesets)
2401 changesets = changesets.where("num_changes > 0")
2402 .order(:created_at => :desc)
2404 assert changesets.size <= 20
2406 assert_select "feed", :count => [changesets.size, 1].min do
2407 assert_select "> title", :count => 1, :text => /^Changesets/
2408 assert_select "> entry", :count => changesets.size
2410 changesets.each do |changeset|
2411 assert_select "> entry > id", changeset_url(:id => changeset.id)