5 class AmfControllerTest < ActionController::TestCase
9 # test all routes which lead to this controller
12 { :path => "/api/0.6/amf/read", :method => :post },
13 { :controller => "amf", :action => "amf_read" }
16 { :path => "/api/0.6/amf/write", :method => :post },
17 { :controller => "amf", :action => "amf_write" }
22 user_en_de = create(:user, :languages => %w(en de))
23 user_de = create(:user, :languages => %w(de))
24 [user_en_de, user_de].each do |user|
25 amf_content "getpresets", "/1", ["#{user.email}:test", ""]
27 assert_response :success
29 presets = amf_result("/1")
31 assert_equal 15, presets.length
32 assert_equal POTLATCH_PRESETS[0], presets[0]
33 assert_equal POTLATCH_PRESETS[1], presets[1]
34 assert_equal POTLATCH_PRESETS[2], presets[2]
35 assert_equal POTLATCH_PRESETS[3], presets[3]
36 assert_equal POTLATCH_PRESETS[4], presets[4]
37 assert_equal POTLATCH_PRESETS[5], presets[5]
38 assert_equal POTLATCH_PRESETS[6], presets[6]
39 assert_equal POTLATCH_PRESETS[7], presets[7]
40 assert_equal POTLATCH_PRESETS[8], presets[8]
41 assert_equal POTLATCH_PRESETS[9], presets[9]
42 assert_equal POTLATCH_PRESETS[10], presets[10]
43 assert_equal POTLATCH_PRESETS[12], presets[12]
44 assert_equal user.languages.first, presets[13]["__potlatch_locale"]
50 way = create(:way_with_nodes, :nodes_count => 1)
51 node = way.nodes.first
52 user = way.changeset.user
54 amf_content "getway", "/1", [way.id]
56 assert_response :success
58 result = amf_result("/1")
59 assert_equal 0, result[0]
60 assert_equal "", result[1]
61 assert_equal way.id, result[2]
62 assert_equal 1, result[3].length
63 assert_equal node.id, result[3][0][2]
64 assert_equal way.version, result[5]
65 assert_equal user.id, result[6]
68 def test_getway_invisible
69 # check an invisible way
70 id = create(:way, :deleted).id
72 amf_content "getway", "/1", [id]
74 assert_response :success
76 result = amf_result("/1")
77 assert_equal -4, result[0]
78 assert_equal "way", result[1]
79 assert_equal id, result[2]
80 assert(result[3].nil? && result[4].nil? && result[5].nil? && result[6].nil?)
83 def test_getway_with_versions
84 # check a way with multiple versions
85 way = create(:way, :with_history, :version => 4)
86 create(:way_node, :way => way)
87 node = way.nodes.first
88 user = way.changeset.user
90 amf_content "getway", "/1", [way.id]
92 assert_response :success
94 result = amf_result("/1")
95 assert_equal 0, result[0]
96 assert_equal "", result[1]
97 assert_equal way.id, result[2]
98 assert_equal 1, result[3].length
99 assert_equal node.id, result[3][0][2]
100 assert_equal way.version, result[5]
101 assert_equal user.id, result[6]
104 def test_getway_with_duplicate_nodes
105 # check a way with duplicate nodes
108 create(:way_node, :way => way, :node => node, :sequence_id => 1)
109 create(:way_node, :way => way, :node => node, :sequence_id => 2)
110 user = way.changeset.user
112 amf_content "getway", "/1", [way.id]
114 assert_response :success
116 result = amf_result("/1")
117 assert_equal 0, result[0]
118 assert_equal "", result[1]
119 assert_equal way.id, result[2]
120 assert_equal 2, result[3].length
121 assert_equal node.id, result[3][0][2]
122 assert_equal node.id, result[3][1][2]
123 assert_equal way.version, result[5]
124 assert_equal user.id, result[6]
127 def test_getway_with_multiple_nodes
128 # check a way with multiple nodes
129 way = create(:way_with_nodes, :nodes_count => 3)
133 user = way.changeset.user
135 amf_content "getway", "/1", [way.id]
137 assert_response :success
139 result = amf_result("/1")
140 assert_equal 0, result[0]
141 assert_equal "", result[1]
142 assert_equal way.id, result[2]
143 assert_equal 3, result[3].length
144 assert_equal a, result[3][0][2]
145 assert_equal b, result[3][1][2]
146 assert_equal c, result[3][2][2]
147 assert_equal way.version, result[5]
148 assert_equal user.id, result[6]
151 def test_getway_nonexistent
152 # check chat a non-existent way is not returned
153 amf_content "getway", "/1", [0]
155 assert_response :success
157 way = amf_result("/1")
158 assert_equal -4, way[0]
159 assert_equal "way", way[1]
160 assert_equal 0, way[2]
161 assert(way[3].nil?) && way[4].nil? && way[5].nil? && way[6].nil?
165 node = create(:node, :lat => 3.0, :lon => 3.0)
167 deleted_way = create(:way, :deleted)
168 create(:way_node, :way => way, :node => node)
169 create(:way_node, :way => deleted_way, :node => node)
170 create(:way_tag, :way => way)
172 minlon = node.lon - 0.1
173 minlat = node.lat - 0.1
174 maxlon = node.lon + 0.1
175 maxlat = node.lat + 0.1
176 amf_content "whichways", "/1", [minlon, minlat, maxlon, maxlat]
178 assert_response :success
181 # check contents of message
182 map = amf_result "/1"
183 assert_equal 0, map[0], "map error code should be 0"
184 assert_equal "", map[1], "map error text should be empty"
186 # check the formatting of the message
187 assert_equal 5, map.length, "map should have length 5"
188 assert_equal Array, map[2].class, 'map "ways" element should be an array'
189 assert_equal Array, map[3].class, 'map "nodes" element should be an array'
190 assert_equal Array, map[4].class, 'map "relations" element should be an array'
192 assert_equal 2, w.length, "way should be (id, version) pair"
193 assert w[0] == w[0].floor, "way ID should be an integer"
194 assert w[1] == w[1].floor, "way version should be an integer"
198 assert_equal 5, w.length, "node should be (id, lat, lon, [tags], version) tuple"
199 assert n[0] == n[0].floor, "node ID should be an integer"
200 assert n[1] >= minlat - 0.01, "node lat should be greater than min"
201 assert n[1] <= maxlat - 0.01, "node lat should be less than max"
202 assert n[2] >= minlon - 0.01, "node lon should be greater than min"
203 assert n[2] <= maxlon - 0.01, "node lon should be less than max"
204 assert_equal Array, a[3].class, "node tags should be array"
205 assert n[4] == n[4].floor, "node version should be an integer"
209 assert_equal 2, r.length, "relation should be (id, version) pair"
210 assert r[0] == r[0].floor, "relation ID should be an integer"
211 assert r[1] == r[1].floor, "relation version should be an integer"
214 # TODO: looks like amf_controller changed since this test was written
215 # so someone who knows what they're doing should check this!
216 ways = map[2].collect { |x| x[0] }
217 assert ways.include?(way.id),
218 "map should include used way"
219 assert !ways.include?(deleted_way.id),
220 "map should not include deleted way"
224 # checks that too-large a bounding box will not be served.
225 def test_whichways_toobig
226 bbox = [-0.1, -0.1, 1.1, 1.1]
227 check_bboxes_are_bad [bbox] do |map, _bbox|
228 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"
233 # checks that an invalid bounding box will not be served. in this case
234 # one with max < min latitudes.
236 # NOTE: the controller expands the bbox by 0.01 in each direction!
237 def test_whichways_badlat
238 bboxes = [[0, 0.1, 0.1, 0], [-0.1, 80, 0.1, 70], [0.24, 54.35, 0.25, 54.33]]
239 check_bboxes_are_bad bboxes do |map, bbox|
240 assert_boundary_error map, " The server said: The minimum latitude must be less than the maximum latitude, but it wasn't", bbox.inspect
245 # same as test_whichways_badlat, but for longitudes
247 # NOTE: the controller expands the bbox by 0.01 in each direction!
248 def test_whichways_badlon
249 bboxes = [[80, -0.1, 70, 0.1], [54.35, 0.24, 54.33, 0.25]]
250 check_bboxes_are_bad bboxes do |map, bbox|
251 assert_boundary_error map, " The server said: The minimum longitude must be less than the maximum longitude, but it wasn't", bbox.inspect
255 def test_whichways_deleted
256 node = create(:node, :with_history, :lat => 24.0, :lon => 24.0)
257 way = create(:way, :with_history)
258 way_v1 = way.old_ways.find_by(:version => 1)
259 deleted_way = create(:way, :with_history, :deleted)
260 deleted_way_v1 = deleted_way.old_ways.find_by(:version => 1)
261 create(:way_node, :way => way, :node => node)
262 create(:way_node, :way => deleted_way, :node => node)
263 create(:old_way_node, :old_way => way_v1, :node => node)
264 create(:old_way_node, :old_way => deleted_way_v1, :node => node)
266 minlon = node.lon - 0.1
267 minlat = node.lat - 0.1
268 maxlon = node.lon + 0.1
269 maxlat = node.lat + 0.1
270 amf_content "whichways_deleted", "/1", [minlon, minlat, maxlon, maxlat]
272 assert_response :success
275 # check contents of message
276 map = amf_result "/1"
277 assert_equal 0, map[0], "first map element should be 0"
278 assert_equal "", map[1], "second map element should be an empty string"
279 assert_equal Array, map[2].class, "third map element should be an array"
280 # TODO: looks like amf_controller changed since this test was written
281 # so someone who knows what they're doing should check this!
282 assert !map[2].include?(way.id),
283 "map should not include visible way"
284 assert map[2].include?(deleted_way.id),
285 "map should include deleted way"
288 def test_whichways_deleted_toobig
289 bbox = [-0.1, -0.1, 1.1, 1.1]
290 amf_content "whichways_deleted", "/1", bbox
292 assert_response :success
295 map = amf_result "/1"
296 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"
300 id = create(:relation).id
301 amf_content "getrelation", "/1", [id]
303 assert_response :success
305 rel = amf_result("/1")
306 assert_equal rel[0], 0
307 assert_equal rel[2], id
310 def test_getrelation_invisible
311 id = create(:relation, :deleted).id
312 amf_content "getrelation", "/1", [id]
314 assert_response :success
316 rel = amf_result("/1")
317 assert_equal rel[0], -4
318 assert_equal rel[1], "relation"
319 assert_equal rel[2], id
320 assert(rel[3].nil?) && rel[4].nil?
323 def test_getrelation_nonexistent
325 amf_content "getrelation", "/1", [id]
327 assert_response :success
329 rel = amf_result("/1")
330 assert_equal rel[0], -4
331 assert_equal rel[1], "relation"
332 assert_equal rel[2], id
333 assert(rel[3].nil?) && rel[4].nil?
337 latest = create(:way, :version => 2)
338 v1 = create(:old_way, :current_way => latest, :version => 1, :timestamp => Time.now.utc - 2.minutes)
339 _v2 = create(:old_way, :current_way => latest, :version => 2, :timestamp => Time.now.utc - 1.minute)
341 # try to get the last visible version (specified by <0) (should be current version)
342 # NOTE: looks from the API changes that this now expects a timestamp
343 # instead of a version number...
344 # try to get version 1
346 v1.way_id => (v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S") }.each do |id, t|
347 amf_content "getway_old", "/1", [id, t]
349 assert_response :success
351 returned_way = amf_result("/1")
352 assert_equal 0, returned_way[0]
353 assert_equal id, returned_way[2]
354 # API returns the *latest* version, even for old ways...
355 assert_equal latest.version, returned_way[5]
360 # test that the server doesn't fall over when rubbish is passed
361 # into the method args.
362 def test_getway_old_invalid
363 way_id = create(:way, :with_history, :version => 2).id
365 way_id => "not a date",
366 way_id => "2009-03-25 00:00:00", # <- wrong format
367 way_id => "0 Jan 2009 00:00:00", # <- invalid date
368 -1 => "1 Jan 2009 00:00:00" }.each do |id, t| # <- invalid
369 amf_content "getway_old", "/1", [id, t]
371 assert_response :success
373 returned_way = amf_result("/1")
374 assert_equal -1, returned_way[0]
375 assert returned_way[3].nil?
376 assert returned_way[4].nil?
377 assert returned_way[5].nil?
381 def test_getway_old_nonexistent
382 # try to get the last version-10 (shoudn't exist)
383 way = create(:way, :with_history, :version => 2)
384 v1 = way.old_ways.find_by(:version => 1)
385 # try to get last visible version of non-existent way
386 # try to get specific version of non-existent way
388 [0, "1 Jan 1970, 00:00:00"],
389 [v1.way_id, (v1.timestamp - 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
390 amf_content "getway_old", "/1", [id, t]
392 assert_response :success
394 returned_way = amf_result("/1")
395 assert_equal -1, returned_way[0]
396 assert returned_way[3].nil?
397 assert returned_way[4].nil?
398 assert returned_way[5].nil?
402 def test_getway_old_invisible
403 way = create(:way, :deleted, :with_history, :version => 1)
404 v1 = way.old_ways.find_by(:version => 1)
405 # try to get deleted version
406 [[v1.way_id, (v1.timestamp + 10).strftime("%d %b %Y, %H:%M:%S")]].each do |id, t|
407 amf_content "getway_old", "/1", [id, t]
409 assert_response :success
411 returned_way = amf_result("/1")
412 assert_equal -1, returned_way[0]
413 assert returned_way[3].nil?
414 assert returned_way[4].nil?
415 assert returned_way[5].nil?
419 def test_getway_history
420 latest = create(:way, :version => 2)
421 oldest = create(:old_way, :current_way => latest, :version => 1, :timestamp => latest.timestamp - 2.minutes)
422 create(:old_way, :current_way => latest, :version => 2, :timestamp => latest.timestamp)
424 amf_content "getway_history", "/1", [latest.id]
426 assert_response :success
428 history = amf_result("/1")
430 # ['way',wayid,history]
431 assert_equal "way", history[0]
432 assert_equal latest.id, history[1]
433 # We use dates rather than version numbers here, because you might
434 # have moved a node within a way (i.e. way version not incremented).
435 # The timestamp is +1 because we say "give me the revision of 15:33:02",
436 # but that might actually include changes at 15:33:02.457.
437 assert_equal (latest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
438 assert_equal (oldest.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
441 def test_getway_history_nonexistent
442 amf_content "getway_history", "/1", [0]
444 assert_response :success
446 history = amf_result("/1")
448 # ['way',wayid,history]
449 assert_equal history[0], "way"
450 assert_equal history[1], 0
451 assert history[2].empty?
454 def test_getnode_history
455 node = create(:node, :version => 2)
456 node_v1 = create(:old_node, :current_node => node, :version => 1, :timestamp => 3.days.ago)
457 _node_v2 = create(:old_node, :current_node => node, :version => 2, :timestamp => 2.days.ago)
458 node_v3 = create(:old_node, :current_node => node, :version => 3, :timestamp => 1.day.ago)
460 amf_content "getnode_history", "/1", [node.id]
462 assert_response :success
464 history = amf_result("/1")
466 # ['node',nodeid,history]
467 # note that (as per getway_history) we actually round up
469 assert_equal history[0], "node",
470 'first element should be "node"'
471 assert_equal history[1], node.id,
472 "second element should be the input node ID"
473 assert_equal history[2].first[0],
474 (node_v3.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
475 "first element in third element (array) should be the latest version"
476 assert_equal history[2].last[0],
477 (node_v1.timestamp + 1).strftime("%d %b %Y, %H:%M:%S"),
478 "last element in third element (array) should be the initial version"
481 def test_getnode_history_nonexistent
482 amf_content "getnode_history", "/1", [0]
484 assert_response :success
486 history = amf_result("/1")
488 # ['node',nodeid,history]
489 assert_equal history[0], "node"
490 assert_equal history[1], 0
491 assert history[2].empty?
494 def test_findgpx_bad_user
495 amf_content "findgpx", "/1", [1, "test@example.com:wrong"]
497 assert_response :success
499 result = amf_result("/1")
501 assert_equal 2, result.length
502 assert_equal -1, result[0]
503 assert_match /must be logged in/, result[1]
505 blocked_user = create(:user)
506 create(:user_block, :user => blocked_user)
507 amf_content "findgpx", "/1", [1, "#{blocked_user.email}:test"]
509 assert_response :success
511 result = amf_result("/1")
513 assert_equal 2, result.length
514 assert_equal -1, result[0]
515 assert_match /access to the API has been blocked/, result[1]
518 def test_findgpx_by_id
520 trace = create(:trace, :visibility => "private", :user => user)
522 amf_content "findgpx", "/1", [trace.id, "#{user.email}:test"]
524 assert_response :success
526 result = amf_result("/1")
528 assert_equal 3, result.length
529 assert_equal 0, result[0]
530 assert_equal "", result[1]
532 assert_equal 1, traces.length
533 assert_equal 3, traces[0].length
534 assert_equal trace.id, traces[0][0]
535 assert_equal trace.name, traces[0][1]
536 assert_equal trace.description, traces[0][2]
539 def test_findgpx_by_name
540 amf_content "findgpx", "/1", ["Trace", "test@example.com: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 amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "new" }, nil, "new", 1]
1323 assert_response :success
1325 result = amf_result("/1")
1326 new_cs_id = result[2].to_i
1328 assert_equal 3, result.size
1329 assert_equal 0, result[0]
1330 assert_equal "", result[1]
1332 cs = Changeset.find(new_cs_id)
1333 assert_equal true, cs.is_open?
1334 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1336 old_cs_id = new_cs_id
1338 amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "newer" }, old_cs_id, "newer", 1]
1340 assert_response :success
1342 result = amf_result("/1")
1343 new_cs_id = result[2].to_i
1345 assert_not_equal old_cs_id, new_cs_id
1347 assert_equal 3, result.size
1348 assert_equal 0, result[0]
1349 assert_equal "", result[1]
1351 cs = Changeset.find(old_cs_id)
1352 assert_equal false, cs.is_open?
1353 assert_equal({ "comment" => "newer", "source" => "new" }, cs.tags)
1355 cs = Changeset.find(new_cs_id)
1356 assert_equal true, cs.is_open?
1357 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1359 old_cs_id = new_cs_id
1361 amf_content "startchangeset", "/1", ["test@example.com:test", {}, old_cs_id, "", 0]
1363 assert_response :success
1365 result = amf_result("/1")
1367 assert_equal 3, result.size
1368 assert_equal 0, result[0]
1369 assert_equal "", result[1]
1370 assert_nil result[2]
1372 cs = Changeset.find(old_cs_id)
1373 assert_equal false, cs.is_open?
1374 assert_equal({ "comment" => "newer", "source" => "newer" }, cs.tags)
1377 # check that we can't close somebody elses changeset
1378 def test_startchangeset_invalid_wrong_user
1379 amf_content "startchangeset", "/1", ["test@example.com:test", { "source" => "new" }, nil, "new", 1]
1381 assert_response :success
1383 result = amf_result("/1")
1384 cs_id = result[2].to_i
1386 assert_equal 3, result.size
1387 assert_equal 0, result[0]
1388 assert_equal "", result[1]
1390 cs = Changeset.find(cs_id)
1391 assert_equal true, cs.is_open?
1392 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1394 amf_content "startchangeset", "/1", ["test@openstreetmap.org:test", {}, cs_id, "delete", 0]
1396 assert_response :success
1398 result = amf_result("/1")
1400 assert_equal 2, result.size
1401 assert_equal -2, result[0]
1402 assert_equal "The user doesn't own that changeset", result[1]
1404 cs = Changeset.find(cs_id)
1405 assert_equal true, cs.is_open?
1406 assert_equal({ "comment" => "new", "source" => "new" }, cs.tags)
1409 # check that invalid characters are stripped from changeset tags
1410 def test_startchangeset_invalid_xmlchar_comment
1411 invalid = "\035\022"
1412 comment = "foo#{invalid}bar"
1414 amf_content "startchangeset", "/1", ["test@example.com:test", {}, nil, comment, 1]
1416 assert_response :success
1418 result = amf_result("/1")
1419 new_cs_id = result[2].to_i
1421 assert_equal 3, result.size
1422 assert_equal 0, result[0]
1423 assert_equal "", result[1]
1425 cs = Changeset.find(new_cs_id)
1426 assert_equal true, cs.is_open?
1427 assert_equal({ "comment" => "foobar" }, cs.tags)
1432 # ************************************************************
1433 # AMF Helper functions
1435 # Get the result record for the specified ID
1436 # It's an assertion FAIL if the record does not exist
1438 assert @amf_result.key?("#{ref}/onResult")
1439 @amf_result["#{ref}/onResult"]
1442 # Encode the AMF message to invoke "target" with parameters as
1443 # the passed data. The ref is used to retrieve the results.
1444 def amf_content(target, ref, data)
1445 a, b = 1.divmod(256)
1447 c.write 0.chr + 0.chr # version 0
1448 c.write 0.chr + 0.chr # n headers
1449 c.write a.chr + b.chr # n bodies
1450 c.write AMF.encodestring(target)
1451 c.write AMF.encodestring(ref)
1452 c.write [-1].pack("N")
1453 c.write AMF.encodevalue(data)
1455 @request.env["RAW_POST_DATA"] = c.string
1458 # Parses the @response object as an AMF messsage.
1459 # The result is a hash of message_ref => data.
1460 # The attribute @amf_result is initialised to this hash.
1461 def amf_parse_response
1462 req = StringIO.new(@response.body)
1464 req.read(2) # version
1466 # parse through any headers
1467 headers = AMF.getint(req) # Read number of headers
1468 headers.times do # Read each header
1469 AMF.getstring(req) # |
1470 req.getc # | skip boolean
1471 AMF.getvalue(req) # |
1474 # parse through responses
1476 bodies = AMF.getint(req) # Read number of bodies
1477 bodies.times do # Read each body
1478 message = AMF.getstring(req) # | get message name
1479 AMF.getstring(req) # | get index in response sequence
1480 AMF.getlong(req) # | get total size in bytes
1481 args = AMF.getvalue(req) # | get response (probably an array)
1482 results[message] = args
1484 @amf_result = results
1489 # given an array of bounding boxes (each an array of 4 floats), call the
1490 # AMF "whichways" controller for each and pass the result back to the
1491 # caller's block for assertion testing.
1492 def check_bboxes_are_bad(bboxes)
1493 bboxes.each do |bbox|
1494 amf_content "whichways", "/1", bbox
1496 assert_response :success
1499 # pass the response back to the caller's block to be tested
1500 # against what the caller expected.
1501 map = amf_result "/1"
1506 # this should be what AMF controller returns when the bbox of a
1507 # whichways request is invalid or too large.
1508 def assert_boundary_error(map, msg = nil, error_hint = nil)
1509 expected_map = [-2, "Sorry - I can't get the map for that area.#{msg}"]
1510 assert_equal expected_map, map, "AMF controller should have returned an error. (#{error_hint})"
1513 # this should be what AMF controller returns when the bbox of a
1514 # whichways_deleted request is invalid or too large.
1515 def assert_deleted_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})"