]> git.openstreetmap.org Git - rails.git/blob - test/models/old_relation_test.rb
Remove support for legacy trace files
[rails.git] / test / models / old_relation_test.rb
1 require "test_helper"
2
3 class OldRelationTest < ActiveSupport::TestCase
4   def test_relation_tags
5     old_relation_v1 = create(:old_relation, :version => 1)
6     old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
7     old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
8     old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
9     taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => old_relation_v3)
10     taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => old_relation_v4)
11
12     tags = OldRelation.find(old_relation_v1.id).old_tags.order(:k)
13     assert_equal 0, tags.count
14
15     tags = OldRelation.find(old_relation_v2.id).old_tags.order(:k)
16     assert_equal 0, tags.count
17
18     tags = OldRelation.find(old_relation_v3.id).old_tags.order(:k)
19     assert_equal taglist_v3.count, tags.count
20     taglist_v3.sort_by!(&:k).each_index do |i|
21       assert_equal taglist_v3[i].k, tags[i].k
22       assert_equal taglist_v3[i].v, tags[i].v
23     end
24
25     tags = OldRelation.find(old_relation_v4.id).old_tags.order(:k)
26     assert_equal taglist_v4.count, tags.count
27     taglist_v4.sort_by!(&:k).each_index do |i|
28       assert_equal taglist_v4[i].k, tags[i].k
29       assert_equal taglist_v4[i].v, tags[i].v
30     end
31   end
32
33   def test_relation_members
34     old_relation_v1 = create(:old_relation)
35     old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
36     old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
37     old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
38     member_node = create(:node)
39     member_way = create(:way)
40     member_relation = create(:relation)
41     create(:old_relation_member, :old_relation => old_relation_v1, :member => member_node, :member_role => "some node")
42     create(:old_relation_member, :old_relation => old_relation_v2, :member => member_node, :member_role => "some changed node")
43     create(:old_relation_member, :old_relation => old_relation_v3, :member => member_node, :member_role => "some changed node")
44     create(:old_relation_member, :old_relation => old_relation_v3, :member => member_relation, :member_role => "some relation")
45     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_node, :member_role => "some node")
46     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_way, :member_role => "some way")
47     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_relation, :member_role => "some relation")
48
49     members = OldRelation.find(old_relation_v1.id).relation_members
50     assert_equal 1, members.count
51     assert_equal "some node", members[0].member_role
52     assert_equal "Node", members[0].member_type
53     assert_equal member_node.id, members[0].member_id
54
55     members = OldRelation.find(old_relation_v2.id).relation_members
56     assert_equal 1, members.count
57     assert_equal "some changed node", members[0].member_role
58     assert_equal "Node", members[0].member_type
59     assert_equal member_node.id, members[0].member_id
60
61     members = OldRelation.find(old_relation_v3.id).relation_members
62     assert_equal 2, members.count
63     assert_equal "some changed node", members[0].member_role
64     assert_equal "Node", members[0].member_type
65     assert_equal member_node.id, members[0].member_id
66     assert_equal "some relation", members[1].member_role
67     assert_equal "Relation", members[1].member_type
68     assert_equal member_relation.id, members[1].member_id
69
70     members = OldRelation.find(old_relation_v4.id).relation_members
71     assert_equal 3, members.count
72     assert_equal "some node", members[0].member_role
73     assert_equal "Node", members[0].member_type
74     assert_equal member_node.id, members[0].member_id
75     assert_equal "some way", members[1].member_role
76     assert_equal "Way", members[1].member_type
77     assert_equal member_way.id, members[1].member_id
78     assert_equal "some relation", members[2].member_role
79     assert_equal "Relation", members[2].member_type
80     assert_equal member_relation.id, members[2].member_id
81   end
82
83   def test_relations
84     old_relation_v1 = create(:old_relation)
85     old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
86     old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
87     old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
88     member_node = create(:node)
89     member_way = create(:way)
90     member_relation = create(:relation)
91     create(:old_relation_member, :old_relation => old_relation_v1, :member => member_node, :member_role => "some node")
92     create(:old_relation_member, :old_relation => old_relation_v2, :member => member_node, :member_role => "some changed node")
93     create(:old_relation_member, :old_relation => old_relation_v3, :member => member_node, :member_role => "some changed node")
94     create(:old_relation_member, :old_relation => old_relation_v3, :member => member_relation, :member_role => "some relation")
95     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_node, :member_role => "some node")
96     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_way, :member_role => "some way")
97     create(:old_relation_member, :old_relation => old_relation_v4, :member => member_relation, :member_role => "some relation")
98
99     members = OldRelation.find(old_relation_v1.id).members
100     assert_equal 1, members.count
101     assert_equal ["Node", member_node.id, "some node"], members[0]
102
103     members = OldRelation.find(old_relation_v2.id).members
104     assert_equal 1, members.count
105     assert_equal ["Node", member_node.id, "some changed node"], members[0]
106
107     members = OldRelation.find(old_relation_v3.id).members
108     assert_equal 2, members.count
109     assert_equal ["Node", member_node.id, "some changed node"], members[0]
110     assert_equal ["Relation", member_relation.id, "some relation"], members[1]
111
112     members = OldRelation.find(old_relation_v4.id).members
113     assert_equal 3, members.count
114     assert_equal ["Node", member_node.id, "some node"], members[0]
115     assert_equal ["Way", member_way.id, "some way"], members[1]
116     assert_equal ["Relation", member_relation.id, "some relation"], members[2]
117   end
118
119   def test_tags
120     old_relation_v1 = create(:old_relation, :version => 1)
121     old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
122     old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
123     old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
124     taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => old_relation_v3)
125     taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => old_relation_v4)
126
127     tags = OldRelation.find(old_relation_v1.id).tags
128     assert_equal 0, tags.size
129
130     tags = OldRelation.find(old_relation_v2.id).tags
131     assert_equal 0, tags.size
132
133     tags = OldRelation.find(old_relation_v3.id).tags
134     assert_equal taglist_v3.count, tags.count
135     taglist_v3.each do |tag|
136       assert_equal tag.v, tags[tag.k]
137     end
138
139     tags = OldRelation.find(old_relation_v4.id).tags
140     assert_equal taglist_v4.count, tags.count
141     taglist_v4.each do |tag|
142       assert_equal tag.v, tags[tag.k]
143     end
144   end
145 end