errors.add_to_base("Node is not in the world") unless in_world?
end
- def in_world?
- return false if self.lat < -90 or self.lat > 90
- return false if self.lon < -180 or self.lon > 180
- return true
- end
-
def self.from_node(node)
old_node = OldNode.new
old_node.latitude = node.latitude
def tags=(t)
@tags = t
- end
+ end
+
def tags_as_hash
hash = {}
Tags.split(self.tags) do |k,v|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<% SCALE = 10000000 unless defined?(SCALE) %>
+
visible_node:
id: 1
latitude: <%= 1*SCALE %>
longitude: <%= 1*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(1,1) %>
timestamp: 2007-01-01 00:00:00
invisible_node:
longitude: <%= 2*SCALE %>
user_id: 1
visible: 0
+ version: 1
+ tile: <%= QuadTile.tile_for_point(2,2) %>
timestamp: 2007-01-01 00:00:00
used_node_1:
longitude: <%= 3*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(3,3) %>
timestamp: 2007-01-01 00:00:00
used_node_2:
longitude: <%= 4*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(4,4) %>
timestamp: 2007-01-01 00:00:00
node_used_by_relationship:
longitude: <%= 5*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(5,5) %>
timestamp: 2007-01-01 00:00:00
node_too_far_north:
latitude: <%= 90.01*SCALE %>
longitude: <%= 6*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(90.01,6) %>
timestamp: 2007-01-01 00:00:00
node_north_limit:
latitude: <%= 90*SCALE %>
longitude: <%= 11*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(90,11) %>
timestamp: 2008-07-08 14:50:00
node_too_far_south:
latitude: <%= -90.01*SCALE %>
longitude: <%= 7*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(-90.01,7) %>
timestamp: 2007-01-01 00:00:00
node_south_limit:
latitude: <%= -90*SCALE %>
longitude: <%= 12*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(-90,12) %>
timestamp: 2008-07-08 15:02:18
node_too_far_west:
latitude: <%= 8*SCALE %>
longitude: <%= -180.01*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(8,-180.01) %>
timestamp: 2007-01-01 00:00:00
node_west_limit:
latitude: <%= 13*SCALE %>
longitude: <%= -180*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(13,-180) %>
timestamp: 2008-07-08 15:17:37
node_too_far_east:
latitude: <%= 9*SCALE %>
longitude: <%= 180.01*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(9,180.01) %>
timestamp: 2007-01-01 00:00:00
node_east_limit:
latitude: <%= 14*SCALE %>
longitude: <%= 180*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(14,180) %>
timestamp: 2008-07-08 15:46:16
node_totally_wrong:
latitude: <%= 200*SCALE %>
longitude: <%= 200*SCALE %>
user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(200,200) %>
timestamp: 2007-01-01 00:00:00
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+<% SCALE = 10000000 unless defined?(SCALE) %>
+
visible_node:
id: 1
latitude: <%= 1*SCALE %>
longitude: <%= 1*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(1,1) %>
timestamp: 2007-01-01 00:00:00
invisible_node:
longitude: <%= 2*SCALE %>
user_id: 1
visible: 0
+ version: 1
+ tile: <%= QuadTile.tile_for_point(2,2) %>
timestamp: 2007-01-01 00:00:00
used_node_1:
longitude: <%= 3*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(3,3) %>
timestamp: 2007-01-01 00:00:00
used_node_2:
longitude: <%= 4*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(4,4) %>
timestamp: 2007-01-01 00:00:00
node_used_by_relationship:
longitude: <%= 5*SCALE %>
user_id: 1
visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(5,5) %>
timestamp: 2007-01-01 00:00:00
+node_too_far_north:
+ id: 6
+ latitude: <%= 90.01*SCALE %>
+ longitude: <%= 6*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(90.01,6) %>
+ timestamp: 2007-01-01 00:00:00
+
+node_north_limit:
+ id: 11
+ latitude: <%= 90*SCALE %>
+ longitude: <%= 11*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(90,11) %>
+ timestamp: 2008-07-08 14:50:00
+
+node_too_far_south:
+ id: 7
+ latitude: <%= -90.01*SCALE %>
+ longitude: <%= 7*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(-90.01,7) %>
+ timestamp: 2007-01-01 00:00:00
+
+node_south_limit:
+ id: 12
+ latitude: <%= -90*SCALE %>
+ longitude: <%= 12*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(-90,12) %>
+ timestamp: 2008-07-08 15:02:18
+
+node_too_far_west:
+ id: 8
+ latitude: <%= 8*SCALE %>
+ longitude: <%= -180.01*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(8,-180.01) %>
+ timestamp: 2007-01-01 00:00:00
+
+node_west_limit:
+ id: 13
+ latitude: <%= 13*SCALE %>
+ longitude: <%= -180*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(13,-180) %>
+ timestamp: 2008-07-08 15:17:37
+
+node_too_far_east:
+ id: 9
+ latitude: <%= 9*SCALE %>
+ longitude: <%= 180.01*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(9,180.01) %>
+ timestamp: 2007-01-01 00:00:00
+
+node_east_limit:
+ id: 14
+ latitude: <%= 14*SCALE %>
+ longitude: <%= 180*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(14,180) %>
+ timestamp: 2008-07-08 15:46:16
+
+node_totally_wrong:
+ id: 10
+ latitude: <%= 200*SCALE %>
+ longitude: <%= 200*SCALE %>
+ user_id: 1
+ visible: 1
+ version: 1
+ tile: <%= QuadTile.tile_for_point(200,200) %>
+ timestamp: 2007-01-01 00:00:00
+
require File.dirname(__FILE__) + '/../test_helper'
class NodeTest < Test::Unit::TestCase
- fixtures :current_nodes, :users, :current_node_tags,:nodes, :node_tags
+ fixtures :current_nodes, :users, :current_node_tags, :nodes, :node_tags
set_fixture_class :current_nodes => :Node
set_fixture_class :nodes => :OldNode
set_fixture_class :node_tags => :OldNodeTag
# the fixture
def valid_node_test(nod)
node = current_nodes(nod)
- assert_equal node.lat, current_nodes(nod).latitude.to_f/SCALE
- assert_equal node.lon, current_nodes(nod).longitude.to_f/SCALE
- assert_equal node.timestamp, current_nodes(nod).timestamp
+ dbnode = Node.find(node.id)
+ assert_equal dbnode.lat, node.latitude.to_f/SCALE
+ assert_equal dbnode.lon, node.longitude.to_f/SCALE
+ assert_equal dbnode.user_id, node.user_id
+ assert_equal dbnode.timestamp, node.timestamp
+ assert_equal dbnode.version, node.version
+ assert_equal dbnode.visible, node.visible
+ #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
assert_valid node
end
- # This helpermethod will check to make sure that a node is outwith the world,
+ # This helper method will check to make sure that a node is outwith the world,
# and has the same lat, lon and timesamp than what was put into the db by the
# fixture
def invalid_node_test(nod)
node = current_nodes(nod)
- assert_equal node.lat, current_nodes(nod).latitude.to_f/SCALE
- assert_equal node.lon, current_nodes(nod).longitude.to_f/SCALE
- assert_equal node.timestamp, current_nodes(nod).timestamp
- assert_equal false, node.valid?
+ dbnode = Node.find(node.id)
+ assert_equal dbnode.lat, node.latitude.to_f/SCALE
+ assert_equal dbnode.lon, node.longitude.to_f/SCALE
+ assert_equal dbnode.user_id, node.user_id
+ assert_equal dbnode.timestamp, node.timestamp
+ assert_equal dbnode.version, node.version
+ assert_equal dbnode.visible, node.visible
+ #assert_equal node.tile, QuadTile.tile_for_point(node.lat, node.lon)
+ assert_equal false, dbnode.valid?
end
# Check that you can create a node and store it
--- /dev/null
+require File.dirname(__FILE__) + '/../test_helper'
+
+class OldNodeTest < Test::Unit::TestCase
+ fixtures :current_nodes, :users, :current_node_tags, :nodes, :node_tags
+ set_fixture_class :current_nodes => :Node
+ set_fixture_class :nodes => :OldNode
+ set_fixture_class :node_tags => :OldNodeTag
+ set_fixture_class :current_node_tags => :NodeTag
+
+ def test_node_too_far_north
+ invalid_node_test(:node_too_far_north)
+ end
+
+ def test_node_north_limit
+ valid_node_test(:node_north_limit)
+ end
+
+ def test_node_too_far_south
+ invalid_node_test(:node_too_far_south)
+ end
+
+ def test_node_south_limit
+ valid_node_test(:node_south_limit)
+ end
+
+ def test_node_too_far_west
+ invalid_node_test(:node_too_far_west)
+ end
+
+ def test_node_west_limit
+ valid_node_test(:node_west_limit)
+ end
+
+ def test_node_too_far_east
+ invalid_node_test(:node_too_far_east)
+ end
+
+ def test_node_east_limit
+ valid_node_test(:node_east_limit)
+ end
+
+ def test_totally_wrong
+ invalid_node_test(:node_totally_wrong)
+ end
+
+ # This helper method will check to make sure that a node is within the world, and
+ # has the the same lat, lon and timestamp than what was put into the db by
+ # the fixture
+ def valid_node_test(nod)
+ node = nodes(nod)
+ dbnode = Node.find(node.id)
+ assert_equal dbnode.lat, node.latitude.to_f/SCALE
+ assert_equal dbnode.lon, node.longitude.to_f/SCALE
+ assert_equal dbnode.user_id, node.user_id
+ assert_equal dbnode.version, node.version
+ assert_equal dbnode.visible, node.visible
+ assert_equal dbnode.timestamp, node.timestamp
+ #assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon)
+ assert_valid node
+ end
+
+ # This helpermethod will check to make sure that a node is outwith the world,
+ # and has the same lat, lon and timesamp than what was put into the db by the
+ # fixture
+ def invalid_node_test(nod)
+ node = nodes(nod)
+ dbnode = Node.find(node.id)
+ assert_equal dbnode.lat, node.latitude.to_f/SCALE
+ assert_equal dbnode.lon, node.longitude.to_f/SCALE
+ assert_equal dbnode.user_id, node.user_id
+ assert_equal dbnode.version, node.version
+ assert_equal dbnode.visible, node.visible
+ assert_equal dbnode.timestamp, node.timestamp
+ #assert_equal node.tile, QuadTile.tile_for_point(nodes(nod).lat, nodes(nod).lon)
+ assert_equal false, node.valid?
+ end
+
+
+end