diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 3381fb183137bd2d39f7109623c694efa71f446d..75e7c1b37aaad0c1922dce9d25aed6dc950f0fdd 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -38,20 +38,21 @@ module Geocoder end # define getters and setters for all configuration settings - self.options_and_defaults.each do |o,d| - eval("def self.#{o}; @@#{o}; end") - eval("def self.#{o}=(obj); @@#{o} = obj; end") + self.options_and_defaults.each do |option, default| + class_eval(<<-END, __FILE__, __LINE__ + 1) + + @@#{option} = default unless defined? @@#{option} + + def self.#{option} + @@#{option} + end + + def self.#{option}=(obj) + @@#{option} = obj + end + + END end - ## - # Set all values to default. - # - def self.set_defaults - self.options_and_defaults.each do |o,d| - self.send("#{o}=", d) - end - end end -end - -Geocoder::Configuration.set_defaults +end \ No newline at end of file diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 61593c6b5730f832ef8f24384fd365021fe46f92..cece36b74bdcc566fca9094c7e0dcd377238ce7f 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -9,4 +9,5 @@ class ConfigurationTest < Test::Unit::TestCase Geocoder.search "something dumb" end end + end diff --git a/test/custom_block_test.rb b/test/custom_block_test.rb index ab2ad9e005b80896370271a2553cac770c263d64..8fab62e819aa6ff05a1b706e185ab7aba92008fc 100644 --- a/test/custom_block_test.rb +++ b/test/custom_block_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class CustomBlockTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_geocode_with_block_runs_block e = Event.new(*venue_params(:msg)) coords = [40.750354, -73.993371] diff --git a/test/error_handling_test.rb b/test/error_handling_test.rb index e60c7b394eb2752f9d0aec58d886652bd5ace483..134e05a67e40871628fa1333af69a0f288578be0 100644 --- a/test/error_handling_test.rb +++ b/test/error_handling_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ErrorHandlingTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_does_not_choke_on_timeout # keep test output clean: suppress timeout warning orig = $VERBOSE; $VERBOSE = nil diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 2a0b02461f9e71268e47cc03814a7417ac1c7ae0..fe1682004ef4c537d7d6882e320c3c4b40d680a5 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class GeocoderTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_distance_to_returns_float v = Venue.new(*venue_params(:msg)) v.latitude, v.longitude = [40.750354, -73.993371] diff --git a/test/https_test.rb b/test/https_test.rb index acba01e68a5f6428581c7b2bc650b5a5d3807273..58219d33cc8f013746583b0d20a699e93b534ad8 100644 --- a/test/https_test.rb +++ b/test/https_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class HttpsTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_uses_https_for_secure_query Geocoder::Configuration.use_https = true g = Geocoder::Lookup::Google.new diff --git a/test/method_aliases_test.rb b/test/method_aliases_test.rb index f44c3478487de0617ad043485d4cb20918218bd9..993e96769bb3a1bbf307f6abe9e25208fb115673 100644 --- a/test/method_aliases_test.rb +++ b/test/method_aliases_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class MethodAliasesTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_distance_from_is_alias_for_distance_to v = Venue.new(*venue_params(:msg)) v.latitude, v.longitude = [40.750354, -73.993371] diff --git a/test/mongoid_test.rb b/test/mongoid_test.rb index c4fb8ae07251f61f3c52480838b308c5ed9e3e36..44b4ca9a0798538974177cfb79332657d9908e3b 100644 --- a/test/mongoid_test.rb +++ b/test/mongoid_test.rb @@ -7,10 +7,6 @@ require 'mongoid_test_helper' class MongoidTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_geocoded_check p = Place.new(*venue_params(:msg)) p.location = [40.750354, -73.993371] diff --git a/test/proxy_test.rb b/test/proxy_test.rb index fe4236050ff6c986e3c3e0ea49fde232bc569880..d701fdce39d2663d5732379676d6960e2268c796 100644 --- a/test/proxy_test.rb +++ b/test/proxy_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ProxyTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - def test_uses_proxy_when_specified Geocoder::Configuration.http_proxy = 'localhost' lookup = Geocoder::Lookup::Google.new diff --git a/test/services_test.rb b/test/services_test.rb index 5eb7555c7dd313bc8021c335baa0008217decec3..33941b307fd55226f19dc0c5fc95a3b4f804d49e 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -3,10 +3,6 @@ require 'test_helper' class ServicesTest < Test::Unit::TestCase - def setup - Geocoder::Configuration.set_defaults - end - # --- Google --- diff --git a/test/test_helper.rb b/test/test_helper.rb index f491504aaed96ec1748d11ce86f3640fa1a395cf..bbe1a1489f3c3710893187cc71f8731d88fa36ce 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -224,6 +224,12 @@ end class Test::Unit::TestCase + + def teardown + Geocoder.send(:remove_const, :Configuration) + load "geocoder/configuration.rb" + end + def venue_params(abbrev) { :msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]