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