Sha256: 174ada10b58dc536226a1aed4c8e503597264b8df7c7e87917b97b360c763381

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

require File.join(File.dirname(__FILE__), 'test_base_geocoder')

Geokit::Geocoders::geocoder_us = nil

class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
  
  GEOCODER_US_FULL='37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'  
  
  def setup
    super
    @us_full_hash = {:city=>"San Francisco", :state=>"CA"}
    @us_full_loc = Geokit::GeoLoc.new(@us_full_hash)
  end  
  
  def test_geocoder_us
    response = MockSuccess.new
    response.expects(:body).returns(GEOCODER_US_FULL)
    url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
    Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
    verify(Geokit::Geocoders::UsGeocoder.geocode(@address))
  end
  
  def test_geocoder_with_geo_loc
    response = MockSuccess.new
    response.expects(:body).returns(GEOCODER_US_FULL)
    url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
    Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
    verify(Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc))    
  end
  
  def test_service_unavailable
    response = MockFailure.new
    url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
    Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
    assert !Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc).success   
  end  
  
  private
  
  def verify(location)
    assert_equal "CA", location.state
    assert_equal "San Francisco", location.city 
    assert_equal "37.792528,-122.393981", location.ll 
    assert location.is_us?
    assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address  #slightly different from yahoo    
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
andre-geokit-1.1.0 test/test_us_geocoder.rb
andre-geokit-1.2.0 test/test_us_geocoder.rb
andre-geokit-1.2.1 test/test_us_geocoder.rb
andre-geokit-1.2.2 test/test_us_geocoder.rb
andre-geokit-1.2.3 test/test_us_geocoder.rb
soey-geokit-1.2.4 test/test_us_geocoder.rb