geokit 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +358 -0
  5. data/.travis.yml +4 -4
  6. data/CHANGELOG.md +16 -0
  7. data/Gemfile +3 -3
  8. data/README.markdown +19 -4
  9. data/Rakefile +11 -16
  10. data/fixtures/keys.yml +9 -0
  11. data/fixtures/vcr_cassettes/google_postal_town.yml +117 -0
  12. data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +30 -30
  13. data/fixtures/vcr_cassettes/mapbox_forward_geocode_city_only.yml +25 -25
  14. data/fixtures/vcr_cassettes/mapbox_forward_geocode_state_only.yml +71 -0
  15. data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +25 -25
  16. data/fixtures/vcr_cassettes/test_component_filtering_off.yml +390 -0
  17. data/fixtures/vcr_cassettes/test_component_filtering_on.yml +164 -0
  18. data/fixtures/vcr_cassettes/test_component_filtering_on_without_filter.yml +404 -0
  19. data/geokit.gemspec +24 -23
  20. data/lib/geokit.rb +7 -7
  21. data/lib/geokit/core_ext.rb +1 -1
  22. data/lib/geokit/geo_loc.rb +25 -19
  23. data/lib/geokit/geocoders.rb +21 -30
  24. data/lib/geokit/geocoders/bing.rb +5 -4
  25. data/lib/geokit/geocoders/ca_geocoder.rb +10 -11
  26. data/lib/geokit/geocoders/fcc.rb +9 -9
  27. data/lib/geokit/geocoders/free_geo_ip.rb +8 -8
  28. data/lib/geokit/geocoders/geo_plugin.rb +7 -7
  29. data/lib/geokit/geocoders/geobytes.rb +10 -10
  30. data/lib/geokit/geocoders/geocodio.rb +14 -14
  31. data/lib/geokit/geocoders/geonames.rb +12 -12
  32. data/lib/geokit/geocoders/google.rb +89 -61
  33. data/lib/geokit/geocoders/ip.rb +9 -14
  34. data/lib/geokit/geocoders/mapbox.rb +30 -30
  35. data/lib/geokit/geocoders/mapquest.rb +12 -12
  36. data/lib/geokit/geocoders/maxmind.rb +1 -1
  37. data/lib/geokit/geocoders/opencage.rb +19 -19
  38. data/lib/geokit/geocoders/openstreetmap.rb +21 -19
  39. data/lib/geokit/geocoders/ripe.rb +7 -7
  40. data/lib/geokit/geocoders/us_geocoder.rb +5 -5
  41. data/lib/geokit/geocoders/yahoo.rb +46 -46
  42. data/lib/geokit/geocoders/yandex.rb +18 -17
  43. data/lib/geokit/inflectors.rb +5 -5
  44. data/lib/geokit/lat_lng.rb +5 -4
  45. data/lib/geokit/multi_geocoder.rb +4 -2
  46. data/lib/geokit/net_adapter/net_http.rb +3 -2
  47. data/lib/geokit/net_adapter/typhoeus.rb +2 -1
  48. data/lib/geokit/version.rb +1 -1
  49. data/test/coverage_loader.rb +25 -0
  50. data/test/helper.rb +18 -87
  51. data/test/test_base_geocoder.rb +44 -11
  52. data/test/test_bing_geocoder.rb +40 -48
  53. data/test/test_bounds.rb +1 -1
  54. data/test/test_ca_geocoder.rb +15 -15
  55. data/test/test_fcc_geocoder.rb +8 -9
  56. data/test/test_free_geo_ip_geocoder.rb +8 -10
  57. data/test/test_geo_plugin_geocoder.rb +21 -22
  58. data/test/test_geobytes_geocoder.rb +9 -11
  59. data/test/test_geocodio_geocoder.rb +12 -14
  60. data/test/test_geoloc.rb +48 -49
  61. data/test/test_geonames_geocoder.rb +19 -23
  62. data/test/test_google_geocoder.rb +197 -189
  63. data/test/test_inflector.rb +7 -7
  64. data/test/test_ipgeocoder.rb +32 -31
  65. data/test/test_latlng.rb +28 -28
  66. data/test/test_map_quest.rb +23 -27
  67. data/test/test_mapbox_geocoder.rb +38 -28
  68. data/test/test_mappable.rb +2 -2
  69. data/test/test_maxmind_geocoder.rb +16 -16
  70. data/test/test_multi_geocoder.rb +5 -5
  71. data/test/test_multi_ip_geocoder.rb +3 -3
  72. data/test/test_net_adapter.rb +4 -4
  73. data/test/test_opencage_geocoder.rb +58 -67
  74. data/test/test_openstreetmap_geocoder.rb +67 -65
  75. data/test/test_polygon.rb +4 -22
  76. data/test/test_ripe_geocoder.rb +21 -26
  77. data/test/test_us_geocoder.rb +21 -21
  78. data/test/test_useragent.rb +46 -0
  79. data/test/test_yahoo_geocoder.rb +35 -47
  80. data/test/test_yandex_geocoder.rb +29 -27
  81. data/test/vcr_loader.rb +18 -0
  82. metadata +20 -6
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), "helper")
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class InflectorTest < Test::Unit::TestCase #:nodoc: all
5
5
  def test_titleize
