1 require File.dirname(__FILE__) + '/../test_helper'
3 class OldNodeTest < ActiveSupport::TestCase
7 assert_equal 21, OldNode.count
10 def test_node_too_far_north
11 invalid_node_test(:node_too_far_north)
14 def test_node_north_limit
15 valid_node_test(:node_north_limit)
18 def test_node_too_far_south
19 invalid_node_test(:node_too_far_south)
22 def test_node_south_limit
23 valid_node_test(:node_south_limit)
26 def test_node_too_far_west
27 invalid_node_test(:node_too_far_west)
30 def test_node_west_limit
31 valid_node_test(:node_west_limit)
34 def test_node_too_far_east
35 invalid_node_test(:node_too_far_east)
38 def test_node_east_limit
39 valid_node_test(:node_east_limit)
42 def test_totally_wrong
43 invalid_node_test(:node_totally_wrong)
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
49 def valid_node_test(nod)
51 dbnode = Node.find(node.node_id)
52 assert_equal dbnode.lat, node.latitude.to_f/SCALE
53 assert_equal dbnode.lon, node.longitude.to_f/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)
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
65 def invalid_node_test(nod)
67 dbnode = Node.find(node.node_id)
68 assert_equal dbnode.lat, node.latitude.to_f/SCALE
69 assert_equal dbnode.lon, node.longitude.to_f/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?
79 node = nodes(:node_with_versions_v1)
80 tags = OldNode.find(node.id).old_tags.order(:k)
81 assert_equal 0, tags.count
83 node = nodes(:node_with_versions_v2)
84 tags = OldNode.find(node.id).old_tags.order(:k)
85 assert_equal 0, tags.count
87 node = nodes(:node_with_versions_v3)
88 tags = OldNode.find(node.id).old_tags.order(:k)
89 assert_equal 3, tags.count
90 assert_equal "testing", tags[0].k
91 assert_equal "added in node version 3", tags[0].v
92 assert_equal "testing three", tags[1].k
93 assert_equal "added in node version 3", tags[1].v
94 assert_equal "testing two", tags[2].k
95 assert_equal "added in node version 3", tags[2].v
97 node = nodes(:node_with_versions_v4)
98 tags = OldNode.find(node.id).old_tags.order(:k)
99 assert_equal 2, tags.count
100 assert_equal "testing", tags[0].k
101 assert_equal "added in node version 3", tags[0].v
102 assert_equal "testing two", tags[1].k
103 assert_equal "modified in node version 4", tags[1].v
107 node = nodes(:node_with_versions_v1)
108 tags = OldNode.find(node.id).tags
109 assert_equal 0, tags.size
111 node = nodes(:node_with_versions_v2)
112 tags = OldNode.find(node.id).tags
113 assert_equal 0, tags.size
115 node = nodes(:node_with_versions_v3)
116 tags = OldNode.find(node.id).tags
117 assert_equal 3, tags.size
118 assert_equal "added in node version 3", tags["testing"]
119 assert_equal "added in node version 3", tags["testing two"]
120 assert_equal "added in node version 3", tags["testing three"]
122 node = nodes(:node_with_versions_v4)
123 tags = OldNode.find(node.id).tags
124 assert_equal 2, tags.size
125 assert_equal "added in node version 3", tags["testing"]
126 assert_equal "modified in node version 4", tags["testing two"]