Sha256: d81a94246d5d92497440ec4e263693a033e36c02e7eda68fb079c570f4c79d12

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

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

class MaxmindGeocoderTest < BaseGeocoderTest #:nodoc: all

  def setup
    super
    @ip = '118.210.47.142'
  end

  def test_ip_from_autralia
    location = mock()
    city = mock()
    ::GeoIP.stubs(:new).with(anything).returns(location)
    location.expects(:city).with(@ip).returns(city)
    city.stubs(:latitude).returns(-34.9287)
    city.stubs(:longitude).returns(138.5986)
    city.stubs(:city_name).returns('Adelaide')
    city.stubs(:region_name).returns('Australia')
    city.stubs(:postal_code).returns('')
    city.stubs(:country_code2).returns('AU')

    res = Geokit::Geocoders::MaxmindGeocoder.geocode(@ip)
    assert_equal 'Adelaide', res.city
    assert_equal 'AU', res.country_code
    assert_equal true, res.success
    assert res.city
  end

  def test_ip_from_south_america
    location = mock()
    city = mock()
    ::GeoIP.stubs(:new).with(anything).returns(location)
    location.expects(:city).with(@ip).returns(city)
    city.stubs(:latitude).returns(-34)
    city.stubs(:longitude).returns(-56)
    city.stubs(:city_name).returns('Canelones')
    city.stubs(:region_name).returns('')
    city.stubs(:postal_code).returns('')
    city.stubs(:country_code2).returns('UR')

    res = Geokit::Geocoders::MaxmindGeocoder.geocode(@ip)
    assert_equal 'Canelones', res.city
    assert_equal 'UR', res.country_code
    assert_equal true, res.success
    assert res.city
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
geokit-1.8.5 test/test_maxmind_geocoder.rb
geokit-1.8.4 test/test_maxmind_geocoder.rb
geokit-1.8.3 test/test_maxmind_geocoder.rb
geokit-1.8.2 test/test_maxmind_geocoder.rb
geokit-1.8.1 test/test_maxmind_geocoder.rb
geokit-1.8.0 test/test_maxmind_geocoder.rb