6
- assert_equal "Sugar Grove", Geokit::Inflector.titleize("Sugar Grove")
7
- assert_equal "Sugar Grove", Geokit::Inflector.titleize("Sugar grove")
8
- assert_equal "Sugar Grove", Geokit::Inflector.titleize("sugar Grove")
9
- assert_equal "Sugar Grove", Geokit::Inflector.titleize("sugar grove")
6
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar Grove')
7
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('Sugar grove')
8
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar Grove')
9
+ assert_equal 'Sugar Grove', Geokit::Inflector.titleize('sugar grove')
10
10
  end
11
11
 
12
12
  def test_titleize_with_unicode
@@ -19,7 +19,7 @@ class InflectorTest < Test::Unit::TestCase #:nodoc: all
19
19
  end
20
20
 
21
21
  def test_url_escape
22
- assert_equal "%E4%B8%8A%E6%B5%B7%E5%B8%82%E5%BE%90%E6%B1%87%E5%8C%BA%E6%BC%95%E6%BA%AA%E5%8C%97%E8%B7%AF1111%E5%8F%B7", Geokit::Inflector.url_escape("上海市徐汇区漕溪北路1111号")
23
- assert_equal "%C3%BC%C3%B6%C3%A4", Geokit::Inflector.url_escape("üöä")
22
+ assert_equal '%E4%B8%8A%E6%B5%B7%E5%B8%82%E5%BE%90%E6%B1%87%E5%8C%BA%E6%BC%95%E6%BA%AA%E5%8C%97%E8%B7%AF1111%E5%8F%B7', Geokit::Inflector.url_escape("上海市徐汇区漕溪北路1111号")
23
+ assert_equal '%C3%BC%C3%B6%C3%A4', Geokit::Inflector.url_escape("üöä")
24
24
  end
25
25
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), "helper")
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
5
  IP_FAILURE = <<-EOF
@@ -31,77 +31,78 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
31
31
  EOF
32
32
 
33
33
  PRIVATE_IPS_TO_TEST = [
34
- "10.10.10.10",
35
- "172.16.1.3",
36
- "172.22.3.42",
37
- "172.30.254.164",
38
- "192.168.1.1",
39
- "0.0.0.0",
40
- "127.0.0.1",
41
- "240.3.4.5",
42
- "225.1.6.55",
34
+ '10.10.10.10',
35
+ '172.16.1.3',
36
+ '172.22.3.42',
37
+ '172.30.254.164',
38
+ '192.168.1.1',
39
+ '0.0.0.0',
40
+ '127.0.0.1',
41
+ '240.3.4.5',
42
+ '225.1.6.55',
43
43
  ].freeze
44
44
 
45
45
  def setup
46
46
  super
47
- @success.provider = "ip"
47
+ @success.provider = 'ip'
48
+ @base_url = 'http://api.hostip.info/get_html.php'
48
49
  end
49
50
 
50
51
  def test_successful_lookup
