From aeaf2d2d20ddec901c5e509be678d8c7583ce788 Mon Sep 17 00:00:00 2001 From: Matt Amos Date: Wed, 10 Dec 2008 14:31:07 +0000 Subject: [PATCH 1/1] Added missing version to the pure rails AMF controller. More stringent tests on whichways. --- app/controllers/amf_controller.rb | 4 ++-- test/functional/amf_controller_test.rb | 32 ++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 45dbea4db..2b9a756d8 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -171,7 +171,7 @@ class AmfController < ApplicationController # return is of the form: # [error_code, # [[way_id, way_version], ...], - # [[node_id, lat, lon, [tags, ...]], ...], + # [[node_id, lat, lon, [tags, ...], node_version], ...], # [[rel_id, rel_version], ...]] # where the ways are any visible ways which refer to any visible # nodes in the bbox, nodes are any visible nodes in the bbox but not @@ -200,7 +200,7 @@ class AmfController < ApplicationController # find the node ids in an area that aren't part of ways nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? } - points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags] } + points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags, n.version] } # find the relations used by those nodes and ways relations = Relation.find_for_nodes(nodes_in_area.collect { |n| n.id }, :conditions => {:visible => true}) + diff --git a/test/functional/amf_controller_test.rb b/test/functional/amf_controller_test.rb index eb7fd1487..b1b2212e7 100644 --- a/test/functional/amf_controller_test.rb +++ b/test/functional/amf_controller_test.rb @@ -55,8 +55,36 @@ class AmfControllerTest < ActionController::TestCase # check contents of message map = amf_result "/1" - assert_equal 0, map[0], 'first map element should be 0' - assert_equal Array, map[1].class, 'second map element should be an array' + assert_equal 0, map[0], 'map error code should be 0' + + # check the formatting of the message + assert_equal 4, map.length, 'map should have length 4' + assert_equal Array, map[1].class, 'map "ways" element should be an array' + assert_equal Array, map[2].class, 'map "nodes" element should be an array' + assert_equal Array, map[3].class, 'map "relations" element should be an array' + map[1].each do |w| + assert_equal 2, w.length, 'way should be (id, version) pair' + assert w[0] == w[0].floor, 'way ID should be an integer' + assert w[1] == w[1].floor, 'way version should be an integer' + end + + map[2].each do |n| + assert_equal 5, w.length, 'node should be (id, lat, lon, [tags], version) tuple' + assert n[0] == n[0].floor, 'node ID should be an integer' + assert n[1] >= minlat - 0.01, 'node lat should be greater than min' + assert n[1] <= maxlat - 0.01, 'node lat should be less than max' + assert n[2] >= minlon - 0.01, 'node lon should be greater than min' + assert n[2] <= maxlon - 0.01, 'node lon should be less than max' + assert_equal Array, a[3].class, 'node tags should be array' + assert n[4] == n[4].floor, 'node version should be an integer' + end + + map[3].each do |r| + assert_equal 2, r.length, 'relation should be (id, version) pair' + assert r[0] == r[0].floor, 'relation ID should be an integer' + assert r[1] == r[1].floor, 'relation version should be an integer' + end + # TODO: looks like amf_controller changed since this test was written # so someone who knows what they're doing should check this! ways = map[1].collect { |x| x[0] } -- 2.43.2