Move api way version test to integration tests

This commit is contained in:
Anton Khorev 2025-02-09 03:19:11 +03:00
parent b0afd3453a
commit 0b802240df
2 changed files with 53 additions and 46 deletions

View 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

View file

@ -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