test/test_ipgeocoder.rb in rjaswal-geokit-1.5.0.2 vs test/test_ipgeocoder.rb in rjaswal-geokit-1.5.1

- old
+ new

@@ -2,12 +2,12 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder') class IpGeocoderTest < BaseGeocoderTest #:nodoc: all IP_FAILURE=<<-EOF - Country: (Private Address) (XX) - City: (Private Address) + Country: SWITZERLAND (CH) + City: (Unknown City) Latitude: Longitude: EOF IP_SUCCESS=<<-EOF @@ -22,14 +22,26 @@ City: BorĂ¥s Latitude: 57.7167 Longitude: 12.9167 EOF - def setup - super - @success.provider = "hostip" - end + PRIVATE_IPS_TO_TEST = [ + '10.10.10.10', + '172.16.1.3', + '172.22.3.42', + '172.30.254.164', + '192.168.1.1', + '0.0.0.0', + '127.0.0.1', + '240.3.4.5', + '225.1.6.55' + ].freeze + + def setup + super + @success.provider = "hostip" + end def test_successful_lookup success = MockSuccess.new success.expects(:body).returns(IP_SUCCESS) url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true' @@ -62,27 +74,37 @@ end def test_failed_lookup failure = MockSuccess.new failure.expects(:body).returns(IP_FAILURE) - url = 'http://api.hostip.info/get_html.php?ip=10.10.10.10&position=true' + url = 'http://api.hostip.info/get_html.php?ip=128.178.0.0&position=true' GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure) - location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10") + location = GeoKit::Geocoders::IpGeocoder.geocode("128.178.0.0") assert_not_nil location assert !location.success? end + def test_private_ips + GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never + PRIVATE_IPS_TO_TEST.each do |ip| + location = GeoKit::Geocoders::IpGeocoder.geocode(ip) + assert_not_nil location + assert !location.success? + end + end + def test_invalid_ip + GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never location = GeoKit::Geocoders::IpGeocoder.geocode("blah") assert_not_nil location assert !location.success? end def test_service_unavailable failure = MockFailure.new - url = 'http://api.hostip.info/get_html.php?ip=10.10.10.10&position=true' + url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true' GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure) - location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10") + location = GeoKit::Geocoders::IpGeocoder.geocode("12.215.42.19") assert_not_nil location assert !location.success? end end