]> git.openstreetmap.org Git - rails.git/commitdiff
Move api way version test to integration tests
authorAnton Khorev <tony29@yandex.ru>
Sun, 9 Feb 2025 00:19:11 +0000 (03:19 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 10 Feb 2025 19:25:22 +0000 (22:25 +0300)
test/controllers/api/old_ways_controller_test.rb
test/integration/way_versions_test.rb [new file with mode: 0644]

index 6cfa1d3d8b960e6bc9d362644a8b5cbde59eeccf..141f9cfa338b91cb8b05a17283eb174e730afaf8 100644 (file)
@@ -80,25 +80,7 @@ module Api
                     "redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
     end
 
-    ##
-    # check that we can retrieve versions of a way
-    def test_show
-      way = create(:way, :with_history)
-      used_way = create(:way, :with_history)
-      create(:relation_member, :member => used_way)
-      way_with_versions = create(:way, :with_history, :version => 4)
-
-      create(:way_tag, :way => way)
-      create(:way_tag, :way => used_way)
-      create(:way_tag, :way => way_with_versions)
-      propagate_tags(way, way.old_ways.last)
-      propagate_tags(used_way, used_way.old_ways.last)
-      propagate_tags(way_with_versions, way_with_versions.old_ways.last)
-
-      check_current_version(way.id)
-      check_current_version(used_way.id)
-      check_current_version(way_with_versions.id)
-    end
+    # TODO: test_show
 
     ##
     # test that redacted ways aren't visible, regardless of
@@ -309,27 +291,6 @@ module Api
 
     private
 
-    ##
-    # 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(WaysController.new) do
-        get api_way_path(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 api_way_version_path(way_id, 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
-
     ##
     # look at all the versions of the way in the history and get each version from
     # the versions call. check that they're the same.
@@ -365,11 +326,5 @@ module Api
       # now redact it
       post way_version_redact_path(way.way_id, way.version), :params => { :redaction => redaction.id }, :headers => headers
     end
-
-    def propagate_tags(way, old_way)
-      way.tags.each do |k, v|
-        create(:old_way_tag, :old_way => old_way, :k => k, :v => v)
-      end
-    end
   end
 end
diff --git a/test/integration/way_versions_test.rb b/test/integration/way_versions_test.rb
new file mode 100644 (file)
index 0000000..866e485
--- /dev/null
@@ -0,0 +1,52 @@
+require "test_helper"
+
+class WayVersionsTest < ActionDispatch::IntegrationTest
+  ##
+  # check that we can retrieve versions of a way
+  def test_version
+    way = create(:way, :with_history)
+    used_way = create(:way, :with_history)
+    create(:relation_member, :member => used_way)
+    way_with_versions = create(:way, :with_history, :version => 4)
+
+    create(:way_tag, :way => way)
+    create(:way_tag, :way => used_way)
+    create(:way_tag, :way => way_with_versions)
+    propagate_tags(way, way.old_ways.last)
+    propagate_tags(used_way, used_way.old_ways.last)
+    propagate_tags(way_with_versions, way_with_versions.old_ways.last)
+
+    check_current_version(way.id)
+    check_current_version(used_way.id)
+    check_current_version(way_with_versions.id)
+  end
+
+  private
+
+  ##
+  # 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(WaysController.new) do
+      get api_way_path(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 api_way_version_path(way_id, 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 propagate_tags(way, old_way)
+    way.tags.each do |k, v|
+      create(:old_way_tag, :old_way => old_way, :k => k, :v => v)
+    end
+  end
+end