X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/baf9ff0ec39c13f52ee8d4f087641dc5fcc9c53b..fcc68b4dc198b7cb0cf93467d96038b0844675fe:/vendor/plugins/geokit/test/google_geocoder_test.rb
diff --git a/vendor/plugins/geokit/test/google_geocoder_test.rb b/vendor/plugins/geokit/test/google_geocoder_test.rb
new file mode 100644
index 0000000..dfa8a0c
--- /dev/null
+++ b/vendor/plugins/geokit/test/google_geocoder_test.rb
@@ -0,0 +1,88 @@
+require File.join(File.dirname(__FILE__), 'base_geocoder_test')
+
+GeoKit::Geocoders::google = 'Google'
+
+class GoogleGeocoderTest < BaseGeocoderTest #:nodoc: all
+
+ GOOGLE_FULL=<<-EOF.strip
+ 100 spear st, san francisco, ca200
geocode100 Spear St, San Francisco, CA 94105, USAUSCASan FranciscoSan Francisco100 Spear St94105-122.393985,37.792501,0
+ EOF
+
+ GOOGLE_CITY=<<-EOF.strip
+ San Francisco200
geocodeSan Francisco, CA, USAUSCASan Francisco-122.418333,37.775000,0
+ EOF
+
+ def setup
+ super
+ @google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
+ @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
+
+ @google_full_loc = GeoKit::GeoLoc.new(@google_full_hash)
+ @google_city_loc = GeoKit::GeoLoc.new(@google_city_hash)
+ end
+
+ def test_google_full_address
+ response = MockSuccess.new
+ response.expects(:body).returns(GOOGLE_FULL)
+ url = "http://maps.google.com/maps/geo?q=#{CGI.escape(@address)}&output=xml&key=Google&oe=utf-8"
+ GeoKit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res=GeoKit::Geocoders::GoogleGeocoder.geocode(@address)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
+ assert res.is_us?
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
+ assert_equal "google", res.provider
+ end
+
+ def test_google_full_address_with_geo_loc
+ response = MockSuccess.new
+ response.expects(:body).returns(GOOGLE_FULL)
+ url = "http://maps.google.com/maps/geo?q=#{CGI.escape(@full_address_short_zip)}&output=xml&key=Google&oe=utf-8"
+ GeoKit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res=GeoKit::Geocoders::GoogleGeocoder.geocode(@google_full_loc)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.792501,-122.393985", res.ll # slightly dif from yahoo
+ assert res.is_us?
+ assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
+ assert_equal "google", res.provider
+ end
+
+ def test_google_city
+ response = MockSuccess.new
+ response.expects(:body).returns(GOOGLE_CITY)
+ url = "http://maps.google.com/maps/geo?q=#{CGI.escape(@address)}&output=xml&key=Google&oe=utf-8"
+ GeoKit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res=GeoKit::Geocoders::GoogleGeocoder.geocode(@address)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.775,-122.418333", res.ll
+ assert res.is_us?
+ assert_equal "San Francisco, CA, USA", res.full_address
+ assert_nil res.street_address
+ assert_equal "google", res.provider
+ end
+
+ def test_google_city_with_geo_loc
+ response = MockSuccess.new
+ response.expects(:body).returns(GOOGLE_CITY)
+ url = "http://maps.google.com/maps/geo?q=#{CGI.escape(@address)}&output=xml&key=Google&oe=utf-8"
+ GeoKit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ res=GeoKit::Geocoders::GoogleGeocoder.geocode(@google_city_loc)
+ assert_equal "CA", res.state
+ assert_equal "San Francisco", res.city
+ assert_equal "37.775,-122.418333", res.ll
+ assert res.is_us?
+ assert_equal "San Francisco, CA, USA", res.full_address
+ assert_nil res.street_address
+ assert_equal "google", res.provider
+ end
+
+ def test_service_unavailable
+ response = MockFailure.new
+ url = "http://maps.google.com/maps/geo?q=#{CGI.escape(@address)}&output=xml&key=Google&oe=utf-8"
+ GeoKit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
+ assert !GeoKit::Geocoders::GoogleGeocoder.geocode(@google_city_loc).success
+ end
+end
\ No newline at end of file