1 require File.dirname(__FILE__) + '/../test_helper'
3 class NodeTest < Test::Unit::TestCase
4 fixtures :current_nodes, :users, :current_node_tags, :nodes, :node_tags
5 set_fixture_class :current_nodes => :Node
6 set_fixture_class :nodes => :OldNode
7 set_fixture_class :node_tags => :OldNodeTag
8 set_fixture_class :currenr_node_tags => :NodeTag
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)
50 node = current_nodes(nod)
51 dbnode = Node.find(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.user_id, node.user_id
55 assert_equal dbnode.timestamp, node.timestamp
56 assert_equal dbnode.version, node.version
57 assert_equal dbnode.visible, node.visible
58 #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
62 # This helper method 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)
66 node = current_nodes(nod)
67 dbnode = Node.find(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.user_id, node.user_id
71 assert_equal dbnode.timestamp, node.timestamp
72 assert_equal dbnode.version, node.version
73 assert_equal dbnode.visible, node.visible
74 #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
75 assert_equal false, dbnode.valid?
78 # Check that you can create a node and store it
80 node_template = Node.new(:latitude => 12.3456,
81 :longitude => 65.4321,
82 :user_id => users(:normal_user),
85 assert node_template.save_with_history!
87 node = Node.find(node_template.id)
89 assert_equal node_template.latitude, node.latitude
90 assert_equal node_template.longitude, node.longitude
91 assert_equal node_template.user_id, node.user_id
92 assert_equal node_template.visible, node.visible
93 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
95 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
96 old_node = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
97 assert_not_nil old_node
98 assert_equal node_template.latitude, old_node.latitude
99 assert_equal node_template.longitude, old_node.longitude
100 assert_equal node_template.user_id, old_node.user_id
101 assert_equal node_template.visible, old_node.visible
102 assert_equal node_template.tags, old_node.tags
103 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
107 node_template = Node.find(current_nodes(:visible_node).id)
108 assert_not_nil node_template
110 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
111 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
112 assert_not_nil old_node_template
114 node_template.latitude = 12.3456
115 node_template.longitude = 65.4321
116 #node_template.tags = "updated=yes"
117 assert node_template.save_with_history!
119 node = Node.find(node_template.id)
121 assert_equal node_template.latitude, node.latitude
122 assert_equal node_template.longitude, node.longitude
123 assert_equal node_template.user_id, node.user_id
124 assert_equal node_template.visible, node.visible
125 #assert_equal node_template.tags, node.tags
126 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
128 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
129 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
130 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
131 assert_not_nil old_node
132 assert_equal node_template.latitude, old_node.latitude
133 assert_equal node_template.longitude, old_node.longitude
134 assert_equal node_template.user_id, old_node.user_id
135 assert_equal node_template.visible, old_node.visible
136 #assert_equal node_template.tags, old_node.tags
137 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
141 node_template = Node.find(current_nodes(:visible_node))
142 assert_not_nil node_template
144 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
145 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
146 assert_not_nil old_node_template
148 node_template.visible = 0
149 assert node_template.save_with_history!
151 node = Node.find(node_template.id)
153 assert_equal node_template.latitude, node.latitude
154 assert_equal node_template.longitude, node.longitude
155 assert_equal node_template.user_id, node.user_id
156 assert_equal node_template.visible, node.visible
157 #assert_equal node_template.tags, node.tags
158 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
160 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
161 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
162 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
163 assert_not_nil old_node
164 assert_equal node_template.latitude, old_node.latitude
165 assert_equal node_template.longitude, old_node.longitude
166 assert_equal node_template.user_id, old_node.user_id
167 assert_equal node_template.visible, old_node.visible
168 #assert_equal node_template.tags, old_node.tags
169 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i