Sha256: bfbece0d8a48ae786ff3869d03cfa37dc76a30f27b43185c670c19a11d7e8330

Contents?: true

Size: 1.47 KB

Versions: 30

Compression:

Stored size: 1.47 KB

Contents

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

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

30 entries across 30 versions & 15 rubygems

Version Path
Pr0d1r2-geokit-1.4.1 test/test_multi_ip_geocoder.rb
andre-geokit-1.4.0 test/test_multi_ip_geocoder.rb
andre-geokit-1.4.1 test/test_multi_ip_geocoder.rb
andre-geokit-1.5.0 test/test_multi_ip_geocoder.rb
darrell-geokit-1.4.1.1 test/test_multi_ip_geocoder.rb
drogus-geokit-1.4.2 test/test_multi_ip_geocoder.rb
flowers-geokit-1.4.1 test/test_multi_ip_geocoder.rb
mussegam-geokit-1.4.1 test/test_multi_ip_geocoder.rb
geokit-premier-0.1.0 test/test_multi_ip_geocoder.rb
geokit-premier-0.0.7 test/test_multi_ip_geocoder.rb
geokit-with-google-premier-1.5.5 test/test_multi_ip_geocoder.rb
geokit-with-google-premier-1.5.0 test/test_multi_ip_geocoder.rb
geokit-with-premier-support-1.5.0 test/test_multi_ip_geocoder.rb
geokit-1.6.0 test/test_multi_ip_geocoder.rb
rjaswal-geokit-1.5.1 test/test_multi_ip_geocoder.rb
rjaswal-geokit-1.5.0.2 test/test_multi_ip_geocoder.rb
geokit-premier-0.0.5 test/test_multi_ip_geocoder.rb
geokit-premier-0.0.4 test/test_multi_ip_geocoder.rb
badnaam-geokit-1.5.1 test/test_multi_ip_geocoder.rb
badnaam-geokit-1.5.0 test/test_multi_ip_geocoder.rb