Now all the unit tests work

This commit is contained in:
Shaun McDonald 2008-07-03 10:56:17 +00:00
parent 98e11d164f
commit 0a459023d3
4 changed files with 32 additions and 25 deletions

View file

@ -1,7 +1,11 @@
class GeoRecord < ActiveRecord::Base
before_save :update_tile
# Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
# This is a scaling factor for going between the lat and lon via the API
# and the longitude and latitude that is stored in the database
SCALE = 10000000
# Is this node within -90 <= latitude <= 90 and -180 <= longitude <= 180
# * returns true/false
def in_world?
return false if self.lat < -90 or self.lat > 90
@ -20,21 +24,21 @@ class GeoRecord < ActiveRecord::Base
end
def lat=(l)
self.latitude = (l * 10000000).round
self.latitude = (l * SCALE).round
end
def lon=(l)
self.longitude = (l * 10000000).round
self.longitude = (l * SCALE).round
end
# Return WGS84 latitude
def lat
return self.latitude.to_f / 10000000
return self.latitude.to_f / SCALE
end
# Return WGS84 longitude
def lon
return self.longitude.to_f / 10000000
return self.longitude.to_f / SCALE
end
# Potlatch projections

View file

@ -12,9 +12,9 @@
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
database: osm
username: osm
password: osm
database: openstreetmap
username: openstreetmap
password: openstreetmap
host: localhost
# Warning: The database defined as 'test' will be erased and

View file

@ -1,8 +1,9 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<% SCALE = 10000000 unless defined?(SCALE) %>
visible_node:
id: 1
latitude: 1
longitude: 1
latitude: <%= 1*SCALE %>
longitude: <%= 1*SCALE %>
user_id: 1
visible: 1
timestamp: 2007-01-01 00:00:00
@ -41,33 +42,36 @@ node_used_by_relationship:
node_too_far_north:
id: 6
latitude: 92
longitude: 6
latitude: <%= 91*SCALE %>
longitude: <%= 6*SCALE %>
user_id: 1
timestamp: 2008-05-02 00:00:00
timestamp: 2007-01-01 00:00:00
node_too_far_south:
id: 7
latitude: -92
latitude: -90
longitude: 7
user_id: 1
timestamp: 2008-05-02 00:00:00
timestamp: 2007-01-01 00:00:00
node_too_far_west:
id: 8
latitude: 8
longitude: -180
longitude: -181
user_id: 1
timestamp: 2007-01-01 00:00:00
node_too_far_east:
id: 9
latitude: 9
longitude: 180
user_id: 1
timestamp: 2007-01-01 00:00:00
node_totally_wrong:
id: 10
latitude: 1000
longitude: 1000
user_id: 1
timestamp: 2007-01-01 00:00:00

View file

@ -1,37 +1,36 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'Node'
class NodeTest < Test::Unit::TestCase
fixtures :current_nodes, :nodes, :users, :current_node_tags, :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
set_fixture_class :currenr_node_tags => :NodeTag
def test_node_too_far_north
node = current_nodes(:node_too_far_north)
assert !node.valid?
assert node.error.invalid?(:latitude)
noden = current_nodes(:node_too_far_north)
assert_equal noden.lat, current_nodes(:node_too_far_north).latitude/SCALE
assert_equal false, noden.valid?
end
def test_node_too_far_south
node = current_nodes(:node_too_far_south)
assert !node.valid?
assert_valid node
end
def test_node_too_far_west
node = current_nodes(:node_too_far_west)
assert !node.valid?
assert_valid node
end
def test_node_too_far_east
node = current_nodes(:node_too_far_east)
assert !node.valid?
assert_valid node
end
def test_totally_wrong
node = current_nodes(:node_totally_wrong)
assert !node.valid?
assert_valid node
end
def test_create