From d5575e0588258f68fe2a5caf0a44af91f092e22b Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri <andersonbravalheri@gmail.com> Date: Thu, 21 Jul 2011 01:37:35 -0300 Subject: [PATCH] Some tests with model configuration included. --- test/configuration_test.rb | 16 ++++++++-------- test/mongoid_test.rb | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 598d0637..37171aee 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -72,16 +72,16 @@ class ConfigurationTest < Test::Unit::TestCase # Geocoder per-model configuration def test_model_configuration Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :km - assert_equal Landmark.geocoder_options[:units], :km + assert_equal :km, Landmark.geocoder_options[:units] assert_equal :spherical, Landmark.geocoder_options[:method] - venue = Landmark.new(*landmark_params(:msg)) - venue.latitude = 0 - venue.longitude = 0 - assert_equal 111, venue.distance_to([0,1]).round - venue.latitude = 40.750354 - venue.longitude = -73.993371 - assert_equal 136, venue.bearing_from([50,-85]).round + v = Landmark.new(*landmark_params(:msg)) + v.latitude = 0 + v.longitude = 0 + assert_equal 111, v.distance_to([0,1]).round + v.latitude = 40.750354 + v.longitude = -73.993371 + assert_equal 136, v.bearing_from([50,-85]).round end end diff --git a/test/mongoid_test.rb b/test/mongoid_test.rb index c4fb8ae0..7b8f4147 100644 --- a/test/mongoid_test.rb +++ b/test/mongoid_test.rb @@ -28,8 +28,20 @@ class MongoidTest < Test::Unit::TestCase p = Place.near(location) assert_equal p.selector[:location]['$nearSphere'], location.reverse end + + def test_model_configuration + p = Place.new(*venue_params(:msg)) + p.location = [0, 0] + + Place.geocoded_by :address, :coordinates => :location, :units => :km + assert_equal 111, p.distance_to([0,1]).round + + Place.geocoded_by :address, :coordinates => :location, :units => :mi + assert_equal 69, p.distance_to([0,1]).round + end end rescue LoadError => crash warn 'Mongoid not installed, not tested.' end + -- GitLab