]> projects.mako.cc - selectricity-live/blob - vendor/plugins/geokit/test/us_geocoder_test.rb
* Validate that quickvote.name is not nil
[selectricity-live] / vendor / plugins / geokit / test / us_geocoder_test.rb
1 require File.join(File.dirname(__FILE__), 'base_geocoder_test')
2
3 GeoKit::Geocoders::geocoder_us = nil
4
5 class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
6   
7   GEOCODER_US_FULL='37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'  
8   
9   def setup
10     super
11     @us_full_hash = {:city=>"San Francisco", :state=>"CA"}
12     @us_full_loc = GeoKit::GeoLoc.new(@us_full_hash)
13   end  
14   
15   def test_geocoder_us
16     response = MockSuccess.new
17     response.expects(:body).returns(GEOCODER_US_FULL)
18     url = "http://geocoder.us/service/csv/geocode?address=#{CGI.escape(@address)}"
19     GeoKit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
20     verify(GeoKit::Geocoders::UsGeocoder.geocode(@address))
21   end
22   
23   def test_geocoder_with_geo_loc
24     response = MockSuccess.new
25     response.expects(:body).returns(GEOCODER_US_FULL)
26     url = "http://geocoder.us/service/csv/geocode?address=#{CGI.escape(@address)}"
27     GeoKit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
28     verify(GeoKit::Geocoders::UsGeocoder.geocode(@us_full_loc))    
29   end
30   
31   def test_service_unavailable
32     response = MockFailure.new
33     url = "http://geocoder.us/service/csv/geocode?address=#{CGI.escape(@address)}"
34     GeoKit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
35     assert !GeoKit::Geocoders::UsGeocoder.geocode(@us_full_loc).success   
36   end  
37   
38   private
39   
40   def verify(location)
41     assert_equal "CA", location.state
42     assert_equal "San Francisco", location.city 
43     assert_equal "37.792528,-122.393981", location.ll 
44     assert location.is_us?
45     assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address  #slightly different from yahoo    
46   end
47 end

Benjamin Mako Hill || Want to submit a patch?