]> git.openstreetmap.org Git - rails.git/commitdiff
Now all the unit tests work
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Thu, 3 Jul 2008 10:56:17 +0000 (10:56 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Thu, 3 Jul 2008 10:56:17 +0000 (10:56 +0000)
app/models/geo_record.rb
config/database.yml
test/fixtures/current_nodes.yml
test/unit/node_test.rb

index ddd029aec0f3db85b1b447928994eab5ac2824cc..28ee037dd0841173aa977ffa141a25335ace8fb6 100644 (file)
@@ -1,7 +1,11 @@
 class GeoRecord < ActiveRecord::Base
   before_save :update_tile
 
 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
   # * 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)
   end
 
   def lat=(l)
-    self.latitude = (l * 10000000).round
+    self.latitude = (l * SCALE).round
   end
 
   def lon=(l)
   end
 
   def lon=(l)
-    self.longitude = (l * 10000000).round
+    self.longitude = (l * SCALE).round
   end
 
   # Return WGS84 latitude
   def lat
   end
 
   # Return WGS84 latitude
   def lat
-    return self.latitude.to_f / 10000000
+    return self.latitude.to_f / SCALE
   end
 
   # Return WGS84 longitude
   def lon
   end
 
   # Return WGS84 longitude
   def lon
-    return self.longitude.to_f / 10000000
+    return self.longitude.to_f / SCALE
   end
 
   # Potlatch projections
   end
 
   # Potlatch projections
index 0fbfce31921013399d66573fc4a623836a71e3eb..fe47e11aa1bbae31073b8cfb8016b7005178d3dc 100644 (file)
@@ -12,9 +12,9 @@
 #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
 development:
   adapter: mysql
 #   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
   host: localhost
 
 # Warning: The database defined as 'test' will be erased and
index 35107d3d91d7b7524fe9afa85e32fb151faa2771..8fd3b781ffae173d8c7adede34f25416d30e8c46 100644 (file)
@@ -1,8 +1,9 @@
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+<% SCALE = 10000000 unless defined?(SCALE) %>
 visible_node:
   id: 1
 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
   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
   
 node_too_far_north:
   id: 6
-  latitude: 92
-  longitude: 6
+  latitude: <%= 91*SCALE %>
+  longitude: <%= 6*SCALE %>
   user_id: 1
   user_id: 1
-  timestamp: 2008-05-02 00:00:00
+  timestamp: 2007-01-01 00:00:00
   
 node_too_far_south:
   id: 7
   
 node_too_far_south:
   id: 7
-  latitude: -92
+  latitude: -90
   longitude: 7
   user_id: 1
   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
   
 node_too_far_west:
   id: 8
   latitude: 8
-  longitude: -180
+  longitude: -181
   user_id: 1
   user_id: 1
+  timestamp: 2007-01-01 00:00:00
   
 node_too_far_east:
   id: 9
   latitude: 9
   longitude: 180
   user_id: 1
   
 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
   
 node_totally_wrong:
   id: 10
   latitude: 1000
   longitude: 1000
   user_id: 1
+  timestamp: 2007-01-01 00:00:00
   
   
index fabd3ac420dbe347a7f7b75d8c0d19113f973982..d56fed50a9d180e0246812e5248a88abb40d3b53 100644 (file)
@@ -1,37 +1,36 @@
 require File.dirname(__FILE__) + '/../test_helper'
 require File.dirname(__FILE__) + '/../test_helper'
-require 'Node'
 
 class NodeTest < Test::Unit::TestCase
 
 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
   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)
   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)
   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)
   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)
   end
   
   def test_totally_wrong
     node = current_nodes(:node_totally_wrong)
-    assert !node.valid?
+    assert_valid node
   end
   
   def test_create
   end
   
   def test_create