Sha256: d91ca545953aa0759ffafdfaf699ffa58fd40c51c1ca9a899855816c609e39ae

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

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

Geokit::Geocoders::ip_provider_order=[:geo_plugin,:ip]

class MultiIpGeocoderTest < BaseGeocoderTest #:nodoc: all

  def setup
    @ip_address = '10.10.10.10'
    @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
    @success.success = true
    @failure = Geokit::GeoLoc.new
  end

  def test_successful_first
    Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@success)
    assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
  end

  def test_failover
    Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
    Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address).returns(@success)
    assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
  end

  def test_failure
    Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
    Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address).returns(@failure)
    assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
  end

  def test_invalid_provider
    temp = Geokit::Geocoders::ip_provider_order
    Geokit::Geocoders.ip_provider_order = [:bogus]
    assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
    Geokit::Geocoders.ip_provider_order = temp
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geokit-1.8.5 test/test_multi_ip_geocoder.rb
geokit-1.8.4 test/test_multi_ip_geocoder.rb
geokit-1.8.3 test/test_multi_ip_geocoder.rb