test/configuration_test.rb in geocoder-1.1.5 vs test/configuration_test.rb in geocoder-1.1.6
- old
+ new
@@ -5,73 +5,48 @@
def setup
Geocoder::Configuration.set_defaults
end
def test_exception_raised_on_bad_lookup_config
- Geocoder::Configuration.lookup = :stoopid
+ Geocoder.configure(:lookup => :stoopid)
assert_raises Geocoder::ConfigurationError do
Geocoder.search "something dumb"
end
end
- # --- class method configuration ---
- def test_configurated_by_class_method
- Geocoder::Configuration.units = :mi
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
- assert_not_equal 111, distance
- assert_equal 69, distance
+ def test_setting_with_class_method
+ Geocoder::Configuration.units = :test
+ assert_equal :test, Geocoder.config.units
+ end
- Geocoder::Configuration.units = :km
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
- assert_equal 111, distance
- assert_not_equal 69, distance
-
- Geocoder::Configuration.distances = :spherical
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
- assert_equal 136, angle
- assert_not_equal 130, angle
-
- Geocoder::Configuration.distances = :linear
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
- assert_not_equal 136, angle
- assert_equal 130, angle
+ def test_setting_with_configure_method
+ Geocoder.configure(:units => :test)
+ assert_equal :test, Geocoder.config.units
end
- # --- Geocoder#configure distances configuration ---
- def test_geocoder_configuration
- # DSL
+ def test_setting_with_block_syntax
+ orig = $VERBOSE; $VERBOSE = nil
Geocoder.configure do |config|
- config.units = :mi
- config.distances = :linear
+ config.units = :test
end
+ assert_equal :test, Geocoder.config.units
+ ensure
+ $VERBOSE = orig
+ end
- assert_equal Geocoder::Configuration.units, :mi
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
- assert_not_equal 111, distance
- assert_equal 69, distance
-
- assert_equal Geocoder::Configuration.distances, :linear
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
- assert_not_equal 136, angle
- assert_equal 130, angle
-
- # Direct
- Geocoder.configure.units = :km
- Geocoder.configure.distances = :spherical
-
- assert_equal Geocoder::Configuration.units, :km
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
- assert_equal 111, distance
- assert_not_equal 69, distance
-
- assert_equal Geocoder::Configuration.distances, :spherical
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
- assert_equal 136, angle
- assert_not_equal 130, angle
+ def test_config_for_lookup
+ Geocoder.configure(
+ :timeout => 5,
+ :api_key => "aaa",
+ :google => {
+ :timeout => 2
+ }
+ )
+ assert_equal 2, Geocoder.config_for_lookup(:google).timeout
+ assert_equal "aaa", Geocoder.config_for_lookup(:google).api_key
end
- # Geocoder per-model configuration
def test_model_configuration
Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :km
assert_equal :km, Landmark.geocoder_options[:units]
assert_equal :spherical, Landmark.geocoder_options[:method]
@@ -88,10 +63,10 @@
v = Landmark.new(*landmark_params(:msg))
v.latitude = 0
v.longitude = 0
# method option > global configuration
- Geocoder.configure.units = :km
+ Geocoder.configure(:units => :km)
assert_equal 69, v.distance_to([0,1], :mi).round
# per-model configuration > global configuration
Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :mi
assert_equal 69, v.distance_to([0,1]).round