]> git.openstreetmap.org Git - rails.git/blob - test/models/old_node_test.rb
Merge remote-tracking branch 'openstreetmap/pull/1416'
[rails.git] / test / models / old_node_test.rb
1 require "test_helper"
2
3 class OldNodeTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_node_count
7     assert_equal 23, OldNode.count
8   end
9
10   def test_node_too_far_north
11     invalid_node_test(:node_too_far_north)
12   end
13
14   def test_node_north_limit
15     valid_node_test(:node_north_limit)
16   end
17
18   def test_node_too_far_south
19     invalid_node_test(:node_too_far_south)
20   end
21
22   def test_node_south_limit
23     valid_node_test(:node_south_limit)
24   end
25
26   def test_node_too_far_west
27     invalid_node_test(:node_too_far_west)
28   end
29
30   def test_node_west_limit
31     valid_node_test(:node_west_limit)
32   end
33
34   def test_node_too_far_east
35     invalid_node_test(:node_too_far_east)
36   end
37
38   def test_node_east_limit
39     valid_node_test(:node_east_limit)
40   end
41
42   def test_totally_wrong
43     invalid_node_test(:node_totally_wrong)
44   end
45
46   # This helper method will check to make sure that a node is within the world, and
47   # has the the same lat, lon and timestamp than what was put into the db by
48   # the fixture
49   def valid_node_test(nod)
50     node = nodes(nod)
51     dbnode = Node.find(node.node_id)
52     assert_equal dbnode.lat, node.latitude.to_f / OldNode::SCALE
53     assert_equal dbnode.lon, node.longitude.to_f / OldNode::SCALE
54     assert_equal dbnode.changeset_id, node.changeset_id
55     assert_equal dbnode.version, node.version
56     assert_equal dbnode.visible, node.visible
57     assert_equal dbnode.timestamp, node.timestamp
58     # assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon)
59     assert node.valid?
60   end
61
62   # This helpermethod will check to make sure that a node is outwith the world,
63   # and has the same lat, lon and timesamp than what was put into the db by the
64   # fixture
65   def invalid_node_test(nod)
66     node = nodes(nod)
67     dbnode = Node.find(node.node_id)
68     assert_equal dbnode.lat, node.latitude.to_f / OldNode::SCALE
69     assert_equal dbnode.lon, node.longitude.to_f / OldNode::SCALE
70     assert_equal dbnode.changeset_id, node.changeset_id
71     assert_equal dbnode.version, node.version
72     assert_equal dbnode.visible, node.visible
73     assert_equal dbnode.timestamp, node.timestamp
74     # assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon)
75     assert_equal false, node.valid?
76   end
77
78   def test_node_tags
79     taglist_v3 = create_list(:old_node_tag, 3, :old_node => nodes(:node_with_versions_v3))
80     taglist_v4 = create_list(:old_node_tag, 2, :old_node => nodes(:node_with_versions_v4))
81
82     node = nodes(:node_with_versions_v1)
83     tags = OldNode.find(node.id).old_tags.order(:k)
84     assert_equal 0, tags.count
85
86     node = nodes(:node_with_versions_v2)
87     tags = OldNode.find(node.id).old_tags.order(:k)
88     assert_equal 0, tags.count
89
90     node = nodes(:node_with_versions_v3)
91     tags = OldNode.find(node.id).old_tags.order(:k)
92     assert_equal taglist_v3.count, tags.count
93     taglist_v3.sort_by!(&:k).each_index do |i|
94       assert_equal taglist_v3[i].k, tags[i].k
95       assert_equal taglist_v3[i].v, tags[i].v
96     end
97
98     node = nodes(:node_with_versions_v4)
99     tags = OldNode.find(node.id).old_tags.order(:k)
100     assert_equal taglist_v4.count, tags.count
101     taglist_v4.sort_by!(&:k).each_index do |i|
102       assert_equal taglist_v4[i].k, tags[i].k
103       assert_equal taglist_v4[i].v, tags[i].v
104     end
105   end
106
107   def test_tags
108     taglist_v3 = create_list(:old_node_tag, 3, :old_node => nodes(:node_with_versions_v3))
109     taglist_v4 = create_list(:old_node_tag, 2, :old_node => nodes(:node_with_versions_v4))
110
111     node = nodes(:node_with_versions_v1)
112     tags = OldNode.find(node.id).tags
113     assert_equal 0, tags.size
114
115     node = nodes(:node_with_versions_v2)
116     tags = OldNode.find(node.id).tags
117     assert_equal 0, tags.size
118
119     node = nodes(:node_with_versions_v3)
120     tags = OldNode.find(node.id).tags
121     assert_equal taglist_v3.count, tags.count
122     taglist_v3.each do |tag|
123       assert_equal tag.v, tags[tag.k]
124     end
125
126     node = nodes(:node_with_versions_v4)
127     tags = OldNode.find(node.id).tags
128     assert_equal taglist_v4.count, tags.count
129     taglist_v4.each do |tag|
130       assert_equal tag.v, tags[tag.k]
131     end
132   end
133 end