]> git.openstreetmap.org Git - rails.git/commitdiff
Fixed fixtures and added new tests for ways and way_nodes.
authorMatt Amos <zerebubuth@gmail.com>
Thu, 16 Oct 2008 13:02:09 +0000 (13:02 +0000)
committerMatt Amos <zerebubuth@gmail.com>
Thu, 16 Oct 2008 13:02:09 +0000 (13:02 +0000)
test/fixtures/current_way_nodes.yml
test/fixtures/current_ways.yml
test/fixtures/way_nodes.yml
test/fixtures/ways.yml
test/functional/old_node_controller_test.rb
test/functional/old_way_controller_test.rb
test/test_helper.rb

index ce394edbeed760341fd4f4d97e7f387dc2cd875b..66aae0f20af7ab68653288d1f8c4c84b9b10c02b 100644 (file)
@@ -12,3 +12,8 @@ t3:
   id: 3
   node_id: 3
   sequence_id: 1
+
+t4:
+  id: 4
+  node_id: 15
+  sequence_id: 1
index bd31916e2a8bcea0baae7e2576bcc798c09ccfc5..cf25b4f4654f404b4fc61162ad4f9b5475241eff 100644 (file)
@@ -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
index c12a248a0cea4ec75408745c43b8f355961db686..0b43f6a9c1f586ce70c7c64f4276cb3a2e5a452b 100644 (file)
@@ -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
index bb1a43c8073b561083dc076f5647a11c067c1358..c1ce7222bdb1a8d43a76f00fe03d2f79fe0fe4e7 100644 (file)
@@ -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
+
index 4b0cf0363cf3f33a73c78af04c67a87013c18a69..ca9a114b154c11f969e96ae6d7ab0ec28c684e47 100644 (file)
@@ -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
index b4e3c5127721210ac025f856f2a28bd8c196f057..c6d4ce240180d351d3b7c99c7072c1770c277944 100644 (file)
@@ -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
index 0c03aac346110dff5fa567188a9b514c285103d0..63567cc9b3ef44cab9133b26aa9d9b43f936c307 100644 (file)
@@ -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