From: Anton Khorev Date: Sun, 9 Feb 2025 00:19:11 +0000 (+0300) Subject: Move api way version test to integration tests X-Git-Tag: live~34^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/0b802240dfe83528f185b418876ca804233cff5c Move api way version test to integration tests --- diff --git a/test/controllers/api/old_ways_controller_test.rb b/test/controllers/api/old_ways_controller_test.rb index 6cfa1d3d8..141f9cfa3 100644 --- a/test/controllers/api/old_ways_controller_test.rb +++ b/test/controllers/api/old_ways_controller_test.rb @@ -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 index 000000000..866e48573 --- /dev/null +++ b/test/integration/way_versions_test.rb @@ -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