]> git.openstreetmap.org Git - rails.git/blob - test/models/old_way_test.rb
Merge remote-tracking branch 'openstreetmap/pull/1496'
[rails.git] / test / models / old_way_test.rb
1 require "test_helper"
2
3 class OldWayTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_db_count
7     assert_equal 14, OldWay.count
8   end
9
10   def test_old_nodes
11     way = ways(:way_with_multiple_nodes_v1)
12     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
13     assert_equal 2, nodes.count
14     assert_equal 2, nodes[0].node_id
15     assert_equal 6, nodes[1].node_id
16
17     way = ways(:way_with_multiple_nodes_v2)
18     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
19     assert_equal 3, nodes.count
20     assert_equal 4, nodes[0].node_id
21     assert_equal 15, nodes[1].node_id
22     assert_equal 6, nodes[2].node_id
23   end
24
25   def test_nds
26     way = ways(:way_with_multiple_nodes_v1)
27     nodes = OldWay.find(way.id).nds
28     assert_equal 2, nodes.count
29     assert_equal 2, nodes[0]
30     assert_equal 6, nodes[1]
31
32     way = ways(:way_with_multiple_nodes_v2)
33     nodes = OldWay.find(way.id).nds
34     assert_equal 3, nodes.count
35     assert_equal 4, nodes[0]
36     assert_equal 15, nodes[1]
37     assert_equal 6, nodes[2]
38   end
39
40   def test_way_tags
41     taglist_v3 = create_list(:old_way_tag, 3, :old_way => ways(:way_with_versions_v3))
42     taglist_v4 = create_list(:old_way_tag, 2, :old_way => ways(:way_with_versions_v4))
43
44     way = ways(:way_with_versions_v1)
45     tags = OldWay.find(way.id).old_tags.order(:k)
46     assert_equal 0, tags.count
47
48     way = ways(:way_with_versions_v2)
49     tags = OldWay.find(way.id).old_tags.order(:k)
50     assert_equal 0, tags.count
51
52     way = ways(:way_with_versions_v3)
53     tags = OldWay.find(way.id).old_tags.order(:k)
54     assert_equal taglist_v3.count, tags.count
55     taglist_v3.sort_by!(&:k).each_index do |i|
56       assert_equal taglist_v3[i].k, tags[i].k
57       assert_equal taglist_v3[i].v, tags[i].v
58     end
59
60     way = ways(:way_with_versions_v4)
61     tags = OldWay.find(way.id).old_tags.order(:k)
62     assert_equal taglist_v4.count, tags.count
63     taglist_v4.sort_by!(&:k).each_index do |i|
64       assert_equal taglist_v4[i].k, tags[i].k
65       assert_equal taglist_v4[i].v, tags[i].v
66     end
67   end
68
69   def test_tags
70     taglist_v3 = create_list(:old_way_tag, 3, :old_way => ways(:way_with_versions_v3))
71     taglist_v4 = create_list(:old_way_tag, 2, :old_way => ways(:way_with_versions_v4))
72
73     way = ways(:way_with_versions_v1)
74     tags = OldWay.find(way.id).tags
75     assert_equal 0, tags.size
76
77     way = ways(:way_with_versions_v2)
78     tags = OldWay.find(way.id).tags
79     assert_equal 0, tags.size
80
81     way = ways(:way_with_versions_v3)
82     tags = OldWay.find(way.id).tags
83     assert_equal taglist_v3.count, tags.count
84     taglist_v3.each do |tag|
85       assert_equal tag.v, tags[tag.k]
86     end
87
88     way = ways(:way_with_versions_v4)
89     tags = OldWay.find(way.id).tags
90     assert_equal taglist_v4.count, tags.count
91     taglist_v4.each do |tag|
92       assert_equal tag.v, tags[tag.k]
93     end
94   end
95
96   def test_get_nodes_undelete
97     way = ways(:way_with_versions_v3)
98     node_tag = create(:node_tag, :node => current_nodes(:node_with_versions))
99     node_tag2 = create(:node_tag, :node => current_nodes(:used_node_1))
100     nodes = OldWay.find(way.id).get_nodes_undelete
101     assert_equal 2, nodes.size
102     assert_equal [1.0, 1.0, 15, 4, { node_tag.k => node_tag.v }, true], nodes[0]
103     assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[1]
104
105     way = ways(:way_with_redacted_versions_v2)
106     node_tag3 = create(:node_tag, :node => current_nodes(:invisible_node))
107     nodes = OldWay.find(way.id).get_nodes_undelete
108     assert_equal 2, nodes.size
109     assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[0]
110     assert_equal [2.0, 2.0, 2, 1, { node_tag3.k => node_tag3.v }, false], nodes[1]
111   end
112 end