4 class AmfControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/api/0.6/amf/read", :method => :post },
12 { :controller => "amf", :action => "amf_read" }
15 { :path => "/api/0.6/amf/write", :method => :post },
16 { :controller => "amf", :action => "amf_write" }
21 user_en_de = create(:user, :languages => %w[en de])
22 user_de = create(:user, :languages => %w[de])
23 [user_en_de, user_de].each do |user|
24 amf_content "getpresets", "/1", ["#{user.email}:test", ""]
26 assert_response :success
28 presets = amf_result("/1")
30 assert_equal 15, presets.length
31 assert_equal POTLATCH_PRESETS[0], presets[0]
32 assert_equal POTLATCH_PRESETS[1], presets[1]
33 assert_equal POTLATCH_PRESETS[2], presets[2]
34 assert_equal POTLATCH_PRESETS[3], presets[3]
35 assert_equal POTLATCH_PRESETS[4], presets[4]
36 assert_equal POTLATCH_PRESETS[5], presets[5]
37 assert_equal POTLATCH_PRESETS[6], presets[6]
38 assert_equal POTLATCH_PRESETS[7], presets[7]
39 assert_equal POTLATCH_PRESETS[8], presets[8]
40 assert_equal POTLATCH_PRESETS[9], presets[9]
41 assert_equal POTLATCH_PRESETS[10], presets[10]
42 assert_equal POTLATCH_PRESETS[12], presets[12]
43 assert_equal user.languages.first, presets[13]["__potlatch_locale"]
49 way = create(:way_with_nodes, :nodes_count => 1)
50 node = way.nodes.first
51 user = way.changeset.user
53 amf_content "getway", "/1", [way.id]
55 assert_response :success
57 result = amf_result("/1")
58 assert_equal 0, result[0]
59 assert_equal "", result[1]
60 assert_equal way.id, result[2]
61 assert_equal 1, result[3].length
62 assert_equal node.id, result[3][0][2]
63 assert_equal way.version, result[5]
64 assert_equal user.id, result[6]
67 def test_getway_invisible
68 # check an invisible way
69 id = create(:way, :deleted).id
71 amf_content "getway", "/1", [id]
73 assert_response :success
75 result = amf_result("/1")
76 assert_equal -4, result[0]
77 assert_equal "way", result[1]
78 assert_equal id, result[2]
79 assert(result[3].nil? && result[4].nil? && result[5].nil? && result[6].nil?)
82 def test_getway_with_versions
83 # check a way with multiple versions
84 way = create(:way, :with_history, :version => 4)
85 create(:way_node, :way => way)
86 node = way.nodes.first
87 user = way.changeset.user
89 amf_content "getway", "/1", [way.id]
91 assert_response :success
93 result = amf_result("/1")
94 assert_equal 0, result[0]
95 assert_equal "", result[1]
96 assert_equal way.id, result[2]
97 assert_equal 1, result[3].length
98 assert_equal node.id, result[3][0][2]
99 assert_equal way.version, result[5]
100 assert_equal user.id, result[6]
103 def test_getway_with_duplicate_nodes
104 # check a way with duplicate nodes
107 create(:way_node, :way => way, :node => node, :sequence_id => 1)
108 create(:way_node, :way => way, :node => node, :sequence_id => 2)
109 user = way.changeset.user
111 amf_content "getway", "/1", [way.id]
113 assert_response :success
115 result = amf_result("/1")
116 assert_equal 0, result[0]
117 assert_equal "", result[1]
118 assert_equal way.id, result[2]
119 assert_equal 2, result[3].length
120 assert_equal node.id, result[3][0][2]
121 assert_equal node.id, result[3][1][2]
122 assert_equal way.version, result[5]
123 assert_equal user.id, result[6]
126 def test_getway_with_multiple_nodes
127 # check a way with multiple nodes
128 way = create(:way_with_nodes, :nodes_count => 3)
132 user = way.changeset.user
134 amf_content "getway", "/1", [way.id]
136 assert_response :success
138 result = amf_result("/1")
139 assert_equal 0, result[0]
140 assert_equal "", result[1]
141 assert_equal way.id, result[2]
142 assert_equal 3, result[3].length
143 assert_equal a, result[3][0][2]
144 assert_equal b, result[3][1][2]
145 assert_equal c, result[3][2][2]
146 assert_equal way.version, result[5]
147 assert_equal user.id, result[6]
150 def test_getway_nonexistent
151 # check chat a non-existent way is not returned
152 amf_content "getway", "/1", [0]
154 assert_response :success
156 way = amf_result("/1")
157 assert_equal -4, way[0]
158 assert_equal "way", way[1]
159 assert_equal 0, way[2]
160 assert(way[3].nil?) && way[4].nil? && way[5].nil? && way[6].nil?
164 node = create(:node, :lat => 3.0, :lon => 3.0)
166 deleted_way = create(:way, :deleted)
167 create(:way_node, :way => way, :node => node)
168 create(:way_node, :way => deleted_way, :node => node)
169 create(:way_tag, :way => way)
171 minlon = node.lon - 0.1
172 minlat = node.lat - 0.1
173 maxlon = node.lon + 0.1
174 maxlat = node.lat + 0.1
175 amf_content "whichways", "/1", [minlon, minlat, maxlon, maxlat]
177 assert_response :success
180 # check contents of message
181 map = amf_result "/1"
182 assert_equal 0, map[0], "map error code should be 0"
183 assert_equal "", map[1], "map error text should be empty"
185 # check the formatting of the message
186 assert_equal 5, map.length, "map should have length 5"
187 assert_equal Array, map[2].class, 'map "ways" element should be an array'
188 assert_equal Array, map[3].class, 'map "nodes" element should be an array'
189 assert_equal Array, map[4].class, 'map "relations" element should be an array'
191 assert_equal 2, w.length, "way should be (id, version) pair"
192 assert w[0] == w[0].floor, "way ID should be an integer"
193 assert w[1] == w[1].floor, "way version should be an integer"
197 assert_equal 5, w.length, "node should be (id, lat, lon, [tags], version) tuple"
198 assert n[0] == n[0].floor, "node ID should be an integer"
199 assert n[1] >= minlat - 0.01, "node lat should be greater than min"
200 assert n[1] <= maxlat - 0.01, "node lat should be less than max"
201 assert n[2] >= minlon - 0.01, "node lon should be greater than min"
202 assert n[2] <= maxlon - 0.01, "node lon should be less than max"
203 assert_equal Array, a[3].class, "node tags should be array"
204 assert n[4] == n[4].floor, "node version should be an integer"
208 assert_equal 2, r.length, "relation should be (id, version) pair"
209 assert r[0] == r[0].floor, "relation ID should be an integer"
210 assert r[1] == r[1].floor, "relation version should be an integer"
213 # TODO: looks like amf_controller changed since this test was written
214 # so someone who knows what they're doing should check this!
215 ways = map[2].collect { |x| x[0] }
216 assert ways.include?(way.id),
217 "map should include used way"
218 assert_not ways.include?(deleted_way.id),
219 "map should not include deleted way"
223 # checks that too-large a bounding box will not be served.
224 def test_whichways_toobig
225 bbox = [-0.1, -0.1, 1.1, 1.1]
226 check_bboxes_are_bad [bbox] do |map, _bbox|
227 assert_boundary_error map, " The server said: The maximum bbox size is 0.25, and your request was too large. Either request a smaller area, or use planet.osm"
232 # checks that an invalid bounding box will not be served. in this case
233 # one with max < min latitudes.
235 # NOTE: the controller expands the bbox by 0.01 in each direction!
236 def test_whichways_badlat
237 bboxes = [[0, 0.1, 0.1, 0], [-0.1, 80, 0.1, 70], [0.24, 54.35, 0.25, 54.33]]
238 check_bboxes_are_bad bboxes do |map, bbox|
239 assert_boundary_error map, " The server said: The minimum latitude must be less than the maximum latitude, but it wasn't", bbox.inspect
244 # same as test_whichways_badlat, but for longitudes
246 # NOTE: the controller expands the bbox by 0.01 in each direction!
247 def test_whichways_badlon
248 bboxes = [[80, -0.1, 70, 0.1], [54.35, 0.24, 54.33, 0.25]]
249 check_bboxes_are_bad bboxes do |map, bbox|
250 assert_boundary_error map, " The server said: The minimum longitude must be less than the maximum longitude, but it wasn't", bbox.inspect
254 def test_whichways_deleted
255 node = create(:node, :with_history, :lat => 24.0, :lon => 24.0)
256 way = create(:way, :with_history)
257 way_v1 = way.old_ways.find_by(:version => 1)
258 deleted_way = create(:way, :with_history, :deleted)
259 deleted_way_v1 = deleted_way.old_ways.find_by(:version => 1)
260 create(:way_node, :way => way, :node => node)
261 create(:way_node, :way => deleted_way, :node => node)
262 create(:old_way_node, :old_way => way_v1, :node => node)
263 create(:old_way_node, :old_way => deleted_way_v1, :node => node)
265 minlon = node.lon - 0.1
266 minlat = node.lat - 0.1
267 maxlon = node.lon + 0.1
268 maxlat = node.lat + 0.1
269 amf_content "whichways_deleted", "/1", [minlon, minlat, maxlon, maxlat]
271 assert_response :success
274 # check contents of message
275 map = amf_result "/1"
276 assert_equal 0, map[0], "first map element should be 0"
277 assert_equal "", map[1], "second map element should be an empty string"
278 assert_equal Array, map[2].class, "third map element should be an array"
279 # TODO: looks like amf_controller changed since this test was written
280 # so someone who knows what they're doing should check this!
281 assert_not map[2].include?(way.id),
282 "map should not include visible way"
283 assert map[2].include?(deleted_way.id),
284 "map should include deleted way"
287 def test_whichways_deleted_toobig
288 bbox = [-0.1, -0.1, 1.1, 1.1]
289 amf_content "whichways_deleted", "/1", bbox
291 assert_response :success
294 map = amf_result "/1"
295 assert_deleted_boundary_error map, " The server said: The maximum bbox size is 0.25, and your request was too large. Either request a smaller area, or use planet.osm"
299 id = create(:relation).id
300 amf_content "getrelation", "/1", [id]
302 assert_response :success
304 rel = amf_result("/1")
305 assert_equal rel[0], 0
306 assert_equal rel[2], id
309 def test_getrelation_invisible
310 id = create(:relation, :deleted).id
311 amf_content "getrelation", "/1", [id]
313 assert_response :success
315 rel = amf_result("/1")
316 assert_equal rel[0], -4
317 assert_equal rel[1], "relation"
318 assert_equal rel[2], id
319 assert(rel[3].nil?) && rel[4].nil?
322 def test_getrelation_nonexistent
324 amf_content "getrelation", "/1", [id]
326 assert_response :success
328 rel = amf_result("/1")
329 assert_equal rel[0], -4
330 assert_equal rel[1], "relation"
331 assert_equal rel[2], id
332 assert(rel[3].nil?) && rel[4].nil?
336 latest = create(:way, :version => 2)
337 v1 = create(:old_way, :current_way => latest, :version => 1, :timestamp => Time.now.utc - 2.minutes)
338 _v2 = create(:old_way, :current_way => latest, :version => 2, :timestamp => Time.now.utc - 1.minute)
340 # try to get the last visible version (specified by <0) (should be current version)
341 # NOTE: looks from the API changes that this now expects a timestamp
342 # instead of a version number...
343 # try to get version 1
345 v1.way_id => (v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S") }.each do |id, t|
346 amf_content "getway_old", "/1", [id, t]
348 assert_response :success
350 returned_way = amf_result("/1")
351 assert_equal 0, returned_way[0]
352 assert_equal id, returned_way[2]
353 # API returns the *latest* version, even for old ways...
354 assert_equal latest.version, returned_way[5]
359 # test that the server doesn't fall over when rubbish is passed
360 # into the method args.
361 def test_getway_old_invalid
362 way_id = create(:way, :with_history, :version => 2).id
364 way_id => "not a date",
365 way_id => "2009-03-25 00:00:00", # <- wrong format
366 way_id => "0 Jan 2009 00:00:00", # <- invalid date
367 -1 => "1 Jan 2009 00:00:00" }.each do |id, t| # <- invalid
368 amf_content "getway_old", "/1", [id, t]
370 assert_response :success
372 returned_way = amf_result("/1")
373 assert_equal -1, returned_way[0]
374 assert returned_way[3].nil?
375 assert returned_way[4].nil?
376 assert returned_way[5].nil?
380 def test_getway_old_nonexistent
381 # try to get the last version-10 (shoudn't exist)
382 way = create(:way, :with_history, :version => 2)
383 v1 = way.old_ways.find_by(:version => 1)
384 # try to get last visible version of non-existent way
385 # try to get specific version of non-existent way
387 [0, "1 Jan 1970, 00:00:00"],
388 [v1.way_id, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
389 amf_content "getway_old", "/1", [id, t]
391 assert_response :success
393 returned_way = amf_result("/1")
394 assert_equal -1, returned_way[0]
395 assert returned_way[3].nil?
396 assert returned_way[4].nil?
397 assert returned_way[5].nil?
401 def test_getway_old_invisible
402 way = create(:way, :deleted, :with_history, :version => 1)
403 v1 = way.old_ways.find_by(:version => 1)
404 # try to get deleted version
405 [[v1.way_id, (v1.timestamp + 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
406 amf_content "getway_old", "/1", [id, t]
408 assert_response :success
410 returned_way = amf_result("/1")
411 assert_equal -1, returned_way[0]
412 assert returned_way[3].nil?
413 assert returned_way[4].nil?
414 assert returned_way[5].nil?
418 def test_getway_history
419 latest = create(:way, :version => 2)
420 oldest = create(:old_way, :current_way => latest, :version => 1, :timestamp => latest.timestamp - 2.minutes)
421 create(:old_way, :current_way => latest, :version => 2, :timestamp => latest.timestamp)
423 amf_content "getway_history", "/1", [latest.id]
425 assert_response :success
427 history = amf_result("/1")
429 # ['way',wayid,history]
430 assert_equal "way", history[0]
431 assert_equal latest.id, history[1]
432 # We use dates rather than version numbers here, because you might
433 # have moved a node within a way (i.e. way version not incremented).
434 # The timestamp is +1 because we say "give me the revision of 15:33:02",
435 # but that might actually include changes at 15:33:02.457.
436 assert_equal (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
437 assert_equal (oldest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
440 def test_getway_history_nonexistent
441 amf_content "getway_history", "/1", [0]
443 assert_response :success
445 history = amf_result("/1")
447 # ['way',wayid,history]
448 assert_equal history[0], "way"
449 assert_equal history[1], 0
450 assert history[2].empty?
453 def test_getnode_history
454 node = create(:node, :version => 2)
455 node_v1 = create(:old_node, :current_node => node, :version => 1, :timestamp => 3.days.ago)
456 _node_v2 = create(:old_node, :current_node => node, :version => 2, :timestamp => 2.days.ago)
457 node_v3 = create(:old_node, :current_node => node, :version => 3, :timestamp => 1.day.ago)
459 amf_content "getnode_history", "/1", [node.id]
461 assert_response :success
463 history = amf_result("/1")
465 # ['node',nodeid,history]
466 # note that (as per getway_history) we actually round up
468 assert_equal history[0], "node",
469 'first element should be "node"'
470 assert_equal history[1], node.id,
471 "second element should be the input node ID"
472 assert_equal history[2].first[0],
473 (node_v3.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
474 "first element in third element (array) should be the latest version"
475 assert_equal history[2].last[0],
476 (node_v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
477 "last element in third element (array) should be the initial version"
480 def test_getnode_history_nonexistent
481 amf_content "getnode_history", "/1", [0]
483 assert_response :success
485 history = amf_result("/1")
487 # ['node',nodeid,history]
488 assert_equal history[0], "node"
489 assert_equal history[1], 0
490 assert history[2].empty?
493 def test_findgpx_bad_user
494 amf_content "findgpx", "/1", [1, "test@example.com:wrong"]
496 assert_response :success
498 result = amf_result("/1")
500 assert_equal 2, result.length
501 assert_equal -1, result[0]
502 assert_match(/must be logged in/, result[1])
504 blocked_user = create(:user)
505 create(:user_block, :user => blocked_user)
506 amf_content "findgpx", "/1", [1, "#{blocked_user.email}:test"]
508 assert_response :success
510 result = amf_result("/1")
512 assert_equal 2, result.length
513 assert_equal -1, result[0]
514 assert_match(/access to the API has been blocked/, result[1])
517 def test_findgpx_by_id
519 trace = create(:trace, :visibility => "private", :user => user)
521 amf_content "findgpx", "/1", [trace.id, "#{user.email}:test"]
523 assert_response :success
525 result = amf_result("/1")
527 assert_equal 3, result.length
528 assert_equal 0, result[0]
529 assert_equal "", result[1]
531 assert_equal 1, traces.length
532 assert_equal 3, traces[0].length
533 assert_equal trace.id, traces[0][0]
534 assert_equal trace.name, traces[0][1]
535 assert_equal trace.description, traces[0][2]
538 def test_findgpx_by_name
541 amf_content "findgpx", "/1", ["Trace", "#{user.email}:test"]
543 assert_response :success
545 result = amf_result("/1")
547 # find by name fails as it uses mysql text search syntax...
548 assert_equal 2, result.length
549 assert_equal -2, result[0]
552 def test_findrelations_by_id
553 relation = create(:relation, :version => 4)
555 amf_content "findrelations", "/1", [relation.id]
557 assert_response :success
559 result = amf_result("/1")
561 assert_equal 1, result.length
562 assert_equal 4, result[0].length
563 assert_equal relation.id, result[0][0]
564 assert_equal relation.tags, result[0][1]
565 assert_equal relation.members, result[0][2]
566 assert_equal relation.version, result[0][3]
568 amf_content "findrelations", "/1", [999999]
570 assert_response :success
572 result = amf_result("/1")
574 assert_equal 0, result.length
577 def test_findrelations_by_tags
578 visible_relation = create(:relation)
579 create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
580 used_relation = create(:relation)
581 super_relation = create(:relation)
582 create(:relation_member, :relation => super_relation, :member => used_relation)
583 create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
584 create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
586 amf_content "findrelations", "/1", ["yes"]
588 assert_response :success
590 result = amf_result("/1").sort
592 assert_equal 2, result.length
593 assert_equal 4, result[0].length
594 assert_equal visible_relation.id, result[0][0]
595 assert_equal visible_relation.tags, result[0][1]
596 assert_equal visible_relation.members, result[0][2]
597 assert_equal visible_relation.version, result[0][3]
598 assert_equal 4, result[1].length
599 assert_equal used_relation.id, result[1][0]
600 assert_equal used_relation.tags, result[1][1]
601 assert_equal used_relation.members, result[1][2]
602 assert_equal used_relation.version, result[1][3]
604 amf_content "findrelations", "/1", ["no"]
606 assert_response :success
608 result = amf_result("/1").sort
610 assert_equal 0, result.length
613 def test_getpoi_without_timestamp
614 node = create(:node, :with_history, :version => 4)
615 create(:node_tag, :node => node)
617 amf_content "getpoi", "/1", [node.id, ""]
619 assert_response :success
621 result = amf_result("/1")
623 assert_equal 7, result.length
624 assert_equal 0, result[0]
625 assert_equal "", result[1]
626 assert_equal node.id, result[2]
627 assert_equal node.lon, result[3]
628 assert_equal node.lat, result[4]
629 assert_equal node.tags, result[5]
630 assert_equal node.version, result[6]
632 amf_content "getpoi", "/1", [999999, ""]
634 assert_response :success
636 result = amf_result("/1")
638 assert_equal 3, result.length
639 assert_equal -4, result[0]
640 assert_equal "node", result[1]
641 assert_equal 999999, result[2]
644 def test_getpoi_with_timestamp
645 current_node = create(:node, :with_history, :version => 4)
646 node = current_node.old_nodes.find_by(:version => 2)
648 # Timestamps are stored with microseconds, but xmlschema truncates them to
649 # previous whole second, causing <= comparison to fail
650 timestamp = (node.timestamp + 1.second).xmlschema
652 amf_content "getpoi", "/1", [node.node_id, timestamp]
654 assert_response :success
656 result = amf_result("/1")
658 assert_equal 7, result.length
659 assert_equal 0, result[0]
660 assert_equal "", result[1]
661 assert_equal node.node_id, result[2]
662 assert_equal node.lon, result[3]
663 assert_equal node.lat, result[4]
664 assert_equal node.tags, result[5]
665 assert_equal current_node.version, result[6]
667 amf_content "getpoi", "/1", [node.node_id, "2000-01-01T00:00:00Z"]
669 assert_response :success
671 result = amf_result("/1")
673 assert_equal 3, result.length
674 assert_equal -4, result[0]
675 assert_equal "node", result[1]
676 assert_equal node.node_id, result[2]
678 amf_content "getpoi", "/1", [999999, Time.now.xmlschema]
680 assert_response :success
682 result = amf_result("/1")
684 assert_equal 3, result.length
685 assert_equal -4, result[0]
686 assert_equal "node", result[1]
687 assert_equal 999999, result[2]
690 # ************************************************************
693 # check that we can update a poi
694 def test_putpoi_update_valid
696 cs_id = nd.changeset.id
697 user = nd.changeset.user
698 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, nd.visible]
700 assert_response :success
702 result = amf_result("/1")
704 assert_equal 5, result.size
705 assert_equal 0, result[0]
706 assert_equal "", result[1]
707 assert_equal nd.id, result[2]
708 assert_equal nd.id, result[3]
709 assert_equal nd.version + 1, result[4]
711 # Now try to update again, with a different lat/lon, using the updated version number
714 amf_content "putpoi", "/2", ["#{user.email}:test", cs_id, nd.version + 1, nd.id, lon, lat, nd.tags, nd.visible]
716 assert_response :success
718 result = amf_result("/2")
720 assert_equal 5, result.size
721 assert_equal 0, result[0]
722 assert_equal "", result[1]
723 assert_equal nd.id, result[2]
724 assert_equal nd.id, result[3]
725 assert_equal nd.version + 2, result[4]
728 # Check that we can create a no valid poi
729 # Using similar method for the node controller test
730 def test_putpoi_create_valid
731 # This node has no tags
733 # create a node with random lat/lon
734 lat = rand(-50..49) + rand
735 lon = rand(-50..49) + rand
737 changeset = create(:changeset)
738 user = changeset.user
740 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, {}, nil]
742 assert_response :success
744 result = amf_result("/1")
746 # check the array returned by the amf
747 assert_equal 5, result.size
748 assert_equal 0, result[0], "expected to get the status ok from the amf"
749 assert_equal 0, result[2], "The old id should be 0"
750 assert result[3] > 0, "The new id should be greater than 0"
751 assert_equal 1, result[4], "The new version should be 1"
753 # Finally check that the node that was saved has saved the data correctly
754 # in both the current and history tables
755 # First check the current table
756 current_node = Node.find(result[3].to_i)
757 assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly"
758 assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly"
759 assert_equal 0, current_node.tags.size, "There seems to be a tag that has been added to the node"
760 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
761 # Now check the history table
762 historic_nodes = OldNode.where(:node_id => result[3])
763 assert_equal 1, historic_nodes.size, "There should only be one historic node created"
764 first_historic_node = historic_nodes.first
765 assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
766 assert_in_delta lon, first_historic_node.lon, 0.00001, "The longitude was not retreuved correctly"
767 assert_equal 0, first_historic_node.tags.size, "There seems to be a tag that have been attached to this node"
768 assert_equal result[4], first_historic_node.version, "The version returned, is different to the one returned by the amf"
771 # This node has some tags
773 # create a node with random lat/lon
774 lat = rand(-50..49) + rand
775 lon = rand(-50..49) + rand
777 amf_content "putpoi", "/2", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, { "key" => "value", "ping" => "pong" }, nil]
779 assert_response :success
781 result = amf_result("/2")
783 # check the array returned by the amf
784 assert_equal 5, result.size
785 assert_equal 0, result[0], "Expected to get the status ok in the amf"
786 assert_equal 0, result[2], "The old id should be 0"
787 assert result[3] > 0, "The new id should be greater than 0"
788 assert_equal 1, result[4], "The new version should be 1"
790 # Finally check that the node that was saved has saved the data correctly
791 # in both the current and history tables
792 # First check the current table
793 current_node = Node.find(result[3].to_i)
794 assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly"
795 assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly"
796 assert_equal 2, current_node.tags.size, "There seems to be a tag that has been added to the node"
797 assert_equal({ "key" => "value", "ping" => "pong" }, current_node.tags, "tags are different")
798 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
799 # Now check the history table
800 historic_nodes = OldNode.where(:node_id => result[3])
801 assert_equal 1, historic_nodes.size, "There should only be one historic node created"
802 first_historic_node = historic_nodes.first
803 assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
804 assert_in_delta lon, first_historic_node.lon, 0.00001, "The longitude was not retreuved correctly"
805 assert_equal 2, first_historic_node.tags.size, "There seems to be a tag that have been attached to this node"
806 assert_equal({ "key" => "value", "ping" => "pong" }, first_historic_node.tags, "tags are different")
807 assert_equal result[4], first_historic_node.version, "The version returned, is different to the one returned by the amf"
810 # try creating a POI with rubbish in the tags
811 def test_putpoi_create_with_control_chars
812 # This node has no tags
814 # create a node with random lat/lon
815 lat = rand(-50..49) + rand
816 lon = rand(-50..49) + rand
818 changeset = create(:changeset)
819 user = changeset.user
821 mostly_invalid = (0..31).to_a.map(&:chr).join
822 tags = { "something" => "foo#{mostly_invalid}bar" }
824 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, tags, nil]
826 assert_response :success
828 result = amf_result("/1")
830 # check the array returned by the amf
831 assert_equal 5, result.size
832 assert_equal 0, result[0], "Expected to get the status ok in the amf"
833 assert_equal 0, result[2], "The old id should be 0"
834 assert result[3] > 0, "The new id should be greater than 0"
835 assert_equal 1, result[4], "The new version should be 1"
837 # Finally check that the node that was saved has saved the data correctly
838 # in both the current and history tables
839 # First check the current table
840 current_node = Node.find(result[3].to_i)
841 assert_equal 1, current_node.tags.size, "There seems to be a tag that has been added to the node"
842 assert_equal({ "something" => "foo\t\n\rbar" }, current_node.tags, "tags were not fixed correctly")
843 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
846 # try creating a POI with rubbish in the tags
847 def test_putpoi_create_with_invalid_utf8
848 # This node has no tags
850 # create a node with random lat/lon
851 lat = rand(-50..49) + rand
852 lon = rand(-50..49) + rand
854 changeset = create(:changeset)
855 user = changeset.user
858 tags = { "something" => "foo#{invalid}bar" }
860 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, tags, nil]
862 assert_response :success
864 result = amf_result("/1")
866 assert_equal 2, result.size
867 assert_equal -1, result[0], "Expected to get the status FAIL in the amf"
868 assert_equal "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1.", result[1]
871 # try deleting a node
872 def test_putpoi_delete_valid
874 cs_id = nd.changeset.id
875 user = nd.changeset.user
877 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
879 assert_response :success
881 result = amf_result("/1")
883 assert_equal 5, result.size
884 assert_equal 0, result[0]
885 assert_equal "", result[1]
886 assert_equal nd.id, result[2]
887 assert_equal nd.id, result[3]
888 assert_equal nd.version + 1, result[4]
890 current_node = Node.find(result[3].to_i)
891 assert_equal false, current_node.visible
894 # try deleting a node that is already deleted
895 def test_putpoi_delete_already_deleted
896 nd = create(:node, :deleted)
897 cs_id = nd.changeset.id
898 user = nd.changeset.user
900 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
902 assert_response :success
904 result = amf_result("/1")
906 assert_equal 3, result.size
907 assert_equal -4, result[0]
908 assert_equal "node", result[1]
909 assert_equal nd.id, result[2]
912 # try deleting a node that has never existed
913 def test_putpoi_delete_not_found
914 changeset = create(:changeset)
916 user = changeset.user
918 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, 1, 999999, 0, 0, {}, false]
920 assert_response :success
922 result = amf_result("/1")
924 assert_equal 3, result.size
925 assert_equal -4, result[0]
926 assert_equal "node", result[1]
927 assert_equal 999999, result[2]
930 # try setting an invalid location on a node
931 def test_putpoi_invalid_latlon
933 cs_id = nd.changeset.id
934 user = nd.changeset.user
936 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, 200, 100, nd.tags, true]
938 assert_response :success
940 result = amf_result("/1")
942 assert_equal 2, result.size
943 assert_equal -2, result[0]
944 assert_match(/Node is not in the world/, result[1])
947 # check that we can create a way
948 def test_putway_create_valid
949 changeset = create(:changeset)
951 user = changeset.user
959 amf_content "putway", "/1", ["#{user.email}:test", cs_id, 0, -1, [a, b, c], { "test" => "new" }, [], {}]
961 assert_response :success
963 result = amf_result("/1")
964 new_way_id = result[3].to_i
966 assert_equal 8, result.size
967 assert_equal 0, result[0]
968 assert_equal "", result[1]
969 assert_equal -1, result[2]
970 assert_not_equal -1, result[3]
971 assert_equal({}, result[4])
972 assert_equal 1, result[5]
973 assert_equal({}, result[6])
974 assert_equal({}, result[7])
976 new_way = Way.find(new_way_id)
977 assert_equal 1, new_way.version
978 assert_equal [a, b, c], new_way.nds
979 assert_equal({ "test" => "new" }, new_way.tags)
981 amf_content "putway", "/1", ["#{user.email}:test", cs_id, 0, -1, [b, d, e, a], { "test" => "newer" }, [], {}]
983 assert_response :success
985 result = amf_result("/1")
986 new_way_id = result[3].to_i
988 assert_equal 8, result.size
989 assert_equal 0, result[0]
990 assert_equal "", result[1]
991 assert_equal -1, result[2]
992 assert_not_equal -1, result[3]
993 assert_equal({}, result[4])
994 assert_equal 1, result[5]
995 assert_equal({}, result[6])
996 assert_equal({}, result[7])
998 new_way = Way.find(new_way_id)
999 assert_equal 1, new_way.version
1000 assert_equal [b, d, e, a], new_way.nds
1001 assert_equal({ "test" => "newer" }, new_way.tags)
1003 amf_content "putway", "/1", ["#{user.email}:test", cs_id, 0, -1, [b, -1, d, e], { "test" => "newest" }, [[4.56, 12.34, -1, 0, { "test" => "new" }], [12.34, 4.56, d, 1, { "test" => "ok" }]], { a => 1 }]
1005 assert_response :success
1007 result = amf_result("/1")
1008 new_way_id = result[3].to_i
1009 new_node_id = result[4]["-1"].to_i
1011 assert_equal 8, result.size
1012 assert_equal 0, result[0]
1013 assert_equal "", result[1]
1014 assert_equal -1, result[2]
1015 assert_not_equal -1, result[3]
1016 assert_equal({ "-1" => new_node_id }, result[4])
1017 assert_equal 1, result[5]
1018 assert_equal({ new_node_id.to_s => 1, d.to_s => 2 }, result[6])
1019 assert_equal({ a.to_s => 1 }, result[7])
1021 new_way = Way.find(new_way_id)
1022 assert_equal 1, new_way.version
1023 assert_equal [b, new_node_id, d, e], new_way.nds
1024 assert_equal({ "test" => "newest" }, new_way.tags)
1026 new_node = Node.find(new_node_id)
1027 assert_equal 1, new_node.version
1028 assert_equal true, new_node.visible
1029 assert_equal 4.56, new_node.lon
1030 assert_equal 12.34, new_node.lat
1031 assert_equal({ "test" => "new" }, new_node.tags)
1033 changed_node = Node.find(d)
1034 assert_equal 2, changed_node.version
1035 assert_equal true, changed_node.visible
1036 assert_equal 12.34, changed_node.lon
1037 assert_equal 4.56, changed_node.lat
1038 assert_equal({ "test" => "ok" }, changed_node.tags)
1040 # node is not deleted because our other ways are using it
1041 deleted_node = Node.find(a)
1042 assert_equal 1, deleted_node.version
1043 assert_equal true, deleted_node.visible
1046 # check that we can update a way
1047 def test_putway_update_valid
1048 way = create(:way_with_nodes, :nodes_count => 3)
1049 cs_id = way.changeset.id
1050 user = way.changeset.user
1052 assert_not_equal({ "test" => "ok" }, way.tags)
1053 amf_content "putway", "/1", ["#{user.email}:test", cs_id, way.version, way.id, way.nds, { "test" => "ok" }, [], {}]
1055 assert_response :success
1057 result = amf_result("/1")
1059 assert_equal 8, result.size
1060 assert_equal 0, result[0]
1061 assert_equal "", result[1]
1062 assert_equal way.id, result[2]
1063 assert_equal way.id, result[3]
1064 assert_equal({}, result[4])
1065 assert_equal way.version + 1, result[5]
1066 assert_equal({}, result[6])
1067 assert_equal({}, result[7])
1069 new_way = Way.find(way.id)
1070 assert_equal way.version + 1, new_way.version
1071 assert_equal way.nds, new_way.nds
1072 assert_equal({ "test" => "ok" }, new_way.tags)
1074 # Test changing the nodes in the way
1075 a = create(:node).id
1076 b = create(:node).id
1077 c = create(:node).id
1078 d = create(:node).id
1080 assert_not_equal [a, b, c, d], way.nds
1081 amf_content "putway", "/1", ["#{user.email}:test", cs_id, way.version + 1, way.id, [a, b, c, d], way.tags, [], {}]
1083 assert_response :success
1085 result = amf_result("/1")
1087 assert_equal 8, result.size
1088 assert_equal 0, result[0]
1089 assert_equal "", result[1]
1090 assert_equal way.id, result[2]
1091 assert_equal way.id, result[3]
1092 assert_equal({}, result[4])
1093 assert_equal way.version + 2, result[5]
1094 assert_equal({}, result[6])
1095 assert_equal({}, result[7])
1097 new_way = Way.find(way.id)
1098 assert_equal way.version + 2, new_way.version
1099 assert_equal [a, b, c, d], new_way.nds
1100 assert_equal way.tags, new_way.tags
1102 amf_content "putway", "/1", ["#{user.email}:test", cs_id, way.version + 2, way.id, [a, -1, b, c], way.tags, [[4.56, 12.34, -1, 0, { "test" => "new" }], [12.34, 4.56, b, 1, { "test" => "ok" }]], { d => 1 }]
1104 assert_response :success
1106 result = amf_result("/1")
1107 new_node_id = result[4]["-1"].to_i
1109 assert_equal 8, result.size
1110 assert_equal 0, result[0]
1111 assert_equal "", result[1]
1112 assert_equal way.id, result[2]
1113 assert_equal way.id, result[3]
1114 assert_equal({ "-1" => new_node_id }, result[4])
1115 assert_equal way.version + 3, result[5]
1116 assert_equal({ new_node_id.to_s => 1, b.to_s => 2 }, result[6])
1117 assert_equal({ d.to_s => 1 }, result[7])
1119 new_way = Way.find(way.id)
1120 assert_equal way.version + 3, new_way.version
1121 assert_equal [a, new_node_id, b, c], new_way.nds
1122 assert_equal way.tags, new_way.tags
1124 new_node = Node.find(new_node_id)
1125 assert_equal 1, new_node.version
1126 assert_equal true, new_node.visible
1127 assert_equal 4.56, new_node.lon
1128 assert_equal 12.34, new_node.lat
1129 assert_equal({ "test" => "new" }, new_node.tags)
1131 changed_node = Node.find(b)
1132 assert_equal 2, changed_node.version
1133 assert_equal true, changed_node.visible
1134 assert_equal 12.34, changed_node.lon
1135 assert_equal 4.56, changed_node.lat
1136 assert_equal({ "test" => "ok" }, changed_node.tags)
1138 deleted_node = Node.find(d)
1139 assert_equal 2, deleted_node.version
1140 assert_equal false, deleted_node.visible
1143 # check that we can delete a way
1144 def test_deleteway_valid
1145 way = create(:way_with_nodes, :nodes_count => 3)
1146 nodes = way.nodes.each_with_object({}) { |n, ns| ns[n.id] = n.version }
1147 cs_id = way.changeset.id
1148 user = way.changeset.user
1150 # Of the three nodes, two should be kept since they are used in
1151 # a different way, and the third deleted since it's unused
1154 create(:way_node, :node => a)
1156 create(:way_node, :node => b)
1159 amf_content "deleteway", "/1", ["#{user.email}:test", cs_id, way.id, way.version, nodes]
1161 assert_response :success
1163 result = amf_result("/1")
1165 assert_equal 5, result.size
1166 assert_equal 0, result[0]
1167 assert_equal "", result[1]
1168 assert_equal way.id, result[2]
1169 assert_equal way.version + 1, result[3]
1170 assert_equal({ c.id.to_s => 2 }, result[4])
1172 new_way = Way.find(way.id)
1173 assert_equal way.version + 1, new_way.version
1174 assert_equal false, new_way.visible
1176 way.nds.each do |node_id|
1177 assert_equal result[4][node_id.to_s].nil?, Node.find(node_id).visible
1181 # check that we can't delete a way that is in use
1182 def test_deleteway_inuse
1183 way = create(:way_with_nodes, :nodes_count => 4)
1184 create(:relation_member, :member => way)
1185 nodes = way.nodes.each_with_object({}) { |n, ns| ns[n.id] = n.version }
1186 cs_id = way.changeset.id
1187 user = way.changeset.user
1189 amf_content "deleteway", "/1", ["#{user.email}:test", cs_id, way.id, way.version, nodes]
1191 assert_response :success
1193 result = amf_result("/1")
1195 assert_equal 2, result.size
1196 assert_equal -1, result[0]
1197 assert_match(/Way #{way.id} is still used/, result[1])
1199 new_way = Way.find(way.id)
1200 assert_equal way.version, new_way.version
1201 assert_equal true, new_way.visible
1203 way.nds.each do |node_id|
1204 assert_equal true, Node.find(node_id).visible
1208 # check that we can create a relation
1209 def test_putrelation_create_valid
1210 changeset = create(:changeset)
1211 user = changeset.user
1212 cs_id = changeset.id
1214 node = create(:node)
1215 way = create(:way_with_nodes, :nodes_count => 2)
1216 relation = create(:relation)
1218 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, 0, -1, { "test" => "new" }, [["Node", node.id, "node"], ["Way", way.id, "way"], ["Relation", relation.id, "relation"]], true]
1220 assert_response :success
1222 result = amf_result("/1")
1223 new_relation_id = result[3].to_i
1225 assert_equal 5, result.size
1226 assert_equal 0, result[0]
1227 assert_equal "", result[1]
1228 assert_equal -1, result[2]
1229 assert_not_equal -1, result[3]
1230 assert_equal 1, result[4]
1232 new_relation = Relation.find(new_relation_id)
1233 assert_equal 1, new_relation.version
1234 assert_equal [["Node", node.id, "node"], ["Way", way.id, "way"], ["Relation", relation.id, "relation"]], new_relation.members
1235 assert_equal({ "test" => "new" }, new_relation.tags)
1236 assert_equal true, new_relation.visible
1239 # check that we can update a relation
1240 def test_putrelation_update_valid
1241 relation = create(:relation)
1242 create(:relation_member, :relation => relation)
1243 user = relation.changeset.user
1244 cs_id = relation.changeset.id
1246 assert_not_equal({ "test" => "ok" }, relation.tags)
1247 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, { "test" => "ok" }, relation.members, true]
1249 assert_response :success
1251 result = amf_result("/1")
1253 assert_equal 5, result.size
1254 assert_equal 0, result[0]
1255 assert_equal "", result[1]
1256 assert_equal relation.id, result[2]
1257 assert_equal relation.id, result[3]
1258 assert_equal relation.version + 1, result[4]
1260 new_relation = Relation.find(relation.id)
1261 assert_equal relation.version + 1, new_relation.version
1262 assert_equal relation.members, new_relation.members
1263 assert_equal({ "test" => "ok" }, new_relation.tags)
1264 assert_equal true, new_relation.visible
1267 # check that we can delete a relation
1268 def test_putrelation_delete_valid
1269 relation = create(:relation)
1270 create(:relation_member, :relation => relation)
1271 create(:relation_tag, :relation => relation)
1272 cs_id = relation.changeset.id
1273 user = relation.changeset.user
1275 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, relation.tags, relation.members, false]
1277 assert_response :success
1279 result = amf_result("/1")
1281 assert_equal 5, result.size
1282 assert_equal 0, result[0]
1283 assert_equal "", result[1]
1284 assert_equal relation.id, result[2]
1285 assert_equal relation.id, result[3]
1286 assert_equal relation.version + 1, result[4]
1288 new_relation = Relation.find(relation.id)
1289 assert_equal relation.version + 1, new_relation.version
1290 assert_equal [], new_relation.members
1291 assert_equal({}, new_relation.tags)
1292 assert_equal false, new_relation.visible
1295 # check that we can't delete a relation that is in use
1296 def test_putrelation_delete_inuse
1297 relation = create(:relation)
1298 super_relation = create(:relation)
1299 create(:relation_member, :relation => super_relation, :member => relation)
1300 cs_id = relation.changeset.id
1301 user = relation.changeset.user
1303 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, relation.tags, relation.members, false]
1305 assert_response :success
1307 result = amf_result("/1")
1309 assert_equal 2, result.size
1310 assert_equal -1, result[0]
1311 assert_match(/relation #{relation.id} is used in/, result[1])
1313 new_relation = Relation.find(relation.id)
1314 assert_equal relation.version, new_relation.version
1315 assert_equal relation.members, new_relation.members
1316 assert_equal relation.tags, new_relation.tags
1317 assert_equal true, new_relation.visible
1320 # check that we can open a changeset
1321 def test_startchangeset_valid
1322 user = create(:user)
1324 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
1326 assert_response :success
1328 result = amf_result("/1")
1329 new_cs_id = result[2].to_i
1331 assert_equal 3, result.size
1332 assert_equal 0, result[0]
1333 assert_equal "", result[1]
1335 cs = Changeset.find(new_cs_id)
1336 assert_equal true, cs.is_open?
1337 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1339 old_cs_id = new_cs_id
1341 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "newer" }, old_cs_id, "newer", 1]
1343 assert_response :success
1345 result = amf_result("/1")
1346 new_cs_id = result[2].to_i
1348 assert_not_equal old_cs_id, new_cs_id
1350 assert_equal 3, result.size
1351 assert_equal 0, result[0]
1352 assert_equal "", result[1]
1354 cs = Changeset.find(old_cs_id)
1355 assert_equal false, cs.is_open?
1356 assert_equal({ "comment" => "newer", "source" => "new" }, cs.tags)
1358 cs = Changeset.find(new_cs_id)
1359 assert_equal true, cs.is_open?
1360 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1362 old_cs_id = new_cs_id
1364 amf_content "startchangeset", "/1", ["#{user.email}:test", {}, old_cs_id, "", 0]
1366 assert_response :success
1368 result = amf_result("/1")
1370 assert_equal 3, result.size
1371 assert_equal 0, result[0]
1372 assert_equal "", result[1]
1373 assert_nil result[2]
1375 cs = Changeset.find(old_cs_id)
1376 assert_equal false, cs.is_open?
1377 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1380 # check that we can't close somebody elses changeset
1381 def test_startchangeset_invalid_wrong_user
1382 user = create(:user)
1383 user2 = create(:user)
1385 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
1387 assert_response :success
1389 result = amf_result("/1")
1390 cs_id = result[2].to_i
1392 assert_equal 3, result.size
1393 assert_equal 0, result[0]
1394 assert_equal "", result[1]
1396 cs = Changeset.find(cs_id)
1397 assert_equal true, cs.is_open?
1398 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1400 amf_content "startchangeset", "/1", ["#{user2.email}:test", {}, cs_id, "delete", 0]
1402 assert_response :success
1404 result = amf_result("/1")
1406 assert_equal 2, result.size
1407 assert_equal -2, result[0]
1408 assert_equal "The user doesn't own that changeset", result[1]
1410 cs = Changeset.find(cs_id)
1411 assert_equal true, cs.is_open?
1412 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1415 # check that invalid characters are stripped from changeset tags
1416 def test_startchangeset_invalid_xmlchar_comment
1417 user = create(:user)
1419 invalid = "\035\022"
1420 comment = "foo#{invalid}bar"
1422 amf_content "startchangeset", "/1", ["#{user.email}:test", {}, nil, comment, 1]
1424 assert_response :success
1426 result = amf_result("/1")
1427 new_cs_id = result[2].to_i
1429 assert_equal 3, result.size
1430 assert_equal 0, result[0]
1431 assert_equal "", result[1]
1433 cs = Changeset.find(new_cs_id)
1434 assert_equal true, cs.is_open?
1435 assert_equal({ "comment" => "foobar" }, cs.tags)
1440 # ************************************************************
1441 # AMF Helper functions
1443 # Get the result record for the specified ID
1444 # It's an assertion FAIL if the record does not exist
1446 assert @amf_result.key?("#{ref}/onResult")
1447 @amf_result["#{ref}/onResult"]
1450 # Encode the AMF message to invoke "target" with parameters as
1451 # the passed data. The ref is used to retrieve the results.
1452 def amf_content(target, ref, data)
1453 a, b = 1.divmod(256)
1455 c.write 0.chr + 0.chr # version 0
1456 c.write 0.chr + 0.chr # n headers
1457 c.write a.chr + b.chr # n bodies
1458 c.write AMF.encodestring(target)
1459 c.write AMF.encodestring(ref)
1460 c.write [-1].pack("N")
1461 c.write AMF.encodevalue(data)
1463 @request.env["RAW_POST_DATA"] = c.string
1466 # Parses the @response object as an AMF messsage.
1467 # The result is a hash of message_ref => data.
1468 # The attribute @amf_result is initialised to this hash.
1469 def amf_parse_response
1470 req = StringIO.new(@response.body)
1472 req.read(2) # version
1474 # parse through any headers
1475 headers = AMF.getint(req) # Read number of headers
1476 headers.times do # Read each header
1477 AMF.getstring(req) # |
1478 req.getc # | skip boolean
1479 AMF.getvalue(req) # |
1482 # parse through responses
1484 bodies = AMF.getint(req) # Read number of bodies
1485 bodies.times do # Read each body
1486 message = AMF.getstring(req) # | get message name
1487 AMF.getstring(req) # | get index in response sequence
1488 AMF.getlong(req) # | get total size in bytes
1489 args = AMF.getvalue(req) # | get response (probably an array)
1490 results[message] = args
1492 @amf_result = results
1497 # given an array of bounding boxes (each an array of 4 floats), call the
1498 # AMF "whichways" controller for each and pass the result back to the
1499 # caller's block for assertion testing.
1500 def check_bboxes_are_bad(bboxes)
1501 bboxes.each do |bbox|
1502 amf_content "whichways", "/1", bbox
1504 assert_response :success
1507 # pass the response back to the caller's block to be tested
1508 # against what the caller expected.
1509 map = amf_result "/1"
1514 # this should be what AMF controller returns when the bbox of a
1515 # whichways request is invalid or too large.
1516 def assert_boundary_error(map, msg = nil, error_hint = nil)
1517 expected_map = [-2, "Sorry - I can't get the map for that area.#{msg}"]
1518 assert_equal expected_map, map, "AMF controller should have returned an error. (#{error_hint})"
1521 # this should be what AMF controller returns when the bbox of a
1522 # whichways_deleted request is invalid or too large.
1523 def assert_deleted_boundary_error(map, msg = nil, error_hint = nil)
1524 expected_map = [-2, "Sorry - I can't get the map for that area.#{msg}"]
1525 assert_equal expected_map, map, "AMF controller should have returned an error. (#{error_hint})"