diff --git a/lib/geocoder/railtie.rb b/lib/geocoder/railtie.rb index 40a683f9b2b292bef20d042ae110d8488deeddf6..1e2eeef2ae854010d58e76390d3c5af8eaec2a7d 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 88a93ea45c71b5b668c427fc69004e62ad114f42..01cbf01147e40a0ebc7c5e506982c20164248f1a 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 569b8b283b75b2261bd4f5d0e3a7a4fa6475c4f4..865ee7c252a2059190de5eeed9558c5549ec1e68 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)