From: Shaun McDonald Date: Thu, 3 Jul 2008 10:56:17 +0000 (+0000) Subject: Now all the unit tests work X-Git-Tag: live~7604^2~326 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/0a459023d313ee16f8901da92058c0c2a4b8b9e9?ds=sidebyside Now all the unit tests work --- diff --git a/app/models/geo_record.rb b/app/models/geo_record.rb index ddd029aec..28ee037dd 100644 --- a/app/models/geo_record.rb +++ b/app/models/geo_record.rb @@ -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 diff --git a/config/database.yml b/config/database.yml index 0fbfce319..fe47e11aa 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 diff --git a/test/fixtures/current_nodes.yml b/test/fixtures/current_nodes.yml index 35107d3d9..8fd3b781f 100644 --- a/test/fixtures/current_nodes.yml +++ b/test/fixtures/current_nodes.yml @@ -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 diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index fabd3ac42..d56fed50a 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -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