From 9e818710010af1b433f4981d04c1443d6b42be12 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 6 Mar 2011 01:10:42 -0500 Subject: [PATCH] Add distance_from as alias for distance_to. --- lib/geocoder/orms/base.rb | 2 ++ test/geocoder_test.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/geocoder/orms/base.rb b/lib/geocoder/orms/base.rb index e72a9687..473955c6 100644 --- a/lib/geocoder/orms/base.rb +++ b/lib/geocoder/orms/base.rb @@ -20,6 +20,8 @@ module Geocoder Geocoder::Calculations.distance_between(mylat, mylon, lat, lon, :units => units) end + alias_method :distance_from, :distance_to + ## # Get other geocoded objects within a given radius. # diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 34fa5c4c..9e92d068 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -57,6 +57,15 @@ class GeocoderTest < Test::Unit::TestCase assert_equal "US", e.country end + def test_distance_to_returns_float + v = Venue.new(*venue_params(:msg)) + v.latitude = 40.750354 + v.longitude = -73.993371 + assert (d = v.distance_to(30, -94)).is_a?(Float) + # make sure distance_from is an alias + assert_equal d, v.distance_from(30, -94) + end + # --- Google --- -- GitLab