3 class OldRelationTest < ActiveSupport::TestCase
7 old_relation_v1 = create(:old_relation, :version => 1)
8 old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
9 old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
10 old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
11 taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => old_relation_v3)
12 taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => old_relation_v4)
14 tags = OldRelation.find(old_relation_v1.id).old_tags.order(:k)
15 assert_equal 0, tags.count
17 tags = OldRelation.find(old_relation_v2.id).old_tags.order(:k)
18 assert_equal 0, tags.count
20 tags = OldRelation.find(old_relation_v3.id).old_tags.order(:k)
21 assert_equal taglist_v3.count, tags.count
22 taglist_v3.sort_by!(&:k).each_index do |i|
23 assert_equal taglist_v3[i].k, tags[i].k
24 assert_equal taglist_v3[i].v, tags[i].v
27 tags = OldRelation.find(old_relation_v4.id).old_tags.order(:k)
28 assert_equal taglist_v4.count, tags.count
29 taglist_v4.sort_by!(&:k).each_index do |i|
30 assert_equal taglist_v4[i].k, tags[i].k
31 assert_equal taglist_v4[i].v, tags[i].v
35 def test_relation_members
36 old_relation_v1 = create(:old_relation)
37 old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
38 old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
39 old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
40 member_node = create(:node)
41 member_way = create(:way)
42 member_relation = create(:relation)
43 create(:old_relation_member, :old_relation => old_relation_v1, :member => member_node, :member_role => "some node")
44 create(:old_relation_member, :old_relation => old_relation_v2, :member => member_node, :member_role => "some changed node")
45 create(:old_relation_member, :old_relation => old_relation_v3, :member => member_node, :member_role => "some changed node")
46 create(:old_relation_member, :old_relation => old_relation_v3, :member => member_relation, :member_role => "some relation")
47 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_node, :member_role => "some node")
48 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_way, :member_role => "some way")
49 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_relation, :member_role => "some relation")
51 members = OldRelation.find(old_relation_v1.id).relation_members
52 assert_equal 1, members.count
53 assert_equal "some node", members[0].member_role
54 assert_equal "Node", members[0].member_type
55 assert_equal member_node.id, members[0].member_id
57 members = OldRelation.find(old_relation_v2.id).relation_members
58 assert_equal 1, members.count
59 assert_equal "some changed node", members[0].member_role
60 assert_equal "Node", members[0].member_type
61 assert_equal member_node.id, members[0].member_id
63 members = OldRelation.find(old_relation_v3.id).relation_members
64 assert_equal 2, members.count
65 assert_equal "some changed node", members[0].member_role
66 assert_equal "Node", members[0].member_type
67 assert_equal member_node.id, members[0].member_id
68 assert_equal "some relation", members[1].member_role
69 assert_equal "Relation", members[1].member_type
70 assert_equal member_relation.id, members[1].member_id
72 members = OldRelation.find(old_relation_v4.id).relation_members
73 assert_equal 3, members.count
74 assert_equal "some node", members[0].member_role
75 assert_equal "Node", members[0].member_type
76 assert_equal member_node.id, members[0].member_id
77 assert_equal "some way", members[1].member_role
78 assert_equal "Way", members[1].member_type
79 assert_equal member_way.id, members[1].member_id
80 assert_equal "some relation", members[2].member_role
81 assert_equal "Relation", members[2].member_type
82 assert_equal member_relation.id, members[2].member_id
86 old_relation_v1 = create(:old_relation)
87 old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
88 old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
89 old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
90 member_node = create(:node)
91 member_way = create(:way)
92 member_relation = create(:relation)
93 create(:old_relation_member, :old_relation => old_relation_v1, :member => member_node, :member_role => "some node")
94 create(:old_relation_member, :old_relation => old_relation_v2, :member => member_node, :member_role => "some changed node")
95 create(:old_relation_member, :old_relation => old_relation_v3, :member => member_node, :member_role => "some changed node")
96 create(:old_relation_member, :old_relation => old_relation_v3, :member => member_relation, :member_role => "some relation")
97 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_node, :member_role => "some node")
98 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_way, :member_role => "some way")
99 create(:old_relation_member, :old_relation => old_relation_v4, :member => member_relation, :member_role => "some relation")
101 members = OldRelation.find(old_relation_v1.id).members
102 assert_equal 1, members.count
103 assert_equal ["Node", member_node.id, "some node"], members[0]
105 members = OldRelation.find(old_relation_v2.id).members
106 assert_equal 1, members.count
107 assert_equal ["Node", member_node.id, "some changed node"], members[0]
109 members = OldRelation.find(old_relation_v3.id).members
110 assert_equal 2, members.count
111 assert_equal ["Node", member_node.id, "some changed node"], members[0]
112 assert_equal ["Relation", member_relation.id, "some relation"], members[1]
114 members = OldRelation.find(old_relation_v4.id).members
115 assert_equal 3, members.count
116 assert_equal ["Node", member_node.id, "some node"], members[0]
117 assert_equal ["Way", member_way.id, "some way"], members[1]
118 assert_equal ["Relation", member_relation.id, "some relation"], members[2]
122 old_relation_v1 = create(:old_relation, :version => 1)
123 old_relation_v2 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 2)
124 old_relation_v3 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 3)
125 old_relation_v4 = create(:old_relation, :current_relation => old_relation_v1.current_relation, :version => 4)
126 taglist_v3 = create_list(:old_relation_tag, 3, :old_relation => old_relation_v3)
127 taglist_v4 = create_list(:old_relation_tag, 2, :old_relation => old_relation_v4)
129 tags = OldRelation.find(old_relation_v1.id).tags
130 assert_equal 0, tags.size
132 tags = OldRelation.find(old_relation_v2.id).tags
133 assert_equal 0, tags.size
135 tags = OldRelation.find(old_relation_v3.id).tags
136 assert_equal taglist_v3.count, tags.count
137 taglist_v3.each do |tag|
138 assert_equal tag.v, tags[tag.k]
141 tags = OldRelation.find(old_relation_v4.id).tags
142 assert_equal taglist_v4.count, tags.count
143 taglist_v4.each do |tag|
144 assert_equal tag.v, tags[tag.k]