X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/baf9ff0ec39c13f52ee8d4f087641dc5fcc9c53b..fcc68b4dc198b7cb0cf93467d96038b0844675fe:/vendor/plugins/geokit/test/yahoo_geocoder_test.rb
diff --git a/vendor/plugins/geokit/test/yahoo_geocoder_test.rb b/vendor/plugins/geokit/test/yahoo_geocoder_test.rb
new file mode 100644
index 0000000..abf9a4e
--- /dev/null
+++ b/vendor/plugins/geokit/test/yahoo_geocoder_test.rb
@@ -0,0 +1,87 @@
+require File.join(File.dirname(__FILE__), 'base_geocoder_test')
+
+GeoKit::Geocoders::yahoo = 'Yahoo'
+
+class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
+ YAHOO_FULL=<<-EOF.strip
+
+ 37.792406-122.39411100 SPEAR STSAN FRANCISCOCA94105-1522US
+
+ EOF
+
+ YAHOO_CITY=<<-EOF.strip
+
+ 37.7742-122.417068SAN FRANCISCOCAUS
+
+ EOF
+
+ def setup
+ super
+ @yahoo_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105-1522", :country_code=>"US"}
+ @yahoo_city_hash = {:city=>"San Francisco", :state=>"CA"}
+ @yahoo_full_loc = GeoKit::GeoLoc.new(@yahoo_full_hash)
+ @yahoo_city_loc = GeoKit::GeoLoc.new(@yahoo_city_hash)
+ end
+
+ # the testing methods themselves
+ def test_yahoo_full_address
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_FULL)
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{CGI.escape(@address)}"
+ GeoKit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ do_full_address_assertions(GeoKit::Geocoders::YahooGeocoder.geocode(@address))
+ end
+
+ def test_yahoo_full_address_with_geo_loc
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_FULL)
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{CGI.escape(@full_address)}"
+ GeoKit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ do_full_address_assertions(GeoKit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
+ end
+
+ def test_yahoo_city
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_CITY)
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{CGI.escape(@address)}"
+ GeoKit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ do_city_assertions(GeoKit::Geocoders::YahooGeocoder.geocode(@address))
+ end
+
+ def test_yahoo_city_with_geo_loc
+ response = MockSuccess.new
+ response.expects(:body).returns(YAHOO_CITY)
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{CGI.escape(@address)}"
+ GeoKit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ do_city_assertions(GeoKit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
+ end
+
+ def test_service_unavailable
+ response = MockFailure.new
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{CGI.escape(@address)}"
+ GeoKit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ assert !GeoKit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc).success
+ end
+
+ private
+
+ # next two methods do the assertions for both address-level and city-level lookups
+ def do_full_address_assertions(res)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.792406,-122.39411", res.ll
+ assert res.is_us?
+ assert_equal "100 Spear St, San Francisco, CA, 94105-1522, US", res.full_address
+ assert_equal "yahoo", res.provider
+ end
+
+ def do_city_assertions(res)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.7742,-122.417068", res.ll
+ assert res.is_us?
+ assert_equal "San Francisco, CA, US", res.full_address
+ assert_nil res.street_address
+ assert_equal "yahoo", res.provider
+ end
+end
\ No newline at end of file