Skip to content
Browse files

Some tests with model configuration included.

  • Loading branch information...
1 parent 5c2cf49 commit d5575e0588258f68fe2a5caf0a44af91f092e22b Anderson Bravalheri committed Jul 21, 2011
Showing with 20 additions and 8 deletions.
  1. +8 −8 test/configuration_test.rb
  2. +12 −0 test/mongoid_test.rb
View
16 test/configuration_test.rb
@@ -72,16 +72,16 @@ def test_geocoder_configuration
# 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
View
12 test/mongoid_test.rb
@@ -28,8 +28,20 @@ def test_custom_coordinate_field_near_scope
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
+

0 comments on commit d5575e0

Please sign in to comment.
Something went wrong with that request. Please try again.