1 require File.dirname(__FILE__) + '/../test_helper'
3 class NodeTest < Test::Unit::TestCase
6 def test_node_too_far_north
7 invalid_node_test(:node_too_far_north)
10 def test_node_north_limit
11 valid_node_test(:node_north_limit)
14 def test_node_too_far_south
15 invalid_node_test(:node_too_far_south)
18 def test_node_south_limit
19 valid_node_test(:node_south_limit)
22 def test_node_too_far_west
23 invalid_node_test(:node_too_far_west)
26 def test_node_west_limit
27 valid_node_test(:node_west_limit)
30 def test_node_too_far_east
31 invalid_node_test(:node_too_far_east)
34 def test_node_east_limit
35 valid_node_test(:node_east_limit)
38 def test_totally_wrong
39 invalid_node_test(:node_totally_wrong)
42 # This helper method will check to make sure that a node is within the world, and
43 # has the the same lat, lon and timestamp than what was put into the db by
45 def valid_node_test(nod)
46 node = current_nodes(nod)
47 dbnode = Node.find(node.id)
48 assert_equal dbnode.lat, node.latitude.to_f/SCALE
49 assert_equal dbnode.lon, node.longitude.to_f/SCALE
50 assert_equal dbnode.changeset_id, node.changeset_id
51 assert_equal dbnode.timestamp, node.timestamp
52 assert_equal dbnode.version, node.version
53 assert_equal dbnode.visible, node.visible
54 #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
58 # This helper method will check to make sure that a node is outwith the world,
59 # and has the same lat, lon and timesamp than what was put into the db by the
61 def invalid_node_test(nod)
62 node = current_nodes(nod)
63 dbnode = Node.find(node.id)
64 assert_equal dbnode.lat, node.latitude.to_f/SCALE
65 assert_equal dbnode.lon, node.longitude.to_f/SCALE
66 assert_equal dbnode.changeset_id, node.changeset_id
67 assert_equal dbnode.timestamp, node.timestamp
68 assert_equal dbnode.version, node.version
69 assert_equal dbnode.visible, node.visible
70 #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
71 assert_equal false, dbnode.valid?
74 # Check that you can create a node and store it
76 node_template = Node.new(:latitude => 12.3456,
77 :longitude => 65.4321,
78 :changeset_id => changesets(:normal_user_first_change).id,
81 assert node_template.create_with_history(users(:normal_user))
83 node = Node.find(node_template.id)
85 assert_equal node_template.latitude, node.latitude
86 assert_equal node_template.longitude, node.longitude
87 assert_equal node_template.changeset_id, node.changeset_id
88 assert_equal node_template.visible, node.visible
89 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
91 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
92 old_node = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
93 assert_not_nil old_node
94 assert_equal node_template.latitude, old_node.latitude
95 assert_equal node_template.longitude, old_node.longitude
96 assert_equal node_template.changeset_id, old_node.changeset_id
97 assert_equal node_template.visible, old_node.visible
98 assert_equal node_template.tags, old_node.tags
99 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
103 node_template = Node.find(current_nodes(:visible_node).id)
104 assert_not_nil node_template
106 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
107 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
108 assert_not_nil old_node_template
110 node_template.latitude = 12.3456
111 node_template.longitude = 65.4321
112 #node_template.tags = "updated=yes"
113 assert node_template.update_from(old_node_template, users(:normal_user))
115 node = Node.find(node_template.id)
117 assert_equal node_template.latitude, node.latitude
118 assert_equal node_template.longitude, node.longitude
119 assert_equal node_template.changeset_id, node.changeset_id
120 assert_equal node_template.visible, node.visible
121 #assert_equal node_template.tags, node.tags
122 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
124 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
125 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
126 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
127 assert_not_nil old_node
128 assert_equal node_template.latitude, old_node.latitude
129 assert_equal node_template.longitude, old_node.longitude
130 assert_equal node_template.changeset_id, old_node.changeset_id
131 assert_equal node_template.visible, old_node.visible
132 #assert_equal node_template.tags, old_node.tags
133 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i
137 node_template = Node.find(current_nodes(:visible_node))
138 assert_not_nil node_template
140 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 1
141 old_node_template = OldNode.find(:first, :conditions => [ "id = ?", node_template.id ])
142 assert_not_nil old_node_template
144 assert node_template.delete_with_history!(old_node_template, users(:normal_user))
146 node = Node.find(node_template.id)
148 assert_equal node_template.latitude, node.latitude
149 assert_equal node_template.longitude, node.longitude
150 assert_equal node_template.changeset_id, node.changeset_id
151 assert_equal node_template.visible, node.visible
152 #assert_equal node_template.tags, node.tags
153 assert_equal node_template.timestamp.to_i, node.timestamp.to_i
155 assert_equal OldNode.find(:all, :conditions => [ "id = ?", node_template.id ]).length, 2
156 assert_equal OldNode.find(:all, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ]).length, 1
157 old_node = OldNode.find(:first, :conditions => [ "id = ? and timestamp = ?", node_template.id, node_template.timestamp ])
158 assert_not_nil old_node
159 assert_equal node_template.latitude, old_node.latitude
160 assert_equal node_template.longitude, old_node.longitude
161 assert_equal node_template.changeset_id, old_node.changeset_id
162 assert_equal node_template.visible, old_node.visible
163 #assert_equal node_template.tags, old_node.tags
164 assert_equal node_template.timestamp.to_i, old_node.timestamp.to_i