51
52
  success = MockSuccess.new
52
53
  success.expects(:body).returns(IP_SUCCESS)
53
- url = "http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true"
54
+ url = "#{@base_url}?ip=12.215.42.19&position=true"
54
55
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
55
- location = Geokit::Geocoders::IpGeocoder.geocode("12.215.42.19")
56
+ location = Geokit::Geocoders::IpGeocoder.geocode('12.215.42.19')
56
57
  assert_not_nil location
57
58
  assert_equal 41.7696, location.lat
58
59
  assert_equal(-88.4588, location.lng)
59
- assert_equal "Sugar Grove", location.city
60
- assert_equal "IL", location.state
61
- assert_equal "US", location.country_code
62
- assert_equal "ip", location.provider
60
+ assert_equal 'Sugar Grove', location.city
61
+ assert_equal 'IL', location.state
62
+ assert_equal 'US', location.country_code
63
+ assert_equal 'ip', location.provider
63
64
  assert location.success?
64
65
  end
65
66
 
66
67
  def test_unicoded_lookup
67
68
  success = MockSuccess.new
68
69
  success.expects(:body).returns(IP_UNICODED)
69
- url = "http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true"
70
+ url = "#{@base_url}?ip=12.215.42.19&position=true"
70
71
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
71
- location = Geokit::Geocoders::IpGeocoder.geocode("12.215.42.19")
72
+ location = Geokit::Geocoders::IpGeocoder.geocode('12.215.42.19')
72
73
  assert_not_nil location
73
74
  assert_equal 57.7167, location.lat
74
75
  assert_equal 12.9167, location.lng
75
76
  assert_equal "Bor\303\245s", location.city
76
77
  assert_nil location.state
77
- assert_equal "SE", location.country_code
78
- assert_equal "ip", location.provider
78
+ assert_equal 'SE', location.country_code
79
+ assert_equal 'ip', location.provider
79
80
  assert location.success?
80
81
  end
81
82
 
82
83
  def test_non_unicoded_lookup
83
84
  success = MockSuccess.new
84
85
  success.stubs(:body).returns(IP_LATIN)
85
- success.stubs(:[]).with("content-type").returns("text/plain; charset=iso-8859-1")
86
- url = "http://api.hostip.info/get_html.php?ip=201.23.177.144&position=true"
86
+ success.stubs(:[]).with('content-type').returns('text/plain; charset=iso-8859-1')
87
+ url = "#{@base_url}?ip=201.23.177.144&position=true"
87
88
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
88
- location = Geokit::Geocoders::IpGeocoder.geocode("201.23.177.144")
89
+ location = Geokit::Geocoders::IpGeocoder.geocode('201.23.177.144')
89
90
  assert_not_nil location
90
91
  assert_equal(-20.8, location.lat)
91
92
  assert_equal(-49.3833, location.lng)
92
93
  assert_equal "São José Do Rio Prêto", location.city
93
94
  assert_nil location.state
94
- assert_equal "BR", location.country_code
95
- assert_equal "ip", location.provider
95
+ assert_equal 'BR', location.country_code
96
+ assert_equal 'ip', location.provider
96
97
  assert location.success?
97
98
  end
98
99
 
99
100
  def test_failed_lookup
100
101
  failure = MockSuccess.new
101
102
  failure.expects(:body).returns(IP_FAILURE)
102
- url = "http://api.hostip.info/get_html.php?ip=128.178.0.0&position=true"
103
+ url = "#{@base_url}?ip=128.178.0.0&position=true"
103
104
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
104
- location = Geokit::Geocoders::IpGeocoder.geocode("128.178.0.0")
105
+ location = Geokit::Geocoders::IpGeocoder.geocode('128.178.0.0')
105
106
  assert_not_nil location
106
107
  assert !location.success?
107
108
  end
@@ -117,16 +118,16 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
117
118
 
118
119
  def test_invalid_ip
119
120
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).never
120
- location = Geokit::Geocoders::IpGeocoder.geocode("blah")
121
+ location = Geokit::Geocoders::IpGeocoder.geocode('blah')
121
122
  assert_not_nil location
