geocoder 1.2.7 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +31 -28
  4. data/examples/reverse_geocode_job.rb +40 -0
  5. data/lib/geocoder.rb +1 -0
  6. data/lib/geocoder/configuration.rb +5 -1
  7. data/lib/geocoder/exceptions.rb +3 -0
  8. data/lib/geocoder/ip_address.rb +2 -10
  9. data/lib/geocoder/logger.rb +55 -0
  10. data/lib/geocoder/lookup.rb +2 -1
  11. data/lib/geocoder/lookups/baidu.rb +5 -5
  12. data/lib/geocoder/lookups/baidu_ip.rb +5 -5
  13. data/lib/geocoder/lookups/base.rb +21 -16
  14. data/lib/geocoder/lookups/bing.rb +15 -2
  15. data/lib/geocoder/lookups/esri.rb +1 -1
  16. data/lib/geocoder/lookups/geocoder_ca.rb +1 -2
  17. data/lib/geocoder/lookups/geocodio.rb +3 -3
  18. data/lib/geocoder/lookups/google.rb +3 -3
  19. data/lib/geocoder/lookups/google_places_details.rb +3 -3
  20. data/lib/geocoder/lookups/mapquest.rb +3 -3
  21. data/lib/geocoder/lookups/maxmind.rb +1 -1
  22. data/lib/geocoder/lookups/maxmind_geoip2.rb +69 -0
  23. data/lib/geocoder/lookups/nominatim.rb +1 -1
  24. data/lib/geocoder/lookups/opencagedata.rb +4 -4
  25. data/lib/geocoder/lookups/pointpin.rb +4 -4
  26. data/lib/geocoder/lookups/postcode_anywhere_uk.rb +3 -3
  27. data/lib/geocoder/lookups/yahoo.rb +3 -3
  28. data/lib/geocoder/lookups/yandex.rb +3 -3
  29. data/lib/geocoder/query.rb +1 -1
  30. data/lib/geocoder/request.rb +70 -12
  31. data/lib/geocoder/results/geoip2.rb +8 -14
  32. data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
  33. data/lib/geocoder/results/yandex.rb +5 -5
  34. data/lib/geocoder/version.rb +1 -1
  35. metadata +6 -147
  36. data/.gitignore +0 -6
  37. data/.travis.yml +0 -32
  38. data/Rakefile +0 -25
  39. data/examples/sidekiq_worker.rb +0 -16
  40. data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
  41. data/test/fixtures/baidu_invalid_key +0 -1
  42. data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
  43. data/test/fixtures/baidu_ip_invalid_key +0 -1
  44. data/test/fixtures/baidu_ip_no_results +0 -1
  45. data/test/fixtures/baidu_no_results +0 -1
  46. data/test/fixtures/baidu_reverse +0 -1
  47. data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
  48. data/test/fixtures/bing_invalid_key +0 -1
  49. data/test/fixtures/bing_madison_square_garden +0 -40
  50. data/test/fixtures/bing_no_results +0 -16
  51. data/test/fixtures/bing_reverse +0 -42
  52. data/test/fixtures/cloudmade_invalid_key +0 -1
  53. data/test/fixtures/cloudmade_madison_square_garden +0 -1
  54. data/test/fixtures/cloudmade_no_results +0 -1
  55. data/test/fixtures/esri_madison_square_garden +0 -59
  56. data/test/fixtures/esri_no_results +0 -8
  57. data/test/fixtures/esri_reverse +0 -21
  58. data/test/fixtures/freegeoip_74_200_247_59 +0 -12
  59. data/test/fixtures/freegeoip_no_results +0 -1
  60. data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
  61. data/test/fixtures/geocoder_ca_no_results +0 -1
  62. data/test/fixtures/geocoder_ca_reverse +0 -34
  63. data/test/fixtures/geocoder_us_madison_square_garden +0 -1
  64. data/test/fixtures/geocoder_us_no_results +0 -1
  65. data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
  66. data/test/fixtures/geocodio_bad_api_key +0 -3
  67. data/test/fixtures/geocodio_invalid +0 -4
  68. data/test/fixtures/geocodio_no_results +0 -1
  69. data/test/fixtures/geocodio_over_query_limit +0 -4
  70. data/test/fixtures/google_garbage +0 -456
  71. data/test/fixtures/google_madison_square_garden +0 -57
  72. data/test/fixtures/google_no_city_data +0 -44
  73. data/test/fixtures/google_no_locality +0 -51
  74. data/test/fixtures/google_no_results +0 -4
  75. data/test/fixtures/google_over_limit +0 -4
  76. data/test/fixtures/google_places_details_invalid_request +0 -4
  77. data/test/fixtures/google_places_details_madison_square_garden +0 -120
  78. data/test/fixtures/google_places_details_no_results +0 -4
  79. data/test/fixtures/google_places_details_no_reviews +0 -60
  80. data/test/fixtures/google_places_details_no_types +0 -66
  81. data/test/fixtures/here_madison_square_garden +0 -72
  82. data/test/fixtures/here_no_results +0 -8
  83. data/test/fixtures/mapquest_error +0 -16
  84. data/test/fixtures/mapquest_invalid_api_key +0 -16
  85. data/test/fixtures/mapquest_invalid_request +0 -16
  86. data/test/fixtures/mapquest_madison_square_garden +0 -52
  87. data/test/fixtures/mapquest_no_results +0 -16
  88. data/test/fixtures/maxmind_24_24_24_21 +0 -1
  89. data/test/fixtures/maxmind_24_24_24_22 +0 -1
  90. data/test/fixtures/maxmind_24_24_24_23 +0 -1
  91. data/test/fixtures/maxmind_24_24_24_24 +0 -1
  92. data/test/fixtures/maxmind_74_200_247_59 +0 -1
  93. data/test/fixtures/maxmind_invalid_key +0 -1
  94. data/test/fixtures/maxmind_no_results +0 -1
  95. data/test/fixtures/nominatim_madison_square_garden +0 -150
  96. data/test/fixtures/nominatim_no_results +0 -1
  97. data/test/fixtures/nominatim_over_limit +0 -1
  98. data/test/fixtures/okf_kirstinmaki +0 -67
  99. data/test/fixtures/okf_no_results +0 -4
  100. data/test/fixtures/opencagedata_invalid_api_key +0 -25
  101. data/test/fixtures/opencagedata_invalid_request +0 -26
  102. data/test/fixtures/opencagedata_madison_square_garden +0 -73
  103. data/test/fixtures/opencagedata_no_results +0 -29
  104. data/test/fixtures/opencagedata_over_limit +0 -31
  105. data/test/fixtures/ovi_madison_square_garden +0 -72
  106. data/test/fixtures/ovi_no_results +0 -8
  107. data/test/fixtures/pointpin_10_10_10_10 +0 -1
  108. data/test/fixtures/pointpin_555_555_555_555 +0 -1
  109. data/test/fixtures/pointpin_80_111_555_555 +0 -1
  110. data/test/fixtures/pointpin_no_results +0 -1
  111. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
  112. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
  113. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
  114. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
  115. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
  116. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
  117. data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
  118. data/test/fixtures/smarty_streets_11211 +0 -1
  119. data/test/fixtures/smarty_streets_madison_square_garden +0 -47
  120. data/test/fixtures/smarty_streets_no_results +0 -1
  121. data/test/fixtures/telize_10_10_10_10 +0 -1
  122. data/test/fixtures/telize_555_555_555_555 +0 -4
  123. data/test/fixtures/telize_74_200_247_59 +0 -1
  124. data/test/fixtures/telize_no_results +0 -1
  125. data/test/fixtures/yahoo_error +0 -1
  126. data/test/fixtures/yahoo_invalid_key +0 -2
  127. data/test/fixtures/yahoo_madison_square_garden +0 -52
  128. data/test/fixtures/yahoo_no_results +0 -10
  129. data/test/fixtures/yahoo_over_limit +0 -2
  130. data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
  131. data/test/fixtures/yandex_invalid_key +0 -1
  132. data/test/fixtures/yandex_kremlin +0 -48
  133. data/test/fixtures/yandex_new_york +0 -1
  134. data/test/fixtures/yandex_no_administrative_area +0 -53
  135. data/test/fixtures/yandex_no_city_and_town +0 -112
  136. data/test/fixtures/yandex_no_results +0 -16
  137. data/test/integration/http_client_test.rb +0 -31
  138. data/test/mongoid_test_helper.rb +0 -43
  139. data/test/test_helper.rb +0 -423
  140. data/test/unit/active_record_test.rb +0 -16
  141. data/test/unit/cache_test.rb +0 -37
  142. data/test/unit/calculations_test.rb +0 -220
  143. data/test/unit/configuration_test.rb +0 -55
  144. data/test/unit/error_handling_test.rb +0 -79
  145. data/test/unit/geocoder_test.rb +0 -78
  146. data/test/unit/https_test.rb +0 -17
  147. data/test/unit/ip_address_test.rb +0 -27
  148. data/test/unit/lookup_test.rb +0 -153
  149. data/test/unit/lookups/bing_test.rb +0 -68
  150. data/test/unit/lookups/dstk_test.rb +0 -26
  151. data/test/unit/lookups/esri_test.rb +0 -48
  152. data/test/unit/lookups/freegeoip_test.rb +0 -27
  153. data/test/unit/lookups/geocoder_ca_test.rb +0 -17
  154. data/test/unit/lookups/geocodio_test.rb +0 -56
  155. data/test/unit/lookups/geoip2_test.rb +0 -27
  156. data/test/unit/lookups/google_places_details_test.rb +0 -122
  157. data/test/unit/lookups/google_premier_test.rb +0 -22
  158. data/test/unit/lookups/google_test.rb +0 -84
  159. data/test/unit/lookups/mapquest_test.rb +0 -60
  160. data/test/unit/lookups/maxmind_local_test.rb +0 -28
  161. data/test/unit/lookups/maxmind_test.rb +0 -63
  162. data/test/unit/lookups/nominatim_test.rb +0 -31
  163. data/test/unit/lookups/okf_test.rb +0 -38
  164. data/test/unit/lookups/opencagedata_test.rb +0 -64
  165. data/test/unit/lookups/pointpin_test.rb +0 -30
  166. data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
  167. data/test/unit/lookups/smarty_streets_test.rb +0 -71
  168. data/test/unit/lookups/telize_test.rb +0 -36
  169. data/test/unit/lookups/yahoo_test.rb +0 -35
  170. data/test/unit/method_aliases_test.rb +0 -26
  171. data/test/unit/model_test.rb +0 -38
  172. data/test/unit/mongoid_test.rb +0 -47
  173. data/test/unit/near_test.rb +0 -87
  174. data/test/unit/oauth_util_test.rb +0 -31
  175. data/test/unit/proxy_test.rb +0 -37
  176. data/test/unit/query_test.rb +0 -52
  177. data/test/unit/rake_task_test.rb +0 -21
  178. data/test/unit/request_test.rb +0 -35
  179. data/test/unit/result_test.rb +0 -81
  180. data/test/unit/test_mode_test.rb +0 -70
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..", "..")
3
- require 'test_helper'
4
-
5
- class OpencagedataTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(lookup: :opencagedata)
9
- set_api_key!(:opencagedata)
10
- end
11
-
12
- def test_result_components
13
- result = Geocoder.search("Madison Square Garden, New York, NY").first
14
- assert_equal "West 31st Street", result.street
15
- assert_match /46, West 31st Street, Koreatown, New York County, 10011, New York City, New York, United States of America/, result.address
16
-
17
- end
18
-
19
- def test_opencagedata_query_url_contains_bounds
20
- lookup = Geocoder::Lookup::Opencagedata.new
21
- url = lookup.query_url(Geocoder::Query.new(
22
- "Some street",
23
- :bounds => [[40.0, -120.0], [39.0, -121.0]]
24
- ))
25
- assert_match(/bounds=40.0+%2C-120.0+%2C39.0+%2C-121.0+/, url)
26
- end
27
-
28
-
29
- def test_no_results
30
- results = Geocoder.search("no results")
31
- assert_equal 0, results.length
32
- end
33
-
34
-
35
- def test_opencagedata_reverse_url
36
- query = Geocoder::Query.new([45.423733, -75.676333])
37
- assert_match /\bq=45.423733%2C-75.676333\b/, query.url
38
- end
39
-
40
-
41
-
42
- def test_raises_exception_when_invalid_request
43
- Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
44
- assert_raises Geocoder::InvalidRequest do
45
- Geocoder.search("invalid request")
46
- end
47
- end
48
-
49
- def test_raises_exception_when_invalid_api_key
50
- Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
51
- assert_raises Geocoder::InvalidApiKey do
52
- Geocoder.search("invalid api key")
53
- end
54
- end
55
-
56
-
57
- def test_raises_exception_when_over_query_limit
58
- Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
59
- l = Geocoder::Lookup.get(:opencagedata)
60
- assert_raises Geocoder::OverQueryLimitError do
61
- l.send(:results, Geocoder::Query.new("over limit"))
62
- end
63
- end
64
- end
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..", "..")
3
- require 'test_helper'
4
-
5
- class PointpinTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(ip_lookup: :pointpin, api_key: "abc123")
9
- end
10
-
11
- def test_result_on_ip_address_search
12
- result = Geocoder.search("80.111.555.555").first
13
- assert result.is_a?(Geocoder::Result::Pointpin)
14
- end
15
-
16
- def test_result_components
17
- result = Geocoder.search("80.111.555.555").first
18
- assert_equal "Dublin, Dublin City, 8, Ireland", result.address
19
- end
20
-
21
- def test_no_results
22
- results = Geocoder.search("10.10.10.10")
23
- assert_equal 0, results.length
24
- end
25
-
26
- def test_invalid_address
27
- results = Geocoder.search("555.555.555.555")
28
- assert_equal 0, results.length
29
- end
30
- end
@@ -1,70 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), '..', '..')
3
- require 'test_helper'
4
-
5
- class PostcodeAnywhereUkTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(lookup: :postcode_anywhere_uk)
9
- set_api_key!(:postcode_anywhere_uk)
10
- end
11
-
12
- def test_result_components_with_placename_search
13
- results = Geocoder.search('Romsey')
14
-
15
- assert_equal 1, results.size
16
- assert_equal 'Romsey, Hampshire', results.first.address
17
- assert_equal 'SU 35270 21182', results.first.os_grid
18
- assert_equal [50.9889, -1.4989], results.first.coordinates
19
- assert_equal 'Romsey', results.first.city
20
- end
21
-
22
- def test_result_components_with_postcode
23
- results = Geocoder.search('WR26NJ')
24
-
25
- assert_equal 1, results.size
26
- assert_equal 'Moseley Road, Hallow, Worcester', results.first.address
27
- assert_equal 'SO 81676 59425', results.first.os_grid
28
- assert_equal [52.2327, -2.2697], results.first.coordinates
29
- assert_equal 'Hallow', results.first.city
30
- end
31
-
32
- def test_result_components_with_county
33
- results = Geocoder.search('hampshire')
34
-
35
- assert_equal 1, results.size
36
- assert_equal 'Hampshire', results.first.address
37
- assert_equal 'SU 48701 26642', results.first.os_grid
38
- assert_equal [51.037, -1.3068], results.first.coordinates
39
- assert_equal '', results.first.city
40
- end
41
-
42
- def test_no_results
43
- assert_equal [], Geocoder.search('no results')
44
- end
45
-
46
- def test_key_limit_exceeded_error
47
- Geocoder.configure(always_raise: [Geocoder::OverQueryLimitError])
48
-
49
- assert_raises Geocoder::OverQueryLimitError do
50
- Geocoder.search('key limit exceeded')
51
- end
52
- end
53
-
54
- def test_unknown_key_error
55
- Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
56
-
57
- assert_raises Geocoder::InvalidApiKey do
58
- Geocoder.search('unknown key')
59
- end
60
- end
61
-
62
- def test_generic_error
63
- Geocoder.configure(always_raise: [Geocoder::Error])
64
-
65
- exception = assert_raises(Geocoder::Error) do
66
- Geocoder.search('generic error')
67
- end
68
- assert_equal 'A generic error occured.', exception.message
69
- end
70
- end
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..", "..")
3
- require 'test_helper'
4
-
5
- class SmartyStreetsTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(lookup: :smarty_streets)
9
- set_api_key!(:smarty_streets)
10
- end
11
-
12
- def test_url_contains_api_key
13
- Geocoder.configure(:smarty_streets => {:api_key => 'blah'})
14
- query = Geocoder::Query.new("Bluffton, SC")
15
- assert_equal "http://api.smartystreets.com/street-address?auth-token=blah&street=Bluffton%2C+SC", query.url
16
- end
17
-
18
- def test_query_for_address_geocode
19
- query = Geocoder::Query.new("42 Wallaby Way Sydney, AU")
20
- assert_match /api\.smartystreets\.com\/street-address\?/, query.url
21
- end
22
-
23
- def test_query_for_zipcode_geocode
24
- query = Geocoder::Query.new("22204")
25
- assert_match /api\.smartystreets\.com\/zipcode\?/, query.url
26
- end
27
-
28
- def test_query_for_zipfour_geocode
29
- query = Geocoder::Query.new("22204-1603")
30
- assert_match /api\.smartystreets\.com\/zipcode\?/, query.url
31
- end
32
-
33
- def test_smarty_streets_result_components
34
- result = Geocoder.search("Madison Square Garden, New York, NY").first
35
- assert_equal "Penn", result.street
36
- assert_equal "10121", result.zipcode
37
- assert_equal "1703", result.zip4
38
- assert_equal "New York", result.city
39
- assert_equal "36061", result.fips
40
- assert !result.zipcode_endpoint?
41
- end
42
-
43
- def test_smarty_streets_result_components_with_zipcode_only_query
44
- result = Geocoder.search("11211").first
45
- assert_equal "Brooklyn", result.city
46
- assert_equal "New York", result.state
47
- assert_equal "NY", result.state_code
48
- assert result.zipcode_endpoint?
49
- end
50
-
51
- def test_no_results
52
- results = Geocoder.search("no results")
53
- assert_equal 0, results.length
54
- end
55
-
56
- def test_raises_exception_on_error_http_status
57
- error_statuses = {
58
- '400' => Geocoder::InvalidRequest,
59
- '401' => Geocoder::RequestDenied,
60
- '402' => Geocoder::OverQueryLimitError
61
- }
62
- Geocoder.configure(always_raise: error_statuses.values)
63
- lookup = Geocoder::Lookup.get(:smarty_streets)
64
- error_statuses.each do |code, err|
65
- assert_raises err do
66
- response = MockHttpResponse.new(code: code.to_i)
67
- lookup.send(:check_response_for_errors!, response)
68
- end
69
- end
70
- end
71
- end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..", "..")
3
- require 'test_helper'
4
-
5
- class TelizeTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(ip_lookup: :telize)
9
- end
10
-
11
- def test_result_on_ip_address_search
12
- result = Geocoder.search("74.200.247.59").first
13
- assert result.is_a?(Geocoder::Result::Telize)
14
- end
15
-
16
- def test_result_components
17
- result = Geocoder.search("74.200.247.59").first
18
- assert_equal "Plano, TX 75093, United States", result.address
19
- end
20
-
21
- def test_no_results
22
- results = Geocoder.search("10.10.10.10")
23
- assert_equal 0, results.length
24
- end
25
-
26
- def test_invalid_address
27
- results = Geocoder.search("555.555.555.555")
28
- assert_equal 0, results.length
29
- end
30
-
31
- def test_uses_http_even_if_use_https_true
32
- Geocoder.configure(use_https: true)
33
- result = Geocoder.search("74.200.247.59").first
34
- assert result.is_a?(Geocoder::Result::Telize)
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..", "..")
3
- require 'test_helper'
4
-
5
- class YahooTest < GeocoderTestCase
6
-
7
- def setup
8
- Geocoder.configure(lookup: :yahoo)
9
- set_api_key!(:yahoo)
10
- end
11
-
12
- def test_no_results
13
- assert_equal [], Geocoder.search("no results")
14
- end
15
-
16
- def test_error
17
- silence_warnings do
18
- assert_equal [], Geocoder.search("error")
19
- end
20
- end
21
-
22
- def test_result_components
23
- result = Geocoder.search("madison square garden").first
24
- assert_equal "10001", result.postal_code
25
- assert_equal "Madison Square Garden, New York, NY 10001, United States", result.address
26
- end
27
-
28
- def test_raises_exception_when_over_query_limit
29
- Geocoder.configure(:always_raise => [Geocoder::OverQueryLimitError])
30
- l = Geocoder::Lookup.get(:yahoo)
31
- assert_raises Geocoder::OverQueryLimitError do
32
- l.send(:results, Geocoder::Query.new("over limit"))
33
- end
34
- end
35
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..")
3
- require 'test_helper'
4
-
5
- class MethodAliasesTest < GeocoderTestCase
6
-
7
- def test_distance_from_is_alias_for_distance_to
8
- v = Place.new(*geocoded_object_params(:msg))
9
- v.latitude, v.longitude = [40.750354, -73.993371]
10
- assert_equal v.distance_from([30, -94]), v.distance_to([30, -94])
11
- end
12
-
13
- def test_fetch_coordinates_is_alias_for_geocode
14
- v = Place.new(*geocoded_object_params(:msg))
15
- coords = [40.750354, -73.993371]
16
- assert_equal coords, v.fetch_coordinates
17
- assert_equal coords, [v.latitude, v.longitude]
18
- end
19
-
20
- def test_fetch_address_is_alias_for_reverse_geocode
21
- v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg))
22
- address = "4 Penn Plaza, New York, NY 10001, USA"
23
- assert_equal address, v.fetch_address
24
- assert_equal address, v.address
25
- end
26
- end
@@ -1,38 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..")
3
- require 'test_helper'
4
-
5
- class ModelTest < GeocoderTestCase
6
-
7
- def test_geocode_with_block_runs_block
8
- e = PlaceWithCustomResultsHandling.new(*geocoded_object_params(:msg))
9
- coords = [40.750354, -73.993371]
10
- e.geocode
11
- assert_equal coords.map{ |c| c.to_s }.join(','), e.coords_string
12
- end
13
-
14
- def test_geocode_with_block_doesnt_auto_assign_coordinates
15
- e = PlaceWithCustomResultsHandling.new(*geocoded_object_params(:msg))
16
- e.geocode
17
- assert_nil e.latitude
18
- assert_nil e.longitude
19
- end
20
-
21
- def test_reverse_geocode_with_block_runs_block
22
- e = PlaceReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg))
23
- e.reverse_geocode
24
- assert_equal "US", e.country
25
- end
26
-
27
- def test_reverse_geocode_with_block_doesnt_auto_assign_address
28
- e = PlaceReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg))
29
- e.reverse_geocode
30
- assert_nil e.address
31
- end
32
-
33
- def test_units_and_method
34
- PlaceReverseGeocoded.reverse_geocoded_by :latitude, :longitude, method: :spherical, units: :km
35
- assert_equal :km, PlaceReverseGeocoded.geocoder_options[:units]
36
- assert_equal :spherical, PlaceReverseGeocoded.geocoder_options[:method]
37
- end
38
- end
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..")
3
- require 'mongoid_test_helper'
4
-
5
- class MongoidTest < GeocoderTestCase
6
- def test_geocoded_check
7
- p = PlaceUsingMongoid.new(*geocoded_object_params(:msg))
8
- p.location = [40.750354, -73.993371]
9
- assert p.geocoded?
10
- end
11
-
12
- def test_distance_to_returns_float
13
- p = PlaceUsingMongoid.new(*geocoded_object_params(:msg))
14
- p.location = [40.750354, -73.993371]
15
- assert p.distance_to([30, -94]).is_a?(Float)
16
- end
17
-
18
- def test_custom_coordinate_field_near_scope
19
- location = [40.750354, -73.993371]
20
- p = PlaceUsingMongoid.near(location)
21
- key = Mongoid::VERSION >= "3" ? "location" : :location
22
- assert_equal p.selector[key]['$nearSphere'], location.reverse
23
- end
24
-
25
- def test_model_configuration
26
- p = PlaceUsingMongoid.new(*geocoded_object_params(:msg))
27
- p.location = [0, 0]
28
-
29
- PlaceUsingMongoid.geocoded_by :address, :coordinates => :location, :units => :km
30
- assert_equal 111, p.distance_to([0,1]).round
31
-
32
- PlaceUsingMongoid.geocoded_by :address, :coordinates => :location, :units => :mi
33
- assert_equal 69, p.distance_to([0,1]).round
34
- end
35
-
36
- def test_index_is_skipped_if_skip_option_flag
37
- result = PlaceUsingMongoidWithoutIndex.index_options.keys.flatten[0] == :coordinates
38
- assert !result
39
- end
40
-
41
- def test_nil_radius_omits_max_distance
42
- location = [40.750354, -73.993371]
43
- p = PlaceUsingMongoid.near(location, nil)
44
- key = Mongoid::VERSION >= "3" ? "location" : :location
45
- assert_equal nil, p.selector[key]['$maxDistance']
46
- end
47
- end
@@ -1,87 +0,0 @@
1
- # encoding: utf-8
2
- $: << File.join(File.dirname(__FILE__), "..")
3
- require 'test_helper'
4
-
5
- class NearTest < GeocoderTestCase
6
-
7
- def test_near_scope_options_without_sqlite_includes_bounding_box_condition
8
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5)
9
- assert_match(/test_table_name.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND test_table_name.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /, result[:conditions][0])
10
- end
11
-
12
- def test_near_scope_options_without_sqlite_includes_radius_condition
13
- result = Place.send(:near_scope_options, 1.0, 2.0, 5)
14
- assert_match(/BETWEEN \? AND \?$/, result[:conditions][0])
15
- end
16
-
17
- def test_near_scope_options_without_sqlite_includes_radius_default_min_radius
18
- result = Place.send(:near_scope_options, 1.0, 2.0, 5)
19
-
20
- assert_equal(0, result[:conditions][1])
21
- assert_equal(5, result[:conditions][2])
22
- end
23
-
24
- def test_near_scope_options_without_sqlite_includes_radius_custom_min_radius
25
- result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 3)
26
-
27
- assert_equal(3, result[:conditions][1])
28
- assert_equal(5, result[:conditions][2])
29
- end
30
-
31
- def test_near_scope_options_without_sqlite_includes_radius_bogus_min_radius
32
- result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 'bogus')
33
-
34
- assert_equal(0, result[:conditions][1])
35
- assert_equal(5, result[:conditions][2])
36
- end
37
-
38
- def test_near_scope_options_with_defaults
39
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5)
40
-
41
- assert_match(/AS distance/, result[:select])
42
- assert_match(/AS bearing/, result[:select])
43
- assert_no_consecutive_comma(result[:select])
44
- end
45
-
46
- def test_near_scope_options_with_no_distance
47
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5, :select_distance => false)
48
-
49
- assert_no_match(/AS distance/, result[:select])
50
- assert_match(/AS bearing/, result[:select])
51
- assert_no_match(/distance/, result[:condition])
52
- assert_no_match(/distance/, result[:order])
53
- assert_no_consecutive_comma(result[:select])
54
- end
55
-
56
- def test_near_scope_options_with_no_bearing
57
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5, :select_bearing => false)
58
-
59
- assert_match(/AS distance/, result[:select])
60
- assert_no_match(/AS bearing/, result[:select])
61
- assert_no_consecutive_comma(result[:select])
62
- end
63
-
64
- def test_near_scope_options_with_custom_distance_column
65
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5, :distance_column => 'calculated_distance')
66
-
67
- assert_no_match(/AS distance/, result[:select])
68
- assert_match(/AS calculated_distance/, result[:select])
69
- assert_no_match(/\bdistance\b/, result[:order])
70
- assert_match(/calculated_distance/, result[:order])
71
- assert_no_consecutive_comma(result[:select])
72
- end
73
-
74
- def test_near_scope_options_with_custom_bearing_column
75
- result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5, :bearing_column => 'calculated_bearing')
76
-
77
- assert_no_match(/AS bearing/, result[:select])
78
- assert_match(/AS calculated_bearing/, result[:select])
79
- assert_no_consecutive_comma(result[:select])
80
- end
81
-
82
- private
83
-
84
- def assert_no_consecutive_comma(string)
85
- assert_no_match(/, *,/, string, "two consecutive commas")
86
- end
87
- end