1 require File.join(File.dirname(__FILE__), 'base_geocoder_test')
3 class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
6 Country: (Private Address) (XX)
7 City: (Private Address)
13 Country: UNITED STATES (US)
28 @success.provider = "hostip"
31 def test_successful_lookup
32 success = MockSuccess.new
33 success.expects(:body).returns(IP_SUCCESS)
34 url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
35 GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
36 location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
37 assert_not_nil location
38 assert_equal 41.7696, location.lat
39 assert_equal -88.4588, location.lng
40 assert_equal "Sugar Grove", location.city
41 assert_equal "IL", location.state
42 assert_equal "US", location.country_code
43 assert_equal "hostip", location.provider
44 assert location.success
47 def test_unicoded_lookup
48 success = MockSuccess.new
49 success.expects(:body).returns(IP_UNICODED)
50 url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
51 GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
52 location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
53 assert_not_nil location
54 assert_equal 57.7167, location.lat
55 assert_equal 12.9167, location.lng
56 assert_equal "Borås", location.city
57 assert_nil location.state
58 assert_equal "SE", location.country_code
59 assert_equal "hostip", location.provider
60 assert location.success
63 def test_failed_lookup
64 failure = MockSuccess.new
65 failure.expects(:body).returns(IP_FAILURE)
66 url = 'http://api.hostip.info/get_html.php?ip=0.0.0.0&position=true'
67 GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
68 location = GeoKit::Geocoders::IpGeocoder.geocode("0.0.0.0")
69 assert_not_nil location
70 assert !location.success
74 location = GeoKit::Geocoders::IpGeocoder.geocode("blah")
75 assert_not_nil location
76 assert !location.success
79 def test_service_unavailable
80 failure = MockFailure.new
81 url = 'http://api.hostip.info/get_html.php?ip=0.0.0.0&position=true'
82 GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
83 location = GeoKit::Geocoders::IpGeocoder.geocode("0.0.0.0")
84 assert_not_nil location
85 assert !location.success