]> git.openstreetmap.org Git - rails.git/blob - test/integration/way_versions_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / integration / way_versions_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class WayVersionsTest < ActionDispatch::IntegrationTest
6   ##
7   # check that we can retrieve versions of a way
8   def test_version
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)
13
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)
20
21     check_current_version(way.id)
22     check_current_version(used_way.id)
23     check_current_version(way_with_versions.id)
24   end
25
26   private
27
28   ##
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)
37     end
38     assert_not_nil current_way, "getting way #{way_id} returned nil"
39
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)
44
45     # check that the ways are identical
46     assert_ways_are_equal current_way, old_way
47   end
48
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)
52     end
53   end
54 end