geokit 1.6.0 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,65 +3,82 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
3
3
  Geokit::Geocoders::google = 'Google'
4
4
 
5
5
  class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
6
-
6
+
7
7
  GOOGLE3_FULL=%q/
8
- {
9
- "status": "OK",
10
- "results": [ {
11
- "types": [ "street_address" ],
12
- "formatted_address": "100 Spear St, San Francisco, CA 94105, USA",
13
- "address_components": [ {
14
- "long_name": "100",
15
- "short_name": "100",
16
- "types": [ "street_number" ]
17
- }, {
18
- "long_name": "Spear St",
19
- "short_name": "Spear St",
20
- "types": [ "route" ]
21
- }, {
22
- "long_name": "San Francisco",
23
- "short_name": "San Francisco",
24
- "types": [ "locality", "political" ]
25
- }, {
26
- "long_name": "San Francisco",
27
- "short_name": "San Francisco",
28
- "types": [ "administrative_area_level_3", "political" ]
29
- }, {
30
- "long_name": "San Francisco",
31
- "short_name": "San Francisco",
32
- "types": [ "administrative_area_level_2", "political" ]
33
- }, {
34
- "long_name": "California",
35
- "short_name": "CA",
36
- "types": [ "administrative_area_level_1", "political" ]
37
- }, {
38
- "long_name": "United States",
39
- "short_name": "US",
40
- "types": [ "country", "political" ]
41
- }, {
42
- "long_name": "94105",
43
- "short_name": "94105",
44
- "types": [ "postal_code" ]
45
- } ],
46
- "geometry": {
47
- "location": {
48
- "lat": 37.7921509,
49
- "lng": -122.3940000
50
- },
51
- "location_type": "ROOFTOP",
52
- "viewport": {
53
- "southwest": {
54
- "lat": 37.7890033,
55
- "lng": -122.3971476
56
- },
57
- "northeast": {
58
- "lat": 37.7952985,
59
- "lng": -122.3908524
8
+ {
9
+ "results" : [
10
+ {
11
+ "address_components" : [
12
+ {
13
+ "long_name" : "5",
14
+ "short_name" : "5",
15
+ "types" : [ "subpremise" ]
16
+ },
17
+ {
18
+ "long_name" : "100",
19
+ "short_name" : "100",
20
+ "types" : [ "street_number" ]
21
+ },
22
+ {
23
+ "long_name" : "Spear St",
24
+ "short_name" : "Spear St",
25
+ "types" : [ "route" ]
26
+ },
27
+ {
28
+ "long_name" : "South Beach",
29
+ "short_name" : "South Beach",
30
+ "types" : [ "neighborhood", "political" ]
31
+ },
32
+ {
33
+ "long_name" : "San Francisco",
34
+ "short_name" : "SF",
35
+ "types" : [ "locality", "political" ]
36
+ },
37
+ {
38
+ "long_name" : "San Francisco",
39
+ "short_name" : "San Francisco",
40
+ "types" : [ "administrative_area_level_2", "political" ]
41
+ },
42
+ {
43
+ "long_name" : "California",
44
+ "short_name" : "CA",
45
+ "types" : [ "administrative_area_level_1", "political" ]
46
+ },
47
+ {
48
+ "long_name" : "United States",
49
+ "short_name" : "US",
50
+ "types" : [ "country", "political" ]
51
+ },
52
+ {
53
+ "long_name" : "94105",
54
+ "short_name" : "94105",
55
+ "types" : [ "postal_code" ]
56
+ }
57
+ ],
58
+ "formatted_address" : "100 Spear St #5, San Francisco, CA 94105, USA",
59
+ "geometry" : {
60
+ "location" : {
61
+ "lat" : 37.79215090,
62
+ "lng" : -122.3940
63
+ },
64
+ "location_type" : "APPROXIMATE",
65
+ "viewport" : {
66
+ "northeast" : {
67
+ "lat" : 37.79349988029150,
68
+ "lng" : -122.3926510197085
69
+ },
70
+ "southwest" : {
71
+ "lat" : 37.79080191970850,
72
+ "lng" : -122.3953489802915
73
+ }
74
+ }
75
+ },
76
+ "partial_match" : true,
77
+ "types" : [ "subpremise" ]
60
78
  }
61
- }
62
- }
63
- } ]
64
- }
79
+ ],
80
+ "status" : "OK"
81
+ }
65
82
  /.strip
66
83
 
67
84
  GOOGLE3_CITY=%q/
@@ -357,12 +374,14 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
357
374
  /
358
375
  def setup
359
376
  super
360
- @google_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
377
+ @full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
378
+ @full_address_short_zip = '100 Spear St Apt. 5, San Francisco, CA, 94105, US'
379
+ @google_full_hash = {:street_address=>"100 Spear St Apt. 5", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
361
380
  @google_city_hash = {:city=>"San Francisco", :state=>"CA"}
362
381
 
363
382
  @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
364
383
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
365
- end
384
+ end
366
385
 
367
386
  def test_google3_full_address
368
387
  response = MockSuccess.new
@@ -371,13 +390,13 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
371
390
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
372
391
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@address)
373
392
  assert_equal "CA", res.state
374
- assert_equal "San Francisco", res.city
393
+ assert_equal "San Francisco", res.city
375
394
  assert_equal "37.7921509,-122.394", res.ll # slightly dif from yahoo
376
395
  assert res.is_us?
377
- assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
396
+ assert_equal "100 Spear St #5, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
378
397
  assert_equal "google3", res.provider
379
398
  end
380
-
399
+
381
400
  def test_google3_full_address_with_geo_loc
382
401
  response = MockSuccess.new
383
402
  response.expects(:body).returns(GOOGLE3_FULL)
@@ -385,22 +404,24 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
385
404
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
386
405
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@google_full_loc)
387
406
  assert_equal "CA", res.state
388
- assert_equal "San Francisco", res.city
407
+ assert_equal "San Francisco", res.city
389
408
  assert_equal "37.7921509,-122.394", res.ll # slightly dif from yahoo
390
409
  assert res.is_us?
391
- assert_equal "100 Spear St, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
410
+ assert_equal "100 Spear St #5, San Francisco, CA 94105, USA", res.full_address #slightly different from yahoo
392
411
  assert_equal "google3", res.provider
393
- end
394
-
412
+ end
413
+
395
414
  def test_google3_full_address_accuracy
396
415
  response = MockSuccess.new
397
416
  response.expects(:body).returns(GOOGLE3_FULL)
398
417
  url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
399
418
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
400
419
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@google_full_loc)
420
+
421
+ puts res.to_hash.inspect
401
422
  assert_equal 9, res.accuracy
402
423
  end
403
-
424
+
404
425
  def test_google3_city
405
426
  response = MockSuccess.new
406
427
  response.expects(:body).returns(GOOGLE3_CITY)
@@ -414,8 +435,8 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
414
435
  assert res.is_us?
415
436
  assert_equal "San Francisco, CA, USA", res.full_address
416
437
  assert_equal "google3", res.provider
417
- end
418
-
438
+ end
439
+
419
440
  def test_google3_city_accuracy
420
441
  response = MockSuccess.new
421
442
  response.expects(:body).returns(GOOGLE3_CITY)
@@ -424,7 +445,7 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
424
445
  res=Geokit::Geocoders::GoogleGeocoder3.geocode(@address)
425
446
  assert_equal 4, res.accuracy
426
447
  end
427
-
448
+
428
449
  def test_google3_city_with_geo_loc
429
450
  response = MockSuccess.new
430
451
  response.expects(:body).returns(GOOGLE3_CITY)
@@ -438,7 +459,7 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
438
459
  assert_equal "San Francisco, CA, USA", res.full_address
439
460
  assert_nil res.street_address
440
461
  assert_equal "google3", res.provider
441
- end
462
+ end
442
463
 
443
464
  def test_google3_suggested_bounds
444
465
  response = MockSuccess.new
@@ -446,18 +467,18 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
446
467
  url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@full_address_short_zip)}"
447
468
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
448
469
  res = Geokit::Geocoders::GoogleGeocoder3.geocode(@google_full_loc)
449
-
470
+
450
471
  assert_instance_of Geokit::Bounds, res.suggested_bounds
451
- assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7890033, -122.3971476), Geokit::LatLng.new(37.7952985, -122.3908524)), res.suggested_bounds
472
+ assert_equal Geokit::Bounds.new(Geokit::LatLng.new(37.7908019197085, -122.395348980292), Geokit::LatLng.new(37.7934998802915, -122.392651019708)), res.suggested_bounds
452
473
  end
453
-
474
+
454
475
  def test_service_unavailable
455
476
  response = MockFailure.new
456
477
  url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=#{Geokit::Inflector::url_escape(@address)}"
457
478
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
458
479
  assert !Geokit::Geocoders::GoogleGeocoder3.geocode(@google_city_loc).success
459
- end
460
-
480
+ end
481
+
461
482
  def test_multiple_results
462
483
  #Geokit::Geocoders::GoogleGeocoder3.do_geocode('via Sandro Pertini 8, Ossona, MI')
463
484
  response = MockSuccess.new
@@ -472,7 +493,7 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
472
493
  assert_equal "Via Sandro Pertini, 8, 20010 Mesero MI, Italy", res.full_address
473
494
  assert_equal "8 Via Sandro Pertini", res.street_address
474
495
  assert_equal "google3", res.provider
475
-
496
+
476
497
  assert_equal 2, res.all.size
477
498
  res = res.all[1]
478
499
  assert_equal "Lombardy", res.state
@@ -483,7 +504,7 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
483
504
  assert_equal "Via Sandro Pertini", res.street_address
484
505
  assert_equal "google3", res.provider
485
506
  end
486
- #
507
+ #
487
508
  def test_reverse_geocode
488
509
  #Geokit::Geocoders::GoogleGeocoder3.do_reverse_geocode("40.4167413, -3.7032498")
489
510
  madrid = Geokit::GeoLoc.new
@@ -494,36 +515,36 @@ class GoogleGeocoder3Test < BaseGeocoderTest #:nodoc: all
494
515
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).
495
516
  returns(response)
496
517
  res=Geokit::Geocoders::GoogleGeocoder3.do_reverse_geocode(madrid.ll)
497
-
518
+
498
519
  assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
499
520
  assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
500
521
  assert_equal "ES", res.country_code
501
522
  assert_equal "google3", res.provider
502
-
523
+
503
524
  assert_equal "Madrid", res.city
504
525
  assert_equal "Madrid", res.state
505
-
526
+
506
527
  assert_equal "Spain", res.country
507
528
  assert_equal "street", res.precision
508
529
  assert_equal true, res.success
509
-
530
+
510
531
  assert_equal "Calle de las Carretas, 28013 Madrid, Spain", res.full_address
511
532
  assert_equal "28013", res.zip
512
533
  assert_equal "Calle de las Carretas", res.street_address
513
- end
534
+ end
514
535
 
515
536
  def test_country_code_biasing
516
537
  response = MockSuccess.new
517
538
  response.expects(:body).returns(GOOGLE3_COUNTRY_CODE_BIASED_RESULT)
518
-
539
+
519
540
  url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=Syracuse&region=it"
520
541
  Geokit::Geocoders::GoogleGeocoder3.expects(:call_geocoder_service).with(url).returns(response)
521
542
  biased_result = Geokit::Geocoders::GoogleGeocoder3.geocode('Syracuse', :bias => 'it')
522
-
543
+
523
544
  assert_equal 'IT', biased_result.country_code
524
545
  assert_equal 'Sicily', biased_result.state
525
546
  end
526
-
547
+
527
548
  def test_too_many_queries
528
549
  response = MockSuccess.new
529
550
  response.expects(:body).returns(GOOGLE3_TOO_MANY)
@@ -3,19 +3,19 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
3
3
  Geokit::Geocoders::google = 'Google'
4
4
 
5
5
  class GoogleReverseGeocoderTest < BaseGeocoderTest #:nodoc: all
6
-
7
- GOOGLE_REVERSE_FULL=<<-EOF.strip
6
+
7
+ GOOGLE_REVERSE_FULL=<<-EOF.strip
8
8
  <?xml version="1.0" encoding="UTF-8" ?><kml xmlns="http://earth.google.com/kml/2.0"><Response><name>51.457833,7.016685</name><Status><code>200</code><request>geocode</request></Status><Placemark id="p1"><address>Porscheplatz 1, 45127 Essen, Deutschland</address><AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><DependentLocality><DependentLocalityName>Stadtkern</DependentLocalityName><Thoroughfare><ThoroughfareName>Porscheplatz 1</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>45127</PostalCodeNumber></PostalCode></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4609805" south="51.4546853" east="7.0198324" west="7.0135372" /></ExtendedData><Point><coordinates>7.0166848,51.4578329,0</coordinates></Point></Placemark><Placemark id="p2"><address>Stadtkern, Essen, Deutschland</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><DependentLocality><DependentLocalityName>Stadtkern</DependentLocalityName></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4630710" south="51.4506320" east="7.0193200" west="7.0026170" /></ExtendedData><Point><coordinates>7.0124328,51.4568201,0</coordinates></Point></Placemark><Placemark id="p3"><address>45127 Essen, Deutschland</address><AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName><PostalCode><PostalCodeNumber>45127</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.4637808" south="51.4503125" east="7.0231080" west="6.9965454" /></ExtendedData><Point><coordinates>7.0104543,51.4556194,0</coordinates></Point></Placemark><Placemark id="p4"><address>Essen, Deutschland</address><AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName><Locality><LocalityName>Essen</LocalityName></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.5342070" south="51.3475730" east="7.1376530" west="6.8943470" /></ExtendedData><Point><coordinates>7.0147614,51.4580686,0</coordinates></Point></Placemark><Placemark id="p5"><address>Essen, Deutschland</address><AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Essen</SubAdministrativeAreaName></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="51.5342070" south="51.3475730" east="7.1376530" west="6.8943470" /></ExtendedData><Point><coordinates>7.0461136,51.4508381,0</coordinates></Point></Placemark><Placemark id="p6"><address>Nordrhein-Westfalen, Deutschland</address><AddressDetails Accuracy="2" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName><AdministrativeArea><AdministrativeAreaName>Nordrhein-Westfalen</AdministrativeAreaName></AdministrativeArea></Country></AddressDetails><ExtendedData><LatLonBox north="52.5314170" south="50.3225720" east="9.4615950" west="5.8663566" /></ExtendedData><Point><coordinates>7.6615938,51.4332367,0</coordinates></Point></Placemark><Placemark id="p7"><address>Deutschland</address><AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>DE</CountryNameCode><CountryName>Deutschland</CountryName></Country></AddressDetails><ExtendedData><LatLonBox north="55.0568230" south="47.2701270" east="15.0418536" west="5.8663566" /></ExtendedData><Point><coordinates>10.4515260,51.1656910,0</coordinates></Point></Placemark></Response></kml>
9
9
  EOF
10
-
11
-
10
+
11
+
12
12
  def test_google_full_address
13
13
  response = MockSuccess.new
14
14
  response.expects(:body).returns(GOOGLE_REVERSE_FULL)
15
-
16
-
15
+
16
+
17
17
  # http://maps.google.com/maps/geo?output=xml&oe=utf-8&ll=51.4578329,7.0166848&key=asdad
18
-
18
+
19
19
  # #<Geokit::GeoLoc:0x10ec7ec
20
20
  # @city="Essen",
21
21
  # @country_code="DE",
@@ -28,22 +28,22 @@ class GoogleReverseGeocoderTest < BaseGeocoderTest #:nodoc: all
28
28
  # @street_address="Porscheplatz 1",
29
29
  # @success=true,
30
30
  # @zip="45127">
31
- #
32
-
33
-
31
+ #
32
+
33
+
34
34
  @latlng = "51.4578329,7.0166848"
35
-
35
+
36
36
  url = "http://maps.google.com/maps/geo?ll=#{Geokit::Inflector.url_escape(@latlng)}&output=xml&key=Google&oe=utf-8"
37
37
  Geokit::Geocoders::GoogleGeocoder.expects(:call_geocoder_service).with(url).returns(response)
38
- res=Geokit::Geocoders::GoogleGeocoder.reverse_geocode(@latlng)
38
+ res=Geokit::Geocoders::GoogleGeocoder.reverse_geocode(@latlng)
39
39
  assert_equal "Nordrhein-Westfalen", res.state
40
- assert_equal "Essen", res.city
40
+ assert_equal "Essen", res.city
41
41
  assert_equal "45127", res.zip
42
42
  assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
43
43
  assert res.is_us? == false
44
44
  assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
45
45
  assert_equal "google", res.provider
46
46
  end
47
-
48
-
49
- end
47
+
48
+
49
+ end
@@ -4,14 +4,14 @@ require 'test/unit'
4
4
  require 'lib/geokit'
5
5
 
6
6
  class InflectorTest < Test::Unit::TestCase #:nodoc: all
7
-
7
+
8
8
  def test_titleize
9
9
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar Grove')
10
10
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar grove')
11
11
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar Grove')
12
12
  assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar grove')
13
13
  end
14
-
14
+
15
15
  def test_titleize_with_unicode
16
16
  assert_equal 'Borås', Geokit::Inflector.titleize('Borås')
17
17
  assert_equal 'Borås', Geokit::Inflector.titleize('borås')
@@ -20,5 +20,5 @@ class InflectorTest < Test::Unit::TestCase #:nodoc: all
20
20
  assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('borås (Abc)')
21
21
  assert_equal 'Borås (Abc)', Geokit::Inflector.titleize('borås (abc)')
22
22
  end
23
-
23
+
24
24
  end
@@ -2,28 +2,28 @@
2
2
  require File.join(File.dirname(__FILE__), 'test_base_geocoder')
3
3
 
4
4
  class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
-
5
+
6
6
  IP_FAILURE=<<-EOF
7
7
  Country: SWITZERLAND (CH)
8
8
  City: (Unknown City)
9
- Latitude:
9
+ Latitude:
10
10
  Longitude:
11
11
  EOF
12
-
12
+
13
13
  IP_SUCCESS=<<-EOF
14
14
  Country: UNITED STATES (US)
15
15
  City: Sugar Grove, IL
16
16
  Latitude: 41.7696
17
17
  Longitude: -88.4588
18
18
  EOF
19
-
19
+
20
20
  IP_UNICODED=<<-EOF
21
21
  Country: SWEDEN (SE)
22
22
  City: Borås
23
23
  Latitude: 57.7167
24
24
  Longitude: 12.9167
25
25
  EOF
26
-
26
+
27
27
  PRIVATE_IPS_TO_TEST = [
28
28
  '10.10.10.10',
29
29
  '172.16.1.3',
@@ -39,8 +39,8 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
39
39
  def setup
40
40
  super
41
41
  @success.provider = "hostip"
42
- end
43
-
42
+ end
43
+
44
44
  def test_successful_lookup
45
45
  success = MockSuccess.new
46
46
  success.expects(:body).returns(IP_SUCCESS)
@@ -56,7 +56,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
56
56
  assert_equal "hostip", location.provider
57
57
  assert location.success?
58
58
  end
59
-
59
+
60
60
  def test_unicoded_lookup
61
61
  success = MockSuccess.new
62
62
  success.expects(:body).returns(IP_UNICODED)
@@ -72,7 +72,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
72
72
  assert_equal "hostip", location.provider
73
73
  assert location.success?
74
74
  end
75
-
75
+
76
76
  def test_failed_lookup
77
77
  failure = MockSuccess.new
78
78
  failure.expects(:body).returns(IP_FAILURE)
@@ -82,7 +82,7 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
82
82
  assert_not_nil location
83
83
  assert !location.success?
84
84
  end
85
-
85
+
86
86
  def test_private_ips
87
87
  GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
88
88
  PRIVATE_IPS_TO_TEST.each do |ip|
@@ -91,14 +91,14 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
91
91
  assert !location.success?
92
92
  end
93
93
  end
94
-
94
+
95
95
  def test_invalid_ip
96
96
  GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
97
97
  location = GeoKit::Geocoders::IpGeocoder.geocode("blah")
98
98
  assert_not_nil location
99
99
  assert !location.success?
100
100
  end
101
-
101
+
102
102
  def test_service_unavailable
103
103
  failure = MockFailure.new
104
104
  url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
@@ -106,5 +106,5 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
106
106
  location = GeoKit::Geocoders::IpGeocoder.geocode("12.215.42.19")
107
107
  assert_not_nil location
108
108
  assert !location.success?
109
- end
109
+ end
110
110
  end