5 class AmfControllerTest < ActionController::TestCase
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/amf/read", :method => :post },
11 { :controller => "amf", :action => "amf_read" }
14 { :path => "/api/0.6/amf/write", :method => :post },
15 { :controller => "amf", :action => "amf_write" }
20 user_en_de = create(:user, :languages => %w(en de))
21 user_de = create(:user, :languages => %w(de))
22 [user_en_de, user_de].each do |user|
23 amf_content "getpresets", "/1", ["#{user.email}:test", ""]
25 assert_response :success
27 presets = amf_result("/1")
29 assert_equal 15, presets.length
30 assert_equal POTLATCH_PRESETS[0], presets[0]
31 assert_equal POTLATCH_PRESETS[1], presets[1]
32 assert_equal POTLATCH_PRESETS[2], presets[2]
33 assert_equal POTLATCH_PRESETS[3], presets[3]
34 assert_equal POTLATCH_PRESETS[4], presets[4]
35 assert_equal POTLATCH_PRESETS[5], presets[5]
36 assert_equal POTLATCH_PRESETS[6], presets[6]
37 assert_equal POTLATCH_PRESETS[7], presets[7]
38 assert_equal POTLATCH_PRESETS[8], presets[8]
39 assert_equal POTLATCH_PRESETS[9], presets[9]
40 assert_equal POTLATCH_PRESETS[10], presets[10]
41 assert_equal POTLATCH_PRESETS[12], presets[12]
42 assert_equal user.languages.first, presets[13]["__potlatch_locale"]
48 way = create(:way_with_nodes, :nodes_count => 1)
49 node = way.nodes.first
50 user = way.changeset.user
52 amf_content "getway", "/1", [way.id]
54 assert_response :success
56 result = amf_result("/1")
57 assert_equal 0, result[0]
58 assert_equal "", result[1]
59 assert_equal way.id, result[2]
60 assert_equal 1, result[3].length
61 assert_equal node.id, result[3][0][2]
62 assert_equal way.version, result[5]
63 assert_equal user.id, result[6]
66 def test_getway_invisible
67 # check an invisible way
68 id = create(:way, :deleted).id
70 amf_content "getway", "/1", [id]
72 assert_response :success
74 result = amf_result("/1")
75 assert_equal -4, result[0]
76 assert_equal "way", result[1]
77 assert_equal id, result[2]
78 assert(result[3].nil? && result[4].nil? && result[5].nil? && result[6].nil?)
81 def test_getway_with_versions
82 # check a way with multiple versions
83 way = create(:way, :with_history, :version => 4)
84 create(:way_node, :way => way)
85 node = way.nodes.first
86 user = way.changeset.user
88 amf_content "getway", "/1", [way.id]
90 assert_response :success
92 result = amf_result("/1")
93 assert_equal 0, result[0]
94 assert_equal "", result[1]
95 assert_equal way.id, result[2]
96 assert_equal 1, result[3].length
97 assert_equal node.id, result[3][0][2]
98 assert_equal way.version, result[5]
99 assert_equal user.id, result[6]
102 def test_getway_with_duplicate_nodes
103 # check a way with duplicate nodes
106 create(:way_node, :way => way, :node => node, :sequence_id => 1)
107 create(:way_node, :way => way, :node => node, :sequence_id => 2)
108 user = way.changeset.user
110 amf_content "getway", "/1", [way.id]
112 assert_response :success
114 result = amf_result("/1")
115 assert_equal 0, result[0]
116 assert_equal "", result[1]
117 assert_equal way.id, result[2]
118 assert_equal 2, result[3].length
119 assert_equal node.id, result[3][0][2]
120 assert_equal node.id, result[3][1][2]
121 assert_equal way.version, result[5]
122 assert_equal user.id, result[6]
125 def test_getway_with_multiple_nodes
126 # check a way with multiple nodes
127 way = create(:way_with_nodes, :nodes_count => 3)
131 user = way.changeset.user
133 amf_content "getway", "/1", [way.id]
135 assert_response :success
137 result = amf_result("/1")
138 assert_equal 0, result[0]
139 assert_equal "", result[1]
140 assert_equal way.id, result[2]
141 assert_equal 3, result[3].length
142 assert_equal a, result[3][0][2]
143 assert_equal b, result[3][1][2]
144 assert_equal c, result[3][2][2]
145 assert_equal way.version, result[5]
146 assert_equal user.id, result[6]
149 def test_getway_nonexistent
150 # check chat a non-existent way is not returned
151 amf_content "getway", "/1", [0]
153 assert_response :success
155 way = amf_result("/1")
156 assert_equal -4, way[0]
157 assert_equal "way", way[1]
158 assert_equal 0, way[2]
159 assert(way[3].nil?) && way[4].nil? && way[5].nil? && way[6].nil?
163 node = create(:node, :lat => 3.0, :lon => 3.0)
165 deleted_way = create(:way, :deleted)
166 create(:way_node, :way => way, :node => node)
167 create(:way_node, :way => deleted_way, :node => node)
168 create(:way_tag, :way => way)
170 minlon = node.lon - 0.1
171 minlat = node.lat - 0.1
172 maxlon = node.lon + 0.1
173 maxlat = node.lat + 0.1
174 amf_content "whichways", "/1", [minlon, minlat, maxlon, maxlat]
176 assert_response :success
179 # check contents of message
180 map = amf_result "/1"
181 assert_equal 0, map[0], "map error code should be 0"
182 assert_equal "", map[1], "map error text should be empty"
184 # check the formatting of the message
185 assert_equal 5, map.length, "map should have length 5"
186 assert_equal Array, map[2].class, 'map "ways" element should be an array'
187 assert_equal Array, map[3].class, 'map "nodes" element should be an array'
188 assert_equal Array, map[4].class, 'map "relations" element should be an array'
190 assert_equal 2, w.length, "way should be (id, version) pair"
191 assert w[0] == w[0].floor, "way ID should be an integer"
192 assert w[1] == w[1].floor, "way version should be an integer"
196 assert_equal 5, w.length, "node should be (id, lat, lon, [tags], version) tuple"
197 assert n[0] == n[0].floor, "node ID should be an integer"
198 assert n[1] >= minlat - 0.01, "node lat should be greater than min"
199 assert n[1] <= maxlat - 0.01, "node lat should be less than max"
200 assert n[2] >= minlon - 0.01, "node lon should be greater than min"
201 assert n[2] <= maxlon - 0.01, "node lon should be less than max"
202 assert_equal Array, a[3].class, "node tags should be array"
203 assert n[4] == n[4].floor, "node version should be an integer"
207 assert_equal 2, r.length, "relation should be (id, version) pair"
208 assert r[0] == r[0].floor, "relation ID should be an integer"
209 assert r[1] == r[1].floor, "relation version should be an integer"
212 # TODO: looks like amf_controller changed since this test was written
213 # so someone who knows what they're doing should check this!
214 ways = map[2].collect { |x| x[0] }
215 assert ways.include?(way.id),
216 "map should include used way"
217 assert !ways.include?(deleted_way.id),
218 "map should not include deleted way"
222 # checks that too-large a bounding box will not be served.
223 def test_whichways_toobig
224 bbox = [-0.1, -0.1, 1.1, 1.1]
225 check_bboxes_are_bad [bbox] do |map, _bbox|
226 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"
231 # checks that an invalid bounding box will not be served. in this case
232 # one with max < min latitudes.
234 # NOTE: the controller expands the bbox by 0.01 in each direction!
235 def test_whichways_badlat
236 bboxes = [[0, 0.1, 0.1, 0], [-0.1, 80, 0.1, 70], [0.24, 54.35, 0.25, 54.33]]
237 check_bboxes_are_bad bboxes do |map, bbox|
238 assert_boundary_error map, " The server said: The minimum latitude must be less than the maximum latitude, but it wasn't", bbox.inspect
243 # same as test_whichways_badlat, but for longitudes
245 # NOTE: the controller expands the bbox by 0.01 in each direction!
246 def test_whichways_badlon
247 bboxes = [[80, -0.1, 70, 0.1], [54.35, 0.24, 54.33, 0.25]]
248 check_bboxes_are_bad bboxes do |map, bbox|
249 assert_boundary_error map, " The server said: The minimum longitude must be less than the maximum longitude, but it wasn't", bbox.inspect
253 def test_whichways_deleted
254 node = create(:node, :with_history, :lat => 24.0, :lon => 24.0)
255 way = create(:way, :with_history)
256 way_v1 = way.old_ways.find_by(:version => 1)
257 deleted_way = create(:way, :with_history, :deleted)
258 deleted_way_v1 = deleted_way.old_ways.find_by(:version => 1)
259 create(:way_node, :way => way, :node => node)
260 create(:way_node, :way => deleted_way, :node => node)
261 create(:old_way_node, :old_way => way_v1, :node => node)
262 create(:old_way_node, :old_way => deleted_way_v1, :node => node)
264 minlon = node.lon - 0.1
265 minlat = node.lat - 0.1
266 maxlon = node.lon + 0.1
267 maxlat = node.lat + 0.1
268 amf_content "whichways_deleted", "/1", [minlon, minlat, maxlon, maxlat]
270 assert_response :success
273 # check contents of message
274 map = amf_result "/1"
275 assert_equal 0, map[0], "first map element should be 0"
276 assert_equal "", map[1], "second map element should be an empty string"
277 assert_equal Array, map[2].class, "third map element should be an array"
278 # TODO: looks like amf_controller changed since this test was written
279 # so someone who knows what they're doing should check this!
280 assert !map[2].include?(way.id),
281 "map should not include visible way"
282 assert map[2].include?(deleted_way.id),
283 "map should include deleted way"
286 def test_whichways_deleted_toobig
287 bbox = [-0.1, -0.1, 1.1, 1.1]
288 amf_content "whichways_deleted", "/1", bbox
290 assert_response :success
293 map = amf_result "/1"
294 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"
298 id = create(:relation).id
299 amf_content "getrelation", "/1", [id]
301 assert_response :success
303 rel = amf_result("/1")
304 assert_equal rel[0], 0
305 assert_equal rel[2], id
308 def test_getrelation_invisible
309 id = create(:relation, :deleted).id
310 amf_content "getrelation", "/1", [id]
312 assert_response :success
314 rel = amf_result("/1")
315 assert_equal rel[0], -4
316 assert_equal rel[1], "relation"
317 assert_equal rel[2], id
318 assert(rel[3].nil?) && rel[4].nil?
321 def test_getrelation_nonexistent
323 amf_content "getrelation", "/1", [id]
325 assert_response :success
327 rel = amf_result("/1")
328 assert_equal rel[0], -4
329 assert_equal rel[1], "relation"
330 assert_equal rel[2], id
331 assert(rel[3].nil?) && rel[4].nil?
335 latest = create(:way, :version => 2)
336 v1 = create(:old_way, :current_way => latest, :version => 1, :timestamp => Time.now.utc - 2.minutes)
337 _v2 = create(:old_way, :current_way => latest, :version => 2, :timestamp => Time.now.utc - 1.minute)
339 # try to get the last visible version (specified by <0) (should be current version)
340 # NOTE: looks from the API changes that this now expects a timestamp
341 # instead of a version number...
342 # try to get version 1
344 v1.way_id => (v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S") }.each do |id, t|
345 amf_content "getway_old", "/1", [id, t]
347 assert_response :success
349 returned_way = amf_result("/1")
350 assert_equal 0, returned_way[0]
351 assert_equal id, returned_way[2]
352 # API returns the *latest* version, even for old ways...
353 assert_equal latest.version, returned_way[5]
358 # test that the server doesn't fall over when rubbish is passed
359 # into the method args.
360 def test_getway_old_invalid
361 way_id = create(:way, :with_history, :version => 2).id
363 way_id => "not a date",
364 way_id => "2009-03-25 00:00:00", # <- wrong format
365 way_id => "0 Jan 2009 00:00:00", # <- invalid date
366 -1 => "1 Jan 2009 00:00:00" }.each do |id, t| # <- invalid
367 amf_content "getway_old", "/1", [id, t]
369 assert_response :success
371 returned_way = amf_result("/1")
372 assert_equal -1, returned_way[0]
373 assert returned_way[3].nil?
374 assert returned_way[4].nil?
375 assert returned_way[5].nil?
379 def test_getway_old_nonexistent
380 # try to get the last version-10 (shoudn't exist)
381 way = create(:way, :with_history, :version => 2)
382 v1 = way.old_ways.find_by(:version => 1)
383 # try to get last visible version of non-existent way
384 # try to get specific version of non-existent way
386 [0, "1 Jan 1970, 00:00:00"],
387 [v1.way_id, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
388 amf_content "getway_old", "/1", [id, t]
390 assert_response :success
392 returned_way = amf_result("/1")
393 assert_equal -1, returned_way[0]
394 assert returned_way[3].nil?
395 assert returned_way[4].nil?
396 assert returned_way[5].nil?
400 def test_getway_old_invisible
401 way = create(:way, :deleted, :with_history, :version => 1)
402 v1 = way.old_ways.find_by(:version => 1)
403 # try to get deleted version
404 [[v1.way_id, (v1.timestamp + 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
405 amf_content "getway_old", "/1", [id, t]
407 assert_response :success
409 returned_way = amf_result("/1")
410 assert_equal -1, returned_way[0]
411 assert returned_way[3].nil?
412 assert returned_way[4].nil?
413 assert returned_way[5].nil?
417 def test_getway_history
418 latest = create(:way, :version => 2)
419 oldest = create(:old_way, :current_way => latest, :version => 1, :timestamp => latest.timestamp - 2.minutes)
420 create(:old_way, :current_way => latest, :version => 2, :timestamp => latest.timestamp)
422 amf_content "getway_history", "/1", [latest.id]
424 assert_response :success
426 history = amf_result("/1")
428 # ['way',wayid,history]
429 assert_equal "way", history[0]
430 assert_equal latest.id, history[1]
431 # We use dates rather than version numbers here, because you might
432 # have moved a node within a way (i.e. way version not incremented).
433 # The timestamp is +1 because we say "give me the revision of 15:33:02",
434 # but that might actually include changes at 15:33:02.457.
435 assert_equal (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
436 assert_equal (oldest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
439 def test_getway_history_nonexistent
440 amf_content "getway_history", "/1", [0]
442 assert_response :success
444 history = amf_result("/1")
446 # ['way',wayid,history]
447 assert_equal history[0], "way"
448 assert_equal history[1], 0
449 assert history[2].empty?
452 def test_getnode_history
453 node = create(:node, :version => 2)
454 node_v1 = create(:old_node, :current_node => node, :version => 1, :timestamp => 3.days.ago)
455 _node_v2 = create(:old_node, :current_node => node, :version => 2, :timestamp => 2.days.ago)
456 node_v3 = create(:old_node, :current_node => node, :version => 3, :timestamp => 1.day.ago)
458 amf_content "getnode_history", "/1", [node.id]
460 assert_response :success
462 history = amf_result("/1")
464 # ['node',nodeid,history]
465 # note that (as per getway_history) we actually round up
467 assert_equal history[0], "node",
468 'first element should be "node"'
469 assert_equal history[1], node.id,
470 "second element should be the input node ID"
471 assert_equal history[2].first[0],
472 (node_v3.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
473 "first element in third element (array) should be the latest version"
474 assert_equal history[2].last[0],
475 (node_v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
476 "last element in third element (array) should be the initial version"
479 def test_getnode_history_nonexistent
480 amf_content "getnode_history", "/1", [0]
482 assert_response :success
484 history = amf_result("/1")
486 # ['node',nodeid,history]
487 assert_equal history[0], "node"
488 assert_equal history[1], 0
489 assert history[2].empty?
492 def test_findgpx_bad_user
493 amf_content "findgpx", "/1", [1, "test@example.com:wrong"]
495 assert_response :success
497 result = amf_result("/1")
499 assert_equal 2, result.length
500 assert_equal -1, result[0]
501 assert_match /must be logged in/, result[1]
503 blocked_user = create(:user)
504 create(:user_block, :user => blocked_user)
505 amf_content "findgpx", "/1", [1, "#{blocked_user.email}:test"]
507 assert_response :success
509 result = amf_result("/1")
511 assert_equal 2, result.length
512 assert_equal -1, result[0]
513 assert_match /access to the API has been blocked/, result[1]
516 def test_findgpx_by_id
518 trace = create(:trace, :visibility => "private", :user => user)
520 amf_content "findgpx", "/1", [trace.id, "#{user.email}:test"]
522 assert_response :success
524 result = amf_result("/1")
526 assert_equal 3, result.length
527 assert_equal 0, result[0]
528 assert_equal "", result[1]
530 assert_equal 1, traces.length
531 assert_equal 3, traces[0].length
532 assert_equal trace.id, traces[0][0]
533 assert_equal trace.name, traces[0][1]
534 assert_equal trace.description, traces[0][2]
537 def test_findgpx_by_name
540 amf_content "findgpx", "/1", ["Trace", "#{user.email}:test"]
542 assert_response :success
544 result = amf_result("/1")
546 # find by name fails as it uses mysql text search syntax...
547 assert_equal 2, result.length
548 assert_equal -2, result[0]
551 def test_findrelations_by_id
552 relation = create(:relation, :version => 4)
554 amf_content "findrelations", "/1", [relation.id]
556 assert_response :success
558 result = amf_result("/1")
560 assert_equal 1, result.length
561 assert_equal 4, result[0].length
562 assert_equal relation.id, result[0][0]
563 assert_equal relation.tags, result[0][1]
564 assert_equal relation.members, result[0][2]
565 assert_equal relation.version, result[0][3]
567 amf_content "findrelations", "/1", [999999]
569 assert_response :success
571 result = amf_result("/1")
573 assert_equal 0, result.length
576 def test_findrelations_by_tags
577 visible_relation = create(:relation)
578 create(:relation_tag, :relation => visible_relation, :k => "test", :v => "yes")
579 used_relation = create(:relation)
580 super_relation = create(:relation)
581 create(:relation_member, :relation => super_relation, :member => used_relation)
582 create(:relation_tag, :relation => used_relation, :k => "test", :v => "yes")
583 create(:relation_tag, :relation => used_relation, :k => "name", :v => "Test Relation")
585 amf_content "findrelations", "/1", ["yes"]
587 assert_response :success
589 result = amf_result("/1").sort
591 assert_equal 2, result.length
592 assert_equal 4, result[0].length
593 assert_equal visible_relation.id, result[0][0]
594 assert_equal visible_relation.tags, result[0][1]
595 assert_equal visible_relation.members, result[0][2]
596 assert_equal visible_relation.version, result[0][3]
597 assert_equal 4, result[1].length
598 assert_equal used_relation.id, result[1][0]
599 assert_equal used_relation.tags, result[1][1]
600 assert_equal used_relation.members, result[1][2]
601 assert_equal used_relation.version, result[1][3]
603 amf_content "findrelations", "/1", ["no"]
605 assert_response :success
607 result = amf_result("/1").sort
609 assert_equal 0, result.length
612 def test_getpoi_without_timestamp
613 node = create(:node, :with_history, :version => 4)
614 create(:node_tag, :node => node)
616 amf_content "getpoi", "/1", [node.id, ""]
618 assert_response :success
620 result = amf_result("/1")
622 assert_equal 7, result.length
623 assert_equal 0, result[0]
624 assert_equal "", result[1]
625 assert_equal node.id, result[2]
626 assert_equal node.lon, result[3]
627 assert_equal node.lat, result[4]
628 assert_equal node.tags, result[5]
629 assert_equal node.version, result[6]
631 amf_content "getpoi", "/1", [999999, ""]
633 assert_response :success
635 result = amf_result("/1")
637 assert_equal 3, result.length
638 assert_equal -4, result[0]
639 assert_equal "node", result[1]
640 assert_equal 999999, result[2]
643 def test_getpoi_with_timestamp
644 current_node = create(:node, :with_history, :version => 4)
645 node = current_node.old_nodes.find_by(:version => 2)
647 # Timestamps are stored with microseconds, but xmlschema truncates them to
648 # previous whole second, causing <= comparison to fail
649 timestamp = (node.timestamp + 1.second).xmlschema
651 amf_content "getpoi", "/1", [node.node_id, timestamp]
653 assert_response :success
655 result = amf_result("/1")
657 assert_equal 7, result.length
658 assert_equal 0, result[0]
659 assert_equal "", result[1]
660 assert_equal node.node_id, result[2]
661 assert_equal node.lon, result[3]
662 assert_equal node.lat, result[4]
663 assert_equal node.tags, result[5]
664 assert_equal current_node.version, result[6]
666 amf_content "getpoi", "/1", [node.node_id, "2000-01-01T00:00:00Z"]
668 assert_response :success
670 result = amf_result("/1")
672 assert_equal 3, result.length
673 assert_equal -4, result[0]
674 assert_equal "node", result[1]
675 assert_equal node.node_id, result[2]
677 amf_content "getpoi", "/1", [999999, Time.now.xmlschema]
679 assert_response :success
681 result = amf_result("/1")
683 assert_equal 3, result.length
684 assert_equal -4, result[0]
685 assert_equal "node", result[1]
686 assert_equal 999999, result[2]
689 # ************************************************************
692 # check that we can update a poi
693 def test_putpoi_update_valid
695 cs_id = nd.changeset.id
696 user = nd.changeset.user
697 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, nd.visible]
699 assert_response :success
701 result = amf_result("/1")
703 assert_equal 5, result.size
704 assert_equal 0, result[0]
705 assert_equal "", result[1]
706 assert_equal nd.id, result[2]
707 assert_equal nd.id, result[3]
708 assert_equal nd.version + 1, result[4]
710 # Now try to update again, with a different lat/lon, using the updated version number
713 amf_content "putpoi", "/2", ["#{user.email}:test", cs_id, nd.version + 1, nd.id, lon, lat, nd.tags, nd.visible]
715 assert_response :success
717 result = amf_result("/2")
719 assert_equal 5, result.size
720 assert_equal 0, result[0]
721 assert_equal "", result[1]
722 assert_equal nd.id, result[2]
723 assert_equal nd.id, result[3]
724 assert_equal nd.version + 2, result[4]
727 # Check that we can create a no valid poi
728 # Using similar method for the node controller test
729 def test_putpoi_create_valid
730 # This node has no tags
732 # create a node with random lat/lon
733 lat = rand(100) - 50 + rand
734 lon = rand(100) - 50 + rand
736 changeset = create(:changeset)
737 user = changeset.user
739 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, {}, nil]
741 assert_response :success
743 result = amf_result("/1")
745 # check the array returned by the amf
746 assert_equal 5, result.size
747 assert_equal 0, result[0], "expected to get the status ok from the amf"
748 assert_equal 0, result[2], "The old id should be 0"
749 assert result[3] > 0, "The new id should be greater than 0"
750 assert_equal 1, result[4], "The new version should be 1"
752 # Finally check that the node that was saved has saved the data correctly
753 # in both the current and history tables
754 # First check the current table
755 current_node = Node.find(result[3].to_i)
756 assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly"
757 assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly"
758 assert_equal 0, current_node.tags.size, "There seems to be a tag that has been added to the node"
759 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
760 # Now check the history table
761 historic_nodes = OldNode.where(:node_id => result[3])
762 assert_equal 1, historic_nodes.size, "There should only be one historic node created"
763 first_historic_node = historic_nodes.first
764 assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
765 assert_in_delta lon, first_historic_node.lon, 0.00001, "The longitude was not retreuved correctly"
766 assert_equal 0, first_historic_node.tags.size, "There seems to be a tag that have been attached to this node"
767 assert_equal result[4], first_historic_node.version, "The version returned, is different to the one returned by the amf"
770 # This node has some tags
772 # create a node with random lat/lon
773 lat = rand(100) - 50 + rand
774 lon = rand(100) - 50 + rand
776 amf_content "putpoi", "/2", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, { "key" => "value", "ping" => "pong" }, nil]
778 assert_response :success
780 result = amf_result("/2")
782 # check the array returned by the amf
783 assert_equal 5, result.size
784 assert_equal 0, result[0], "Expected to get the status ok in the amf"
785 assert_equal 0, result[2], "The old id should be 0"
786 assert result[3] > 0, "The new id should be greater than 0"
787 assert_equal 1, result[4], "The new version should be 1"
789 # Finally check that the node that was saved has saved the data correctly
790 # in both the current and history tables
791 # First check the current table
792 current_node = Node.find(result[3].to_i)
793 assert_in_delta lat, current_node.lat, 0.00001, "The latitude was not retreieved correctly"
794 assert_in_delta lon, current_node.lon, 0.00001, "The longitude was not retreived correctly"
795 assert_equal 2, current_node.tags.size, "There seems to be a tag that has been added to the node"
796 assert_equal({ "key" => "value", "ping" => "pong" }, current_node.tags, "tags are different")
797 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
798 # Now check the history table
799 historic_nodes = OldNode.where(:node_id => result[3])
800 assert_equal 1, historic_nodes.size, "There should only be one historic node created"
801 first_historic_node = historic_nodes.first
802 assert_in_delta lat, first_historic_node.lat, 0.00001, "The latitude was not retreived correctly"
803 assert_in_delta lon, first_historic_node.lon, 0.00001, "The longitude was not retreuved correctly"
804 assert_equal 2, first_historic_node.tags.size, "There seems to be a tag that have been attached to this node"
805 assert_equal({ "key" => "value", "ping" => "pong" }, first_historic_node.tags, "tags are different")
806 assert_equal result[4], first_historic_node.version, "The version returned, is different to the one returned by the amf"
809 # try creating a POI with rubbish in the tags
810 def test_putpoi_create_with_control_chars
811 # This node has no tags
813 # create a node with random lat/lon
814 lat = rand(100) - 50 + rand
815 lon = rand(100) - 50 + rand
817 changeset = create(:changeset)
818 user = changeset.user
820 mostly_invalid = (0..31).to_a.map(&:chr).join
821 tags = { "something" => "foo#{mostly_invalid}bar" }
823 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, tags, nil]
825 assert_response :success
827 result = amf_result("/1")
829 # check the array returned by the amf
830 assert_equal 5, result.size
831 assert_equal 0, result[0], "Expected to get the status ok in the amf"
832 assert_equal 0, result[2], "The old id should be 0"
833 assert result[3] > 0, "The new id should be greater than 0"
834 assert_equal 1, result[4], "The new version should be 1"
836 # Finally check that the node that was saved has saved the data correctly
837 # in both the current and history tables
838 # First check the current table
839 current_node = Node.find(result[3].to_i)
840 assert_equal 1, current_node.tags.size, "There seems to be a tag that has been added to the node"
841 assert_equal({ "something" => "foo\t\n\rbar" }, current_node.tags, "tags were not fixed correctly")
842 assert_equal result[4], current_node.version, "The version returned, is different to the one returned by the amf"
845 # try creating a POI with rubbish in the tags
846 def test_putpoi_create_with_invalid_utf8
847 # This node has no tags
849 # create a node with random lat/lon
850 lat = rand(100) - 50 + rand
851 lon = rand(100) - 50 + rand
853 changeset = create(:changeset)
854 user = changeset.user
857 tags = { "something" => "foo#{invalid}bar" }
859 amf_content "putpoi", "/1", ["#{user.email}:test", changeset.id, nil, nil, lon, lat, tags, nil]
861 assert_response :success
863 result = amf_result("/1")
865 assert_equal 2, result.size
866 assert_equal -1, result[0], "Expected to get the status FAIL in the amf"
867 assert_equal "One of the tags is invalid. Linux users may need to upgrade to Flash Player 10.1.", result[1]
870 # try deleting a node
871 def test_putpoi_delete_valid
873 cs_id = nd.changeset.id
874 user = nd.changeset.user
876 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
878 assert_response :success
880 result = amf_result("/1")
882 assert_equal 5, result.size
883 assert_equal 0, result[0]
884 assert_equal "", result[1]
885 assert_equal nd.id, result[2]
886 assert_equal nd.id, result[3]
887 assert_equal nd.version + 1, result[4]
889 current_node = Node.find(result[3].to_i)
890 assert_equal false, current_node.visible
893 # try deleting a node that is already deleted
894 def test_putpoi_delete_already_deleted
895 nd = create(:node, :deleted)
896 cs_id = nd.changeset.id
897 user = nd.changeset.user
899 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, nd.lon, nd.lat, nd.tags, false]
901 assert_response :success
903 result = amf_result("/1")
905 assert_equal 3, result.size
906 assert_equal -4, result[0]
907 assert_equal "node", result[1]
908 assert_equal nd.id, result[2]
911 # try deleting a node that has never existed
912 def test_putpoi_delete_not_found
913 changeset = create(:changeset)
915 user = changeset.user
917 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, 1, 999999, 0, 0, {}, false]
919 assert_response :success
921 result = amf_result("/1")
923 assert_equal 3, result.size
924 assert_equal -4, result[0]
925 assert_equal "node", result[1]
926 assert_equal 999999, result[2]
929 # try setting an invalid location on a node
930 def test_putpoi_invalid_latlon
932 cs_id = nd.changeset.id
933 user = nd.changeset.user
935 amf_content "putpoi", "/1", ["#{user.email}:test", cs_id, nd.version, nd.id, 200, 100, nd.tags, true]
937 assert_response :success
939 result = amf_result("/1")
941 assert_equal 2, result.size
942 assert_equal -2, result[0]
943 assert_match /Node is not in the world/, result[1]
946 # check that we can create a way
947 def test_putway_create_valid
948 changeset = create(:changeset)
950 user = changeset.user
958 amf_content "putway", "/1", ["#{user.email}:test", cs_id, 0, -1, [a, b, c], { "test" => "new" }, [], {}]
960 assert_response :success
962 result = amf_result("/1")
963 new_way_id = result[3].to_i
965 assert_equal 8, result.size
966 assert_equal 0, result[0]
967 assert_equal "", result[1]
968 assert_equal -1, result[2]
969 assert_not_equal -1, result[3]
970 assert_equal({}, result[4])
971 assert_equal 1, result[5]
972 assert_equal({}, result[6])
973 assert_equal({}, result[7])
975 new_way = Way.find(new_way_id)
976 assert_equal 1, new_way.version
977 assert_equal [a, b, c], new_way.nds
978 assert_equal({ "test" => "new" }, new_way.tags)
980 amf_content "putway", "/1", ["#{user.email}:test", cs_id, 0, -1, [b, d, e, a], { "test" => "newer" }, [], {}]
982 assert_response :success
984 result = amf_result("/1")
985 new_way_id = result[3].to_i
987 assert_equal 8, result.size
988 assert_equal 0, result[0]
989 assert_equal "", result[1]
990 assert_equal -1, result[2]
991 assert_not_equal -1, result[3]
992 assert_equal({}, result[4])
993 assert_equal 1, result[5]
994 assert_equal({}, result[6])
995 assert_equal({}, result[7])
997 new_way = Way.find(new_way_id)
998 assert_equal 1, new_way.version
999 assert_equal [b, d, e, a], new_way.nds
1000 assert_equal({ "test" => "newer" }, new_way.tags)
1002 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 }]
1004 assert_response :success
1006 result = amf_result("/1")
1007 new_way_id = result[3].to_i
1008 new_node_id = result[4]["-1"].to_i
1010 assert_equal 8, result.size
1011 assert_equal 0, result[0]
1012 assert_equal "", result[1]
1013 assert_equal -1, result[2]
1014 assert_not_equal -1, result[3]
1015 assert_equal({ "-1" => new_node_id }, result[4])
1016 assert_equal 1, result[5]
1017 assert_equal({ new_node_id.to_s => 1, d.to_s => 2 }, result[6])
1018 assert_equal({ a.to_s => 1 }, result[7])
1020 new_way = Way.find(new_way_id)
1021 assert_equal 1, new_way.version
1022 assert_equal [b, new_node_id, d, e], new_way.nds
1023 assert_equal({ "test" => "newest" }, new_way.tags)
1025 new_node = Node.find(new_node_id)
1026 assert_equal 1, new_node.version
1027 assert_equal true, new_node.visible
1028 assert_equal 4.56, new_node.lon
1029 assert_equal 12.34, new_node.lat
1030 assert_equal({ "test" => "new" }, new_node.tags)
1032 changed_node = Node.find(d)
1033 assert_equal 2, changed_node.version
1034 assert_equal true, changed_node.visible
1035 assert_equal 12.34, changed_node.lon
1036 assert_equal 4.56, changed_node.lat
1037 assert_equal({ "test" => "ok" }, changed_node.tags)
1039 # node is not deleted because our other ways are using it
1040 deleted_node = Node.find(a)
1041 assert_equal 1, deleted_node.version
1042 assert_equal true, deleted_node.visible
1045 # check that we can update a way
1046 def test_putway_update_valid
1047 way = create(:way_with_nodes, :nodes_count => 3)
1048 cs_id = way.changeset.id
1049 user = way.changeset.user
1051 assert_not_equal({ "test" => "ok" }, way.tags)
1052 amf_content "putway", "/1", ["#{user.email}:test", cs_id, way.version, way.id, way.nds, { "test" => "ok" }, [], {}]
1054 assert_response :success
1056 result = amf_result("/1")
1058 assert_equal 8, result.size
1059 assert_equal 0, result[0]
1060 assert_equal "", result[1]
1061 assert_equal way.id, result[2]
1062 assert_equal way.id, result[3]
1063 assert_equal({}, result[4])
1064 assert_equal way.version + 1, result[5]
1065 assert_equal({}, result[6])
1066 assert_equal({}, result[7])
1068 new_way = Way.find(way.id)
1069 assert_equal way.version + 1, new_way.version
1070 assert_equal way.nds, new_way.nds
1071 assert_equal({ "test" => "ok" }, new_way.tags)
1073 # Test changing the nodes in the way
1074 a = create(:node).id
1075 b = create(:node).id
1076 c = create(:node).id
1077 d = create(:node).id
1079 assert_not_equal [a, b, c, d], way.nds
1080 amf_content "putway", "/1", ["#{user.email}:test", cs_id, way.version + 1, way.id, [a, b, c, d], way.tags, [], {}]
1082 assert_response :success
1084 result = amf_result("/1")
1086 assert_equal 8, result.size
1087 assert_equal 0, result[0]
1088 assert_equal "", result[1]
1089 assert_equal way.id, result[2]
1090 assert_equal way.id, result[3]
1091 assert_equal({}, result[4])
1092 assert_equal way.version + 2, result[5]
1093 assert_equal({}, result[6])
1094 assert_equal({}, result[7])
1096 new_way = Way.find(way.id)
1097 assert_equal way.version + 2, new_way.version
1098 assert_equal [a, b, c, d], new_way.nds
1099 assert_equal way.tags, new_way.tags
1101 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 }]
1103 assert_response :success
1105 result = amf_result("/1")
1106 new_node_id = result[4]["-1"].to_i
1108 assert_equal 8, result.size
1109 assert_equal 0, result[0]
1110 assert_equal "", result[1]
1111 assert_equal way.id, result[2]
1112 assert_equal way.id, result[3]
1113 assert_equal({ "-1" => new_node_id }, result[4])
1114 assert_equal way.version + 3, result[5]
1115 assert_equal({ new_node_id.to_s => 1, b.to_s => 2 }, result[6])
1116 assert_equal({ d.to_s => 1 }, result[7])
1118 new_way = Way.find(way.id)
1119 assert_equal way.version + 3, new_way.version
1120 assert_equal [a, new_node_id, b, c], new_way.nds
1121 assert_equal way.tags, new_way.tags
1123 new_node = Node.find(new_node_id)
1124 assert_equal 1, new_node.version
1125 assert_equal true, new_node.visible
1126 assert_equal 4.56, new_node.lon
1127 assert_equal 12.34, new_node.lat
1128 assert_equal({ "test" => "new" }, new_node.tags)
1130 changed_node = Node.find(b)
1131 assert_equal 2, changed_node.version
1132 assert_equal true, changed_node.visible
1133 assert_equal 12.34, changed_node.lon
1134 assert_equal 4.56, changed_node.lat
1135 assert_equal({ "test" => "ok" }, changed_node.tags)
1137 deleted_node = Node.find(d)
1138 assert_equal 2, deleted_node.version
1139 assert_equal false, deleted_node.visible
1142 # check that we can delete a way
1143 def test_deleteway_valid
1144 way = create(:way_with_nodes, :nodes_count => 3)
1145 nodes = way.nodes.each_with_object({}) { |n, ns| ns[n.id] = n.version }
1146 cs_id = way.changeset.id
1147 user = way.changeset.user
1149 # Of the three nodes, two should be kept since they are used in
1150 # a different way, and the third deleted since it's unused
1153 create(:way_node, :node => a)
1155 create(:way_node, :node => b)
1158 amf_content "deleteway", "/1", ["#{user.email}:test", cs_id, way.id, way.version, nodes]
1160 assert_response :success
1162 result = amf_result("/1")
1164 assert_equal 5, result.size
1165 assert_equal 0, result[0]
1166 assert_equal "", result[1]
1167 assert_equal way.id, result[2]
1168 assert_equal way.version + 1, result[3]
1169 assert_equal({ c.id.to_s => 2 }, result[4])
1171 new_way = Way.find(way.id)
1172 assert_equal way.version + 1, new_way.version
1173 assert_equal false, new_way.visible
1175 way.nds.each do |node_id|
1176 assert_equal result[4][node_id.to_s].nil?, Node.find(node_id).visible
1180 # check that we can't delete a way that is in use
1181 def test_deleteway_inuse
1182 way = create(:way_with_nodes, :nodes_count => 4)
1183 create(:relation_member, :member => way)
1184 nodes = way.nodes.each_with_object({}) { |n, ns| ns[n.id] = n.version }
1185 cs_id = way.changeset.id
1186 user = way.changeset.user
1188 amf_content "deleteway", "/1", ["#{user.email}:test", cs_id, way.id, way.version, nodes]
1190 assert_response :success
1192 result = amf_result("/1")
1194 assert_equal 2, result.size
1195 assert_equal -1, result[0]
1196 assert_match /Way #{way.id} is still used/, result[1]
1198 new_way = Way.find(way.id)
1199 assert_equal way.version, new_way.version
1200 assert_equal true, new_way.visible
1202 way.nds.each do |node_id|
1203 assert_equal true, Node.find(node_id).visible
1207 # check that we can create a relation
1208 def test_putrelation_create_valid
1209 changeset = create(:changeset)
1210 user = changeset.user
1211 cs_id = changeset.id
1213 node = create(:node)
1214 way = create(:way_with_nodes, :nodes_count => 2)
1215 relation = create(:relation)
1217 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]
1219 assert_response :success
1221 result = amf_result("/1")
1222 new_relation_id = result[3].to_i
1224 assert_equal 5, result.size
1225 assert_equal 0, result[0]
1226 assert_equal "", result[1]
1227 assert_equal -1, result[2]
1228 assert_not_equal -1, result[3]
1229 assert_equal 1, result[4]
1231 new_relation = Relation.find(new_relation_id)
1232 assert_equal 1, new_relation.version
1233 assert_equal [["Node", node.id, "node"], ["Way", way.id, "way"], ["Relation", relation.id, "relation"]], new_relation.members
1234 assert_equal({ "test" => "new" }, new_relation.tags)
1235 assert_equal true, new_relation.visible
1238 # check that we can update a relation
1239 def test_putrelation_update_valid
1240 relation = create(:relation)
1241 create(:relation_member, :relation => relation)
1242 user = relation.changeset.user
1243 cs_id = relation.changeset.id
1245 assert_not_equal({ "test" => "ok" }, relation.tags)
1246 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, { "test" => "ok" }, relation.members, true]
1248 assert_response :success
1250 result = amf_result("/1")
1252 assert_equal 5, result.size
1253 assert_equal 0, result[0]
1254 assert_equal "", result[1]
1255 assert_equal relation.id, result[2]
1256 assert_equal relation.id, result[3]
1257 assert_equal relation.version + 1, result[4]
1259 new_relation = Relation.find(relation.id)
1260 assert_equal relation.version + 1, new_relation.version
1261 assert_equal relation.members, new_relation.members
1262 assert_equal({ "test" => "ok" }, new_relation.tags)
1263 assert_equal true, new_relation.visible
1266 # check that we can delete a relation
1267 def test_putrelation_delete_valid
1268 relation = create(:relation)
1269 create(:relation_member, :relation => relation)
1270 create(:relation_tag, :relation => relation)
1271 cs_id = relation.changeset.id
1272 user = relation.changeset.user
1274 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, relation.tags, relation.members, false]
1276 assert_response :success
1278 result = amf_result("/1")
1280 assert_equal 5, result.size
1281 assert_equal 0, result[0]
1282 assert_equal "", result[1]
1283 assert_equal relation.id, result[2]
1284 assert_equal relation.id, result[3]
1285 assert_equal relation.version + 1, result[4]
1287 new_relation = Relation.find(relation.id)
1288 assert_equal relation.version + 1, new_relation.version
1289 assert_equal [], new_relation.members
1290 assert_equal({}, new_relation.tags)
1291 assert_equal false, new_relation.visible
1294 # check that we can't delete a relation that is in use
1295 def test_putrelation_delete_inuse
1296 relation = create(:relation)
1297 super_relation = create(:relation)
1298 create(:relation_member, :relation => super_relation, :member => relation)
1299 cs_id = relation.changeset.id
1300 user = relation.changeset.user
1302 amf_content "putrelation", "/1", ["#{user.email}:test", cs_id, relation.version, relation.id, relation.tags, relation.members, false]
1304 assert_response :success
1306 result = amf_result("/1")
1308 assert_equal 2, result.size
1309 assert_equal -1, result[0]
1310 assert_match /relation #{relation.id} is used in/, result[1]
1312 new_relation = Relation.find(relation.id)
1313 assert_equal relation.version, new_relation.version
1314 assert_equal relation.members, new_relation.members
1315 assert_equal relation.tags, new_relation.tags
1316 assert_equal true, new_relation.visible
1319 # check that we can open a changeset
1320 def test_startchangeset_valid
1321 user = create(:user)
1323 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
1325 assert_response :success
1327 result = amf_result("/1")
1328 new_cs_id = result[2].to_i
1330 assert_equal 3, result.size
1331 assert_equal 0, result[0]
1332 assert_equal "", result[1]
1334 cs = Changeset.find(new_cs_id)
1335 assert_equal true, cs.is_open?
1336 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1338 old_cs_id = new_cs_id
1340 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "newer" }, old_cs_id, "newer", 1]
1342 assert_response :success
1344 result = amf_result("/1")
1345 new_cs_id = result[2].to_i
1347 assert_not_equal old_cs_id, new_cs_id
1349 assert_equal 3, result.size
1350 assert_equal 0, result[0]
1351 assert_equal "", result[1]
1353 cs = Changeset.find(old_cs_id)
1354 assert_equal false, cs.is_open?
1355 assert_equal({ "comment" => "newer", "source" => "new" }, cs.tags)
1357 cs = Changeset.find(new_cs_id)
1358 assert_equal true, cs.is_open?
1359 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1361 old_cs_id = new_cs_id
1363 amf_content "startchangeset", "/1", ["#{user.email}:test", {}, old_cs_id, "", 0]
1365 assert_response :success
1367 result = amf_result("/1")
1369 assert_equal 3, result.size
1370 assert_equal 0, result[0]
1371 assert_equal "", result[1]
1372 assert_nil result[2]
1374 cs = Changeset.find(old_cs_id)
1375 assert_equal false, cs.is_open?
1376 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1379 # check that we can't close somebody elses changeset
1380 def test_startchangeset_invalid_wrong_user
1381 user = create(:user)
1382 user2 = create(:user)
1384 amf_content "startchangeset", "/1", ["#{user.email}:test", { "source" => "new" }, nil, "new", 1]
1386 assert_response :success
1388 result = amf_result("/1")
1389 cs_id = result[2].to_i
1391 assert_equal 3, result.size
1392 assert_equal 0, result[0]
1393 assert_equal "", result[1]
1395 cs = Changeset.find(cs_id)
1396 assert_equal true, cs.is_open?
1397 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1399 amf_content "startchangeset", "/1", ["#{user2.email}:test", {}, cs_id, "delete", 0]
1401 assert_response :success
1403 result = amf_result("/1")
1405 assert_equal 2, result.size
1406 assert_equal -2, result[0]
1407 assert_equal "The user doesn't own that changeset", result[1]
1409 cs = Changeset.find(cs_id)
1410 assert_equal true, cs.is_open?
1411 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1414 # check that invalid characters are stripped from changeset tags
1415 def test_startchangeset_invalid_xmlchar_comment
1416 user = create(:user)
1418 invalid = "\035\022"
1419 comment = "foo#{invalid}bar"
1421 amf_content "startchangeset", "/1", ["#{user.email}:test", {}, nil, comment, 1]
1423 assert_response :success
1425 result = amf_result("/1")
1426 new_cs_id = result[2].to_i
1428 assert_equal 3, result.size
1429 assert_equal 0, result[0]
1430 assert_equal "", result[1]
1432 cs = Changeset.find(new_cs_id)
1433 assert_equal true, cs.is_open?
1434 assert_equal({ "comment" => "foobar" }, cs.tags)
1439 # ************************************************************
1440 # AMF Helper functions
1442 # Get the result record for the specified ID
1443 # It's an assertion FAIL if the record does not exist
1445 assert @amf_result.key?("#{ref}/onResult")
1446 @amf_result["#{ref}/onResult"]
1449 # Encode the AMF message to invoke "target" with parameters as
1450 # the passed data. The ref is used to retrieve the results.
1451 def amf_content(target, ref, data)
1452 a, b = 1.divmod(256)
1454 c.write 0.chr + 0.chr # version 0
1455 c.write 0.chr + 0.chr # n headers
1456 c.write a.chr + b.chr # n bodies
1457 c.write AMF.encodestring(target)
1458 c.write AMF.encodestring(ref)
1459 c.write [-1].pack("N")
1460 c.write AMF.encodevalue(data)
1462 @request.env["RAW_POST_DATA"] = c.string
1465 # Parses the @response object as an AMF messsage.
1466 # The result is a hash of message_ref => data.
1467 # The attribute @amf_result is initialised to this hash.
1468 def amf_parse_response
1469 req = StringIO.new(@response.body)
1471 req.read(2) # version
1473 # parse through any headers
1474 headers = AMF.getint(req) # Read number of headers
1475 headers.times do # Read each header
1476 AMF.getstring(req) # |
1477 req.getc # | skip boolean
1478 AMF.getvalue(req) # |
1481 # parse through responses
1483 bodies = AMF.getint(req) # Read number of bodies
1484 bodies.times do # Read each body
1485 message = AMF.getstring(req) # | get message name
1486 AMF.getstring(req) # | get index in response sequence
1487 AMF.getlong(req) # | get total size in bytes
1488 args = AMF.getvalue(req) # | get response (probably an array)
1489 results[message] = args
1491 @amf_result = results
1496 # given an array of bounding boxes (each an array of 4 floats), call the
1497 # AMF "whichways" controller for each and pass the result back to the
1498 # caller's block for assertion testing.
1499 def check_bboxes_are_bad(bboxes)
1500 bboxes.each do |bbox|
1501 amf_content "whichways", "/1", bbox
1503 assert_response :success
1506 # pass the response back to the caller's block to be tested
1507 # against what the caller expected.
1508 map = amf_result "/1"
1513 # this should be what AMF controller returns when the bbox of a
1514 # whichways request is invalid or too large.
1515 def assert_boundary_error(map, msg = nil, error_hint = nil)
1516 expected_map = [-2, "Sorry - I can't get the map for that area.#{msg}"]
1517 assert_equal expected_map, map, "AMF controller should have returned an error. (#{error_hint})"
1520 # this should be what AMF controller returns when the bbox of a
1521 # whichways_deleted request is invalid or too large.
1522 def assert_deleted_boundary_error(map, msg = nil, error_hint = nil)
1523 expected_map = [-2, "Sorry - I can't get the map for that area.#{msg}"]
1524 assert_equal expected_map, map, "AMF controller should have returned an error. (#{error_hint})"