122
123
  assert !location.success?
123
124
  end
124
125
 
125
126
  def test_service_unavailable
126
127
  failure = MockFailure.new
127
- url = "http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true"
128
+ url = "#{@base_url}?ip=12.215.42.19&position=true"
128
129
  Geokit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
129
- location = Geokit::Geocoders::IpGeocoder.geocode("12.215.42.19")
130
+ location = Geokit::Geocoders::IpGeocoder.geocode('12.215.42.19')
130
131
  assert_not_nil location
131
132
  assert !location.success?
132
133
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "helper")
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class LatLngTest < Test::Unit::TestCase #:nodoc: all
4
4
  def setup
@@ -9,19 +9,19 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
9
9
 
10
10
  def valid_reverse_geocoding_result
11
11
  location = Geokit::GeoLoc.new(
12
- city: "Essen",
13
- country_code: "DE",
12
+ city: 'Essen',
13
+ country_code: 'DE',
14
14
  lat: 51.4578329,
15
15
  lng: 7.0166848,
16
- provider: "google",
17
- state: "Nordrhein-Westfalen",
18
- street_address: "Porscheplatz 1",
19
- zip: "45127",
16
+ provider: 'google',
17
+ state: 'Nordrhein-Westfalen',
18
+ street_address: 'Porscheplatz 1',
19
+ zip: '45127',
20
20
  )
21
21
 
22
- location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
23
- location.precision = "address"
24
- location.provider = "google"
22
+ location.full_address = 'Porscheplatz 1, 45127 Essen, Deutschland'
23
+ location.precision = 'address'
24
+ location.provider = 'google'
25
25
  location.success = true
26
26
  location
27
27
  end
@@ -201,12 +201,12 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
201
201
  Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
202
202
  res = point.reverse_geocode
203
203
 
204
- assert_equal "Nordrhein-Westfalen", res.state
205
- assert_equal "Essen", res.city
206
- assert_equal "45127", res.zip
207
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
204
+ assert_equal 'Nordrhein-Westfalen', res.state
205
+ assert_equal 'Essen', res.city
206
+ assert_equal '45127', res.zip
207
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
208
208
  assert res.is_us? == false
209
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address # slightly different from yahoo
209
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
210
210
  end
211
211
 
212
212
  def test_reverse_geocoding_using_specific_geocoder
@@ -214,13 +214,13 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
214
214
  Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
215
215
  res = point.reverse_geocode(using: Geokit::Geocoders::GoogleGeocoder)
216
216
 
217
- assert_equal "Nordrhein-Westfalen", res.state
218
- assert_equal "Essen", res.city
219
- assert_equal "45127", res.zip
220
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
217
+ assert_equal 'Nordrhein-Westfalen', res.state
218
+ assert_equal 'Essen', res.city
219
+ assert_equal '45127', res.zip
220
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
221
221
  assert res.is_us? == false
222
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address # slightly different from yahoo
223
- assert_equal "google", res.provider
222
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
223
+ assert_equal 'google', res.provider
224
224
  end
225
225
 
226
226
  def test_reverse_geocoding_using_specific_geocoder_short_syntax
@@ -228,13 +228,13 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
228
228
  Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
229
229
  res = point.reverse_geocode(using: :google)
230
230
 
231
- assert_equal "Nordrhein-Westfalen", res.state
232
- assert_equal "Essen", res.city
233
- assert_equal "45127", res.zip
234
- assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
231
+ assert_equal 'Nordrhein-Westfalen', res.state
232
+ assert_equal 'Essen', res.city
233
+ assert_equal '45127', res.zip
234
+ assert_equal '51.4578329,7.0166848', res.ll # slightly dif from yahoo
235
235
  assert res.is_us? == false
236
- assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address # slightly different from yahoo
237
- assert_equal "google", res.provider
236
+ assert_equal 'Porscheplatz 1, 45127 Essen, Deutschland', res.full_address # slightly different from yahoo
237
+ assert_equal 'google', res.provider
238
238
  end
239
239
 
240
240
  def test_to_dms
@@ -256,7 +256,7 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
256
256
  end
