From: Matt Amos Date: Thu, 16 Oct 2008 13:02:09 +0000 (+0000) Subject: Fixed fixtures and added new tests for ways and way_nodes. X-Git-Tag: live~7604^2~258 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/89c677d8819ed2087a9427fb234253c0fff56a55 Fixed fixtures and added new tests for ways and way_nodes. --- diff --git a/test/fixtures/current_way_nodes.yml b/test/fixtures/current_way_nodes.yml index ce394edbe..66aae0f20 100644 --- a/test/fixtures/current_way_nodes.yml +++ b/test/fixtures/current_way_nodes.yml @@ -12,3 +12,8 @@ t3: id: 3 node_id: 3 sequence_id: 1 + +t4: + id: 4 + node_id: 15 + sequence_id: 1 diff --git a/test/fixtures/current_ways.yml b/test/fixtures/current_ways.yml index bd31916e2..cf25b4f46 100644 --- a/test/fixtures/current_ways.yml +++ b/test/fixtures/current_ways.yml @@ -19,3 +19,9 @@ used_way: visible: 1 version: 1 +way_with_versions: + id: 4 + changeset_id: 4 + timestamp: 2008-01-01 00:01:00 + visible: 1 + version: 4 diff --git a/test/fixtures/way_nodes.yml b/test/fixtures/way_nodes.yml index c12a248a0..0b43f6a9c 100644 --- a/test/fixtures/way_nodes.yml +++ b/test/fixtures/way_nodes.yml @@ -3,12 +3,6 @@ t1a: node_id: 3 sequence_id: 1 version: 1 - -t1b: - id: 1 - node_id: 4 - sequence_id: 2 - version: 1 t2: id: 2 @@ -21,3 +15,51 @@ t3: node_id: 3 sequence_id: 1 version: 1 + +w4_v1_n1: + id: 4 + node_id: 3 + sequence_id: 1 + version: 1 + +w4_v1_n2: + id: 4 + node_id: 4 + sequence_id: 2 + version: 1 + +w4_v2_n1: + id: 4 + node_id: 15 + sequence_id: 1 + version: 2 + +w4_v2_n2: + id: 4 + node_id: 3 + sequence_id: 2 + version: 2 + +w4_v2_n3: + id: 4 + node_id: 4 + sequence_id: 3 + version: 2 + +w4_v3_n1: + id: 4 + node_id: 15 + sequence_id: 1 + version: 3 + +w4_v3_n2: + id: 4 + node_id: 3 + sequence_id: 2 + version: 3 + +w4_v4_n1: + id: 4 + node_id: 15 + sequence_id: 1 + version: 4 diff --git a/test/fixtures/ways.yml b/test/fixtures/ways.yml index bb1a43c80..c1ce7222b 100644 --- a/test/fixtures/ways.yml +++ b/test/fixtures/ways.yml @@ -19,3 +19,31 @@ used_way: visible: 0 version: 1 +way_with_versions_v1: + id: 4 + changeset_id: 4 + timestamp: 2008-01-01 00:01:00 + visible: 1 + version: 1 + +way_with_versions_v2: + id: 4 + changeset_id: 4 + timestamp: 2008-01-01 00:02:00 + visible: 1 + version: 2 + +way_with_versions: + id: 4 + changeset_id: 4 + timestamp: 2008-01-01 00:03:00 + visible: 1 + version: 3 + +way_with_versions_v4: + id: 4 + changeset_id: 4 + timestamp: 2008-01-01 00:04:00 + visible: 1 + version: 4 + diff --git a/test/functional/old_node_controller_test.rb b/test/functional/old_node_controller_test.rb index 4b0cf0363..ca9a114b1 100644 --- a/test/functional/old_node_controller_test.rb +++ b/test/functional/old_node_controller_test.rb @@ -153,18 +153,4 @@ class OldNodeControllerTest < Test::Unit::TestCase @request.env["RAW_POST_DATA"] = c.to_s end - ## - # takes a block which is executed in the context of a different - # ActionController instance. this is used so that code can call methods - # on the node controller whilst testing the old_node controller. - def with_controller(new_controller) - controller_save = @controller - begin - @controller = new_controller - yield - ensure - @controller = controller_save - end - end - end diff --git a/test/functional/old_way_controller_test.rb b/test/functional/old_way_controller_test.rb index b4e3c5127..c6d4ce240 100644 --- a/test/functional/old_way_controller_test.rb +++ b/test/functional/old_way_controller_test.rb @@ -24,10 +24,86 @@ class OldWayControllerTest < Test::Unit::TestCase end def test_history_invisible + # check that an invisible way's history is returned properly + get :history, :id => ways(:invisible_way).id + assert_response :success + end + + def test_history_invalid # check chat a non-existent way is not returned get :history, :id => 0 assert_response :not_found + end + + ## + # check that we can retrieve versions of a way + def test_version + check_current_version(current_ways(:visible_way).id) + check_current_version(current_ways(:used_way).id) + check_current_version(current_ways(:way_with_versions).id) + end + + ## + # check that returned history is the same as getting all + # versions of a way from the api. + def test_history_equals_versions + check_history_equals_versions(current_ways(:visible_way).id) + check_history_equals_versions(current_ways(:used_way).id) + check_history_equals_versions(current_ways(:way_with_versions).id) + end + + ## + # check that the current version of a way is equivalent to the + # version which we're getting from the versions call. + def check_current_version(way_id) + # get the current version + current_way = with_controller(WayController.new) do + get :read, :id => way_id + assert_response :success, "can't get current way #{way_id}" + Way.from_xml(@response.body) + end + assert_not_nil current_way, "getting way #{way_id} returned nil" + + # get the "old" version of the way from the version method + get :version, :id => way_id, :version => current_way.version + assert_response :success, "can't get old way #{way_id}, v#{current_way.version}" + old_way = Way.from_xml(@response.body) + + # check that the ways are identical + assert_ways_are_equal current_way, old_way + end + + ## + # + def check_history_equals_versions(way_id) + get :history, :id => way_id + assert_response :success, "can't get way #{way_id} from API" + history_doc = XML::Parser.string(@response.body).parse + assert_not_nil history_doc, "parsing way #{way_id} history failed" + + history_doc.find("//osm/way").each do |way_doc| + history_way = Way.from_xml_node(way_doc) + assert_not_nil history_way, "parsing way #{way_id} version failed" + + get :version, :id => way_id, :version => history_way.version + assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}" + version_way = Way.from_xml(@response.body) + assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}" + + assert_ways_are_equal history_way, version_way + 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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 0c03aac34..63567cc9b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -58,5 +58,19 @@ class Test::Unit::TestCase set_fixture_class :relation_tags => :OldRelationTag end + ## + # takes a block which is executed in the context of a different + # ActionController instance. this is used so that code can call methods + # on the node controller whilst testing the old_node controller. + def with_controller(new_controller) + controller_save = @controller + begin + @controller = new_controller + yield + ensure + @controller = controller_save + end + end + # Add more helper methods to be used by all tests here... end