From 0f9c3847b9e1585e6ff46a945df0bc7e6028b21c Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Sun, 6 Mar 2011 22:08:24 -0500 Subject: [PATCH] Set config options properly. If forward and reverse geocoding were both declared and options passed for both, only the options for the first were being set. --- lib/geocoder/railtie.rb | 3 ++- test/geocoder_test.rb | 12 ++++++++++++ test/test_helper.rb | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/geocoder/railtie.rb b/lib/geocoder/railtie.rb index 40a683f9..1e2eeef2 100644 --- a/lib/geocoder/railtie.rb +++ b/lib/geocoder/railtie.rb @@ -60,10 +60,11 @@ module Geocoder def geocoder_init(options) unless geocoder_initialized? - @geocoder_options = options + @geocoder_options = {} require 'geocoder/orms/active_record' include Geocoder::Orm::ActiveRecord end + @geocoder_options.merge! options end def geocoder_initialized? diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 88a93ea4..01cbf011 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -69,6 +69,18 @@ class GeocoderTest < Test::Unit::TestCase assert_equal "US", e.country end + def test_fetch_forward_and_reverse_geocoding_on_same_model + g = GasStation.new("Exxon") + g.address = "404 New St, Middletown, CT" + g.fetch_coordinates + assert_not_nil g.lat + assert_not_nil g.lon + + assert_nil g.location + g.fetch_address + assert_not_nil g.location + end + # --- Google --- diff --git a/test/test_helper.rb b/test/test_helper.rb index 569b8b28..865ee7c2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -132,6 +132,20 @@ class Party < ActiveRecord::Base end end +## +# Forward and reverse geocoded model. +# Should fill in whatever's missing (coords or address). +# +class GasStation < ActiveRecord::Base + geocoded_by :address, :latitude => :lat, :longitude => :lon + reverse_geocoded_by :lat, :lon, :address => :location + + def initialize(name) + super() + write_attribute :name, name + end +end + class Test::Unit::TestCase def venue_params(abbrev) -- GitLab