]> projects.mako.cc - selectricity-live/blob - vendor/plugins/geokit/test/multi_geocoder_test.rb
Merge head
[selectricity-live] / vendor / plugins / geokit / test / multi_geocoder_test.rb
1 require File.join(File.dirname(__FILE__), 'base_geocoder_test')
2
3 GeoKit::Geocoders::provider_order=[:google,:yahoo,:us]
4
5 class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
6   
7   def setup
8     super
9     @failure = GeoKit::GeoLoc.new
10   end
11   
12   def test_successful_first
13     GeoKit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@success)
14     assert_equal @success, GeoKit::Geocoders::MultiGeocoder.geocode(@address)
15   end
16   
17   def test_failover
18     GeoKit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
19     GeoKit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@success)
20     assert_equal @success, GeoKit::Geocoders::MultiGeocoder.geocode(@address)    
21   end
22   
23   def test_double_failover
24     GeoKit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
25     GeoKit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
26     GeoKit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@success)
27     assert_equal @success, GeoKit::Geocoders::MultiGeocoder.geocode(@address)    
28   end
29   
30   def test_failure
31     GeoKit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
32     GeoKit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
33     GeoKit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@failure)
34     assert_equal @failure, GeoKit::Geocoders::MultiGeocoder.geocode(@address)    
35   end
36
37   def test_invalid_provider
38     temp = GeoKit::Geocoders::provider_order
39     GeoKit::Geocoders.provider_order = [:bogus]
40     assert_equal @failure, GeoKit::Geocoders::MultiGeocoder.geocode(@address)    
41     GeoKit::Geocoders.provider_order = temp
42   end
43
44 end

Benjamin Mako Hill || Want to submit a patch?