257
257
 
258
258
  def test_invalid_units
259
- expected_exception_message = "feet is an unsupported unit of length."
259
+ expected_exception_message = 'feet is an unsupported unit of length.'
260
260
 
261
261
  exception = assert_raise(ArgumentError) do
262
262
  @loc_a.distance_to(@loc_e, units: :feet)
@@ -1,53 +1,49 @@
1
- require File.join(File.dirname(__FILE__), "helper")
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class MapQuestGeocoderTest < BaseGeocoderTest #:nodoc: all
4
4
  def setup
5
5
  super
6
- @full_address = "100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US"
7
- @google_full_hash = {street_address: "100 Spear St Apt. 5", city: "San Francisco", state: "CA", zip: "94105", country_code: "US"}
8
- @google_city_hash = {city: "San Francisco", state: "CA"}
6
+ @full_address = '100 Spear St Apt. 5, San Francisco, CA, 94105-1522, US'
7
+ @google_full_hash = {street_address: '100 Spear St Apt. 5', city: 'San Francisco', state: 'CA', zip: '94105', country_code: 'US'}
8
+ @google_city_hash = {city: 'San Francisco', state: 'CA'}
9
9
 
10
10
  @google_full_loc = Geokit::GeoLoc.new(@google_full_hash)
11
11
  @google_city_loc = Geokit::GeoLoc.new(@google_city_hash)
12
+
13
+ @key = @keys['map_quest']['key']
14
+ geocoder_class.key = @key
15
+ @base_url = 'https://www.mapquestapi.com/geocoding/v1'
12
16
  end
13
17
 
14
18
  def test_map_quest_full_address_with_geo_loc
15
- VCR.use_cassette("map_quest_full") do
16
- key = "Fmjtd%7Cluur2d0125%2C2s%3Do5-9a8lhz"
17
- Geokit::Geocoders::MapQuestGeocoder.key = key
18
- url = "https://www.mapquestapi.com/geocoding/v1/address?key=#{key}&location=100+Spear+St+Apt.+5%2C+San+Francisco%2C+CA%2C+94105%2C+US"
19
+ url = "#{@base_url}/address?key=#{@key}&location=100+Spear+St+Apt.+5%2C+San+Francisco%2C+CA%2C+94105%2C+US"
19
20
  TestHelper.expects(:last_url).with(url)
20
- res = Geokit::Geocoders::MapQuestGeocoder.geocode(@google_full_loc)
21
- assert_equal "CA", res.state
22
- assert_equal "San Francisco", res.city
21
+ res = geocode(@google_full_loc, :map_quest_full)
22
+ assert_equal 'CA', res.state
23
+ assert_equal 'San Francisco', res.city
23
24
  assert_array_in_delta [37.7921509, -122.394], res.to_a # slightly dif from yahoo
24
25
  assert res.is_us?
25
- assert_equal "100 Spear St, Apt 5, San Francisco, CA, 94105-1500, US", res.full_address # slightly different from yahoo
26
- assert_equal "map_quest", res.provider
27
- end
26
+ assert_equal '100 Spear St, Apt 5, San Francisco, CA, 94105-1500, US', res.full_address # slightly different from yahoo
27
+ assert_equal 'map_quest', res.provider
28
28
  end
29
29
 
30
30
  def test_reverse_geocode
31
- VCR.use_cassette("map_quest_reverse_madrid") do
32
- madrid = Geokit::GeoLoc.new
33
- madrid.lat, madrid.lng = "40.4167413", "-3.7032498"
34
- key = "Fmjtd%7Cluur2d0125%2C2s%3Do5-9a8lhz"
35
- Geokit::Geocoders::MapQuestGeocoder.key = key
36
- url = "https://www.mapquestapi.com/geocoding/v1/reverse?key=#{key}&location=#{madrid.lat},#{madrid.lng}"
31
+ madrid = Geokit::GeoLoc.new
32
+ madrid.lat, madrid.lng = '40.4167413', '-3.7032498'
33
+ url = "#{@base_url}/reverse?key=#{@key}&location=#{madrid.lat},#{madrid.lng}"
37
34
  TestHelper.expects(:last_url).with(url)
