Added tests for ways_for_node. Altered behaviour to not return deleted ways. Fixed ways fixture where most recent history != current.
This commit is contained in:
parent
a8eb3a6ada
commit
6339473cb7
7 changed files with 70 additions and 43 deletions
2
test/fixtures/ways.yml
vendored
2
test/fixtures/ways.yml
vendored
|
@ -16,7 +16,7 @@ used_way:
|
|||
id: 3
|
||||
changeset_id: 1
|
||||
timestamp: 2007-01-01 00:00:00
|
||||
visible: 0
|
||||
visible: 1
|
||||
version: 1
|
||||
|
||||
way_with_versions_v1:
|
||||
|
|
|
@ -112,20 +112,6 @@ class OldNodeControllerTest < Test::Unit::TestCase
|
|||
assert_nodes_are_equal current_node, old_node
|
||||
end
|
||||
|
||||
##
|
||||
# for some reason a==b is false, but there doesn't seem to be any
|
||||
# difference between the nodes, so i'm checking all the attributes
|
||||
# manually and blaming it on ActiveRecord
|
||||
def assert_nodes_are_equal(a, b)
|
||||
assert_equal a.id, b.id, "node IDs"
|
||||
assert_equal a.latitude, b.latitude, "latitude on node #{a.id}"
|
||||
assert_equal a.longitude, b.longitude, "longitude on node #{a.id}"
|
||||
assert_equal a.changeset_id, b.changeset_id, "changeset ID on node #{a.id}"
|
||||
assert_equal a.visible, b.visible, "visible on node #{a.id}"
|
||||
assert_equal a.version, b.version, "version on node #{a.id}"
|
||||
assert_equal a.tags, b.tags, "tags on node #{a.id}"
|
||||
end
|
||||
|
||||
##
|
||||
# returns a 16 character long string with some nasty characters in it.
|
||||
# this ought to stress-test the tag handling as well as the versioning.
|
||||
|
|
|
@ -95,16 +95,4 @@ class OldWayControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# for some reason assert_equal a, b fails when the ways are actually
|
||||
# equal, so this method manually checks the fields...
|
||||
def assert_ways_are_equal(a, b)
|
||||
assert_equal a.id, b.id, "way IDs"
|
||||
assert_equal a.changeset_id, b.changeset_id, "changeset ID on way #{a.id}"
|
||||
assert_equal a.visible, b.visible, "visible on way #{a.id}"
|
||||
assert_equal a.version, b.version, "version on way #{a.id}"
|
||||
assert_equal a.tags, b.tags, "tags on way #{a.id}"
|
||||
assert_equal a.nds, b.nds, "node references on way #{a.id}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -37,21 +37,11 @@ class WayControllerTest < Test::Unit::TestCase
|
|||
# check chat a non-existent way is not returned
|
||||
get :read, :id => 0
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
# check the "ways for node" mode
|
||||
get :ways_for_node, :id => current_nodes(:used_node_1).id
|
||||
assert_response :success
|
||||
# FIXME check whether this contains the stuff we want!
|
||||
#print @response.body
|
||||
# Needs to be updated when changing fixtures
|
||||
# The generator should probably be defined in the environment.rb file
|
||||
# in the same place as the api version
|
||||
assert_select "osm[version=#{API_VERSION}][generator=\"OpenStreetMap server\"]", 1
|
||||
assert_select "osm way", 3
|
||||
assert_select "osm way nd", 3
|
||||
assert_select "osm way tag", 3
|
||||
|
||||
# check the "full" mode
|
||||
##
|
||||
# check the "full" mode
|
||||
def test_full
|
||||
get :full, :id => current_ways(:visible_way).id
|
||||
assert_response :success
|
||||
# FIXME check whether this contains the stuff we want!
|
||||
|
@ -290,6 +280,33 @@ class WayControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# test that a call to ways_for_node returns all ways that contain the node
|
||||
# and none that don't.
|
||||
def test_ways_for_node
|
||||
# in current fixtures ways 1 and 3 all use node 3. ways 2 and 4
|
||||
# *used* to use it but doesn't.
|
||||
get :ways_for_node, :id => current_nodes(:used_node_1).id
|
||||
assert_response :success
|
||||
ways_xml = XML::Parser.string(@response.body).parse
|
||||
assert_not_nil ways_xml, "failed to parse ways_for_node response"
|
||||
|
||||
# check that the set of IDs match expectations
|
||||
expected_way_ids = [ current_ways(:visible_way).id,
|
||||
current_ways(:used_way).id
|
||||
]
|
||||
found_way_ids = ways_xml.find("//osm/way").collect { |w| w["id"].to_i }
|
||||
assert_equal expected_way_ids, found_way_ids,
|
||||
"expected ways for node #{current_nodes(:used_node_1).id} did not match found"
|
||||
|
||||
# check the full ways to ensure we're not missing anything
|
||||
expected_way_ids.each do |id|
|
||||
way_xml = ways_xml.find("//osm/way[@id=#{id}]").first
|
||||
assert_ways_are_equal(Way.find(id),
|
||||
Way.from_xml_node(way_xml))
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# update the changeset_id of a node element
|
||||
def update_changeset(xml, changeset_id)
|
||||
|
|
|
@ -72,5 +72,33 @@ class Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# for some reason assert_equal a, b fails when the ways are actually
|
||||
# equal, so this method manually checks the fields...
|
||||
def assert_ways_are_equal(a, b)
|
||||
assert_not_nil a, "first way is not allowed to be nil"
|
||||
assert_not_nil b, "second way #{a.id} is not allowed to be nil"
|
||||
assert_equal a.id, b.id, "way IDs"
|
||||
assert_equal a.changeset_id, b.changeset_id, "changeset ID on way #{a.id}"
|
||||
assert_equal a.visible, b.visible, "visible on way #{a.id}, #{a.visible.inspect} != #{b.visible.inspect}"
|
||||
assert_equal a.version, b.version, "version on way #{a.id}"
|
||||
assert_equal a.tags, b.tags, "tags on way #{a.id}"
|
||||
assert_equal a.nds, b.nds, "node references on way #{a.id}"
|
||||
end
|
||||
|
||||
##
|
||||
# for some reason a==b is false, but there doesn't seem to be any
|
||||
# difference between the nodes, so i'm checking all the attributes
|
||||
# manually and blaming it on ActiveRecord
|
||||
def assert_nodes_are_equal(a, b)
|
||||
assert_equal a.id, b.id, "node IDs"
|
||||
assert_equal a.latitude, b.latitude, "latitude on node #{a.id}"
|
||||
assert_equal a.longitude, b.longitude, "longitude on node #{a.id}"
|
||||
assert_equal a.changeset_id, b.changeset_id, "changeset ID on node #{a.id}"
|
||||
assert_equal a.visible, b.visible, "visible on node #{a.id}"
|
||||
assert_equal a.version, b.version, "version on node #{a.id}"
|
||||
assert_equal a.tags, b.tags, "tags on node #{a.id}"
|
||||
end
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue