Sha256: 34011bc46d7a4354bd68a15329085e64de7b83707dd3379083924430390bb798

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

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

class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
  GEOCODER_US_FULL = '37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'

  def setup
    geocoder_class.key = nil
    super
    @us_full_hash = {city: 'San Francisco', state: 'CA'}
    @us_full_loc = Geokit::GeoLoc.new(@us_full_hash)
    @base_url = 'http://geocoder.us/service/csv/geocode'
  end

  def test_geocoder_us
    response = MockSuccess.new
    response.expects(:body).returns(GEOCODER_US_FULL)
    url = "#{@base_url}?address=#{escape(@address)}"
    geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
    verify(geocode(@address))
  end

  def test_geocoder_with_geo_loc
    response = MockSuccess.new
    response.expects(:body).returns(GEOCODER_US_FULL)
    url = "#{@base_url}?address=#{escape(@address)}"
    geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
    verify(geocode(@us_full_loc))
  end

  def test_service_unavailable
    response = MockFailure.new
    url = "#{@base_url}?address=#{escape(@address)}"
    geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
    assert !geocode(@us_full_loc).success
  end

  def test_all_method
    response = MockSuccess.new
    response.expects(:body).returns(GEOCODER_US_FULL)
    url = "#{@base_url}?address=#{escape(@address)}"
    geocoder_class.expects(:call_geocoder_service).with(url).returns(response)
    res = geocode(@address)
    assert_equal 1, res.all.size
  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

5 entries across 5 versions & 1 rubygems

Version Path
geokit-1.14.0 test/test_us_geocoder.rb
geokit-1.13.1 test/test_us_geocoder.rb
geokit-1.13.0 test/test_us_geocoder.rb
geokit-1.12.0 test/test_us_geocoder.rb
geokit-1.11.0 test/test_us_geocoder.rb