38
- res = Geokit::Geocoders::MapQuestGeocoder.do_reverse_geocode(madrid.ll)
35
+ res = reverse_geocode(madrid.ll, :map_quest_reverse_madrid)
39
36
 
40
37
  assert_equal madrid.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
41
38
  assert_equal madrid.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
42
- assert_equal "ES", res.country_code
43
- assert_equal "map_quest", res.provider
39
+ assert_equal 'ES', res.country_code
40
+ assert_equal 'map_quest', res.provider
44
41
 
45
- assert_equal "Madrid", res.city
46
- assert_equal "Comunidad de Madrid", res.state
42
+ assert_equal 'Madrid', res.city
43
+ assert_equal 'Comunidad de Madrid', res.state
47
44
 
48
45
  assert_equal nil, res.country
49
- assert_equal "28014", res.zip
46
+ assert_equal '28014', res.zip
50
47
  assert_equal true, res.success
51
- end
52
48
  end
53
49
  end
@@ -1,44 +1,54 @@
1
- require File.join(File.dirname(__FILE__), "helper")
2
-
3
- Geokit::Geocoders::MapboxGeocoder.key = ""
1
+ require File.join(File.dirname(__FILE__), 'helper')
4
2
 
5
3
  class MapboxGeocoderTest < BaseGeocoderTest #:nodoc: all
6
4
  def setup
5
+ geocoder_class.key = ''
7
6
  super
8
- @address = "1714 14th Street NW, Washington, DC"
7
+ @address = '1714 14th Street NW, Washington, DC'
9
8
  @latlng = Geokit::LatLng.new(38.913175, -77.032458)
10
- @city = "Washington, DC"
9
+ @city = 'Washington, DC'
10
+ @state = 'District of Columbia'
11
+
12
+ geocoder_class.key = @keys['mapbox']['key']
11
13
  end
12
14
 
13
15
  def test_forward_geocode
14
- VCR.use_cassette("mapbox_forward_geocode") do
15
- res = Geokit::Geocoders::MapboxGeocoder.geocode(@address)
16
- assert_equal 38.913184, res.lat
17
- assert_equal(-77.031952, res.lng)
18
- assert_equal "United States", res.country
19
- assert_equal "District of Columbia", res.state
20
- assert_equal "20009", res.zip
21
- end
16
+ res = geocode(@address, :mapbox_forward_geocode)
17
+ assert_equal 38.913184, res.lat
18
+ assert_equal(-77.031952, res.lng)
19
+ assert_equal 'United States', res.country
20
+ assert_equal 'District of Columbia', res.state
21
+ assert_equal '20009', res.zip
22
+ assert_equal 'zip', res.precision
22
23
  end
23
24
 
24
25
  def test_reverse_geocode
25
- VCR.use_cassette("mapbox_reverse_geocode") do
26
- res = Geokit::Geocoders::MapboxGeocoder.reverse_geocode(@latlng)
27
- assert_equal "United States", res.country
28
- assert_equal "District of Columbia", res.state
29
- assert_equal "20009", res.zip
30
- end
26
+ res = reverse_geocode(@latlng, :mapbox_reverse_geocode)
27
+ assert_equal 'United States', res.country
28
+ assert_equal 'District of Columbia', res.state
29
+ assert_equal '20009', res.zip
30
+ assert_equal 'zip', res.precision
31
31
  end
32
32
 
33
33
  def test_city_only
