1 # frozen_string_literal: true
5 class WayVersionsTest < ActionDispatch::IntegrationTest
7 # check that we can retrieve versions of a way
9 way = create(:way, :with_history)
10 used_way = create(:way, :with_history)
11 create(:relation_member, :member => used_way)
12 way_with_versions = create(:way, :with_history, :version => 4)
14 create(:way_tag, :way => way)
15 create(:way_tag, :way => used_way)
16 create(:way_tag, :way => way_with_versions)
17 propagate_tags(way, way.old_ways.last)
18 propagate_tags(used_way, used_way.old_ways.last)
19 propagate_tags(way_with_versions, way_with_versions.old_ways.last)
21 check_current_version(way.id)
22 check_current_version(used_way.id)
23 check_current_version(way_with_versions.id)
29 # check that the current version of a way is equivalent to the
30 # version which we're getting from the versions call.
31 def check_current_version(way_id)
32 # get the current version
33 current_way = with_controller(WaysController.new) do
34 get api_way_path(way_id)
35 assert_response :success, "can't get current way #{way_id}"
36 Way.from_xml(@response.body)
38 assert_not_nil current_way, "getting way #{way_id} returned nil"
40 # get the "old" version of the way from the version method
41 get api_way_version_path(way_id, current_way.version)
42 assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
43 old_way = Way.from_xml(@response.body)
45 # check that the ways are identical
46 assert_ways_are_equal current_way, old_way
49 def propagate_tags(way, old_way)
50 way.tags.each do |k, v|
51 create(:old_way_tag, :old_way => old_way, :k => k, :v => v)