34
- VCR.use_cassette("mapbox_forward_geocode_city_only") do
35
- res = Geokit::Geocoders::MapboxGeocoder.geocode(@city)
36
- assert_equal 38.8951, res.lat
37
- assert_equal(-77.0364, res.lng)
38
- assert_equal "United States", res.country
39
- assert_equal "District of Columbia", res.state
40
- assert_equal "Washington", res.city
41
- assert_equal "20004", res.zip
42
- end
34
+ res = geocode(@city, :mapbox_forward_geocode_city_only)
35
+ assert_equal 38.895, res.lat
36
+ assert_equal(-77.0366, res.lng)
37
+ assert_equal 'United States', res.country
38
+ assert_equal 'District of Columbia', res.state
39
+ assert_equal 'Washington', res.city
40
+ assert_equal '20004', res.zip
41
+ assert_equal 'zip', res.precision
42
+ end
43
+
44
+ def test_state_only
45
+ res = geocode(@state, :mapbox_forward_geocode_state_only)
46
+ assert_equal 38.89657, res.lat
47
+ assert_equal(-76.990661, res.lng)
48
+ assert_equal 'United States', res.country
49
+ assert_equal 'District of Columbia', res.state
50
+ assert_nil res.city
51
+ assert_nil res.zip
52
+ assert_equal 'state', res.precision
43
53
  end
44
54
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "helper")
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  # Test distances from http://www.csgnetwork.com/degreelenllavcalc.html
4
4
  class MappableTest < Test::Unit::TestCase #:nodoc: all
@@ -66,6 +66,6 @@ class MappableTest < Test::Unit::TestCase #:nodoc: all
66
66
  exception = assert_raise(ArgumentError) do
67
67
  TestMappable.get_units!(units: :feet)
68
68
  end
69
- assert_equal "feet is an unsupported unit of length.", exception.message
69
+ assert_equal 'feet is an unsupported unit of length.', exception.message
70
70
  end
71
71
  end
@@ -1,9 +1,9 @@
1
- require File.join(File.dirname(__FILE__), "helper")
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class MaxmindGeocoderTest < BaseGeocoderTest #:nodoc: all
4
4
  def setup
5
5
  super
6
- @ip = "118.210.47.142"
6
+ @ip = '118.210.47.142'
7
7
  end
8
8
 
9
9
  def test_ip_from_autralia
@@ -13,14 +13,14 @@ class MaxmindGeocoderTest < BaseGeocoderTest #:nodoc: all
13
13
  location.expects(:city).with(@ip).returns(city)
14
14
  city.stubs(:latitude).returns(-34.9287)
15
15
  city.stubs(:longitude).returns(138.5986)
16
- city.stubs(:city_name).returns("Adelaide")
17
- city.stubs(:region_name).returns("Australia")
18
- city.stubs(:postal_code).returns("")
19
- city.stubs(:country_code2).returns("AU")
16
+ city.stubs(:city_name).returns('Adelaide')
17
+ city.stubs(:region_name).returns('Australia')
18
+ city.stubs(:postal_code).returns('')
19
+ city.stubs(:country_code2).returns('AU')
20
20
 
21
- res = Geokit::Geocoders::MaxmindGeocoder.geocode(@ip)
22
- assert_equal "Adelaide", res.city
23
- assert_equal "AU", res.country_code
21
+ res = geocode(@ip)
22
+ assert_equal 'Adelaide', res.city
23
+ assert_equal 'AU', res.country_code
24
24
  assert_equal true, res.success
25
25
  assert res.city
26
26
  end
@@ -32,14 +32,14 @@ class MaxmindGeocoderTest < BaseGeocoderTest #:nodoc: all
32
32
  location.expects(:city).with(@ip).returns(city)
33
33
  city.stubs(:latitude).returns(-34)
34
34
  city.stubs(:longitude).returns(-56)
35
- city.stubs(:city_name).returns("Canelones")
36
- city.stubs(:region_name).returns("")
37
- city.stubs(:postal_code).returns("")
38
- city.stubs(:country_code2).returns("UR")
35
+ city.stubs(:city_name).returns('Canelones')
36
+ city.stubs(:region_name).returns('')
37
+ city.stubs(:postal_code).returns('')
38
+ city.stubs(:country_code2).returns('UR')
39
39
 
40
- res = Geokit::Geocoders::MaxmindGeocoder.geocode(@ip)
41
- assert_equal "Canelones", res.city
42
- assert_equal "UR", res.country_code
40
+ res = geocode(@ip)
41
+ assert_equal 'Canelones', res.city
42
+ assert_equal 'UR', res.country_code
43
43
  assert_equal true, res.success
44
44
  assert res.city
45
45
  end