geocoder 1.2.6 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +189 -1
- data/LICENSE +1 -1
- data/README.md +387 -755
- data/examples/autoexpire_cache_redis.rb +5 -3
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +17 -16
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +6 -2
- data/lib/geocoder/calculations.rb +30 -38
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +18 -5
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +19 -0
- data/lib/geocoder/ip_address.rb +16 -11
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +31 -12
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/baidu.rb +17 -9
- data/lib/geocoder/lookups/baidu_ip.rb +7 -31
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/lib/geocoder/lookups/base.rb +73 -25
- data/lib/geocoder/lookups/bing.rb +38 -15
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +55 -8
- data/lib/geocoder/lookups/freegeoip.rb +18 -5
- data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
- data/lib/geocoder/lookups/geocodio.rb +8 -8
- data/lib/geocoder/lookups/geoip2.rb +10 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +37 -9
- data/lib/geocoder/lookups/google_places_details.rb +9 -9
- data/lib/geocoder/lookups/google_places_search.rb +33 -0
- data/lib/geocoder/lookups/google_premier.rb +11 -1
- data/lib/geocoder/lookups/here.rb +29 -23
- data/lib/geocoder/lookups/ip2location.rb +67 -0
- data/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +59 -0
- data/lib/geocoder/lookups/location_iq.rb +50 -0
- data/lib/geocoder/lookups/mapbox.rb +59 -0
- data/lib/geocoder/lookups/mapquest.rb +7 -9
- data/lib/geocoder/lookups/maxmind.rb +7 -7
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +9 -2
- data/lib/geocoder/lookups/nominatim.rb +18 -6
- data/lib/geocoder/lookups/opencagedata.rb +16 -9
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +63 -0
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +14 -13
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +7 -8
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +23 -5
- data/lib/geocoder/lookups/telize.rb +42 -7
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +17 -9
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/models/mongo_base.rb +0 -2
- data/lib/geocoder/query.rb +15 -1
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +103 -14
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +257 -0
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +5 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/esri.rb +30 -6
- data/lib/geocoder/results/freegeoip.rb +2 -7
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geocodio.rb +15 -3
- data/lib/geocoder/results/geoip2.rb +37 -25
- data/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/lib/geocoder/results/google.rb +26 -0
- data/lib/geocoder/results/google_places_details.rb +4 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/here.rb +21 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/lib/geocoder/results/ipregistry.rb +308 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/latlon.rb +71 -0
- data/lib/geocoder/results/location_iq.rb +6 -0
- data/lib/geocoder/results/mapbox.rb +57 -0
- data/lib/geocoder/results/mapquest.rb +5 -8
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/nominatim.rb +18 -3
- data/lib/geocoder/results/opencagedata.rb +20 -2
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/pointpin.rb +0 -4
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +55 -19
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/results/yandex.rb +57 -7
- data/lib/geocoder/sql.rb +9 -6
- data/lib/geocoder/stores/active_record.rb +49 -10
- data/lib/geocoder/stores/base.rb +2 -14
- data/lib/geocoder/stores/mongo_base.rb +0 -31
- data/lib/geocoder/version.rb +1 -1
- data/lib/geocoder.rb +2 -1
- data/lib/hash_recursive_merge.rb +1 -2
- data/lib/maxmind_database.rb +4 -4
- data/lib/tasks/geocoder.rake +29 -4
- metadata +56 -159
- data/.gitignore +0 -6
- data/.travis.yml +0 -31
- data/Rakefile +0 -25
- data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
- data/lib/geocoder/lookups/geocoder_us.rb +0 -39
- data/lib/geocoder/lookups/okf.rb +0 -43
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/lookups/yahoo.rb +0 -88
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -62
- data/lib/geocoder/results/yahoo.rb +0 -55
- data/lib/oauth_util.rb +0 -112
- data/test/fixtures/baidu_invalid_key +0 -1
- data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
- data/test/fixtures/baidu_ip_invalid_key +0 -1
- data/test/fixtures/baidu_ip_no_results +0 -1
- data/test/fixtures/baidu_no_results +0 -1
- data/test/fixtures/baidu_reverse +0 -1
- data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
- data/test/fixtures/bing_invalid_key +0 -1
- data/test/fixtures/bing_madison_square_garden +0 -40
- data/test/fixtures/bing_no_results +0 -16
- data/test/fixtures/bing_reverse +0 -42
- data/test/fixtures/cloudmade_invalid_key +0 -1
- data/test/fixtures/cloudmade_madison_square_garden +0 -1
- data/test/fixtures/cloudmade_no_results +0 -1
- data/test/fixtures/esri_madison_square_garden +0 -59
- data/test/fixtures/esri_no_results +0 -8
- data/test/fixtures/esri_reverse +0 -21
- data/test/fixtures/freegeoip_74_200_247_59 +0 -12
- data/test/fixtures/freegeoip_no_results +0 -1
- data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
- data/test/fixtures/geocoder_ca_no_results +0 -1
- data/test/fixtures/geocoder_ca_reverse +0 -34
- data/test/fixtures/geocoder_us_madison_square_garden +0 -1
- data/test/fixtures/geocoder_us_no_results +0 -1
- data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
- data/test/fixtures/geocodio_bad_api_key +0 -3
- data/test/fixtures/geocodio_invalid +0 -4
- data/test/fixtures/geocodio_no_results +0 -1
- data/test/fixtures/geocodio_over_query_limit +0 -4
- data/test/fixtures/google_garbage +0 -456
- data/test/fixtures/google_madison_square_garden +0 -57
- data/test/fixtures/google_no_city_data +0 -44
- data/test/fixtures/google_no_locality +0 -51
- data/test/fixtures/google_no_results +0 -4
- data/test/fixtures/google_over_limit +0 -4
- data/test/fixtures/google_places_details_invalid_request +0 -4
- data/test/fixtures/google_places_details_madison_square_garden +0 -120
- data/test/fixtures/google_places_details_no_results +0 -4
- data/test/fixtures/google_places_details_no_reviews +0 -60
- data/test/fixtures/google_places_details_no_types +0 -66
- data/test/fixtures/here_madison_square_garden +0 -72
- data/test/fixtures/here_no_results +0 -8
- data/test/fixtures/mapquest_error +0 -16
- data/test/fixtures/mapquest_invalid_api_key +0 -16
- data/test/fixtures/mapquest_invalid_request +0 -16
- data/test/fixtures/mapquest_madison_square_garden +0 -52
- data/test/fixtures/mapquest_no_results +0 -16
- data/test/fixtures/maxmind_24_24_24_21 +0 -1
- data/test/fixtures/maxmind_24_24_24_22 +0 -1
- data/test/fixtures/maxmind_24_24_24_23 +0 -1
- data/test/fixtures/maxmind_24_24_24_24 +0 -1
- data/test/fixtures/maxmind_74_200_247_59 +0 -1
- data/test/fixtures/maxmind_invalid_key +0 -1
- data/test/fixtures/maxmind_no_results +0 -1
- data/test/fixtures/nominatim_madison_square_garden +0 -150
- data/test/fixtures/nominatim_no_results +0 -1
- data/test/fixtures/nominatim_over_limit +0 -1
- data/test/fixtures/okf_kirstinmaki +0 -67
- data/test/fixtures/okf_no_results +0 -4
- data/test/fixtures/opencagedata_invalid_api_key +0 -25
- data/test/fixtures/opencagedata_invalid_request +0 -26
- data/test/fixtures/opencagedata_madison_square_garden +0 -73
- data/test/fixtures/opencagedata_no_results +0 -29
- data/test/fixtures/opencagedata_over_limit +0 -31
- data/test/fixtures/ovi_madison_square_garden +0 -72
- data/test/fixtures/ovi_no_results +0 -8
- data/test/fixtures/pointpin_10_10_10_10 +0 -1
- data/test/fixtures/pointpin_555_555_555_555 +0 -1
- data/test/fixtures/pointpin_80_111_555_555 +0 -1
- data/test/fixtures/pointpin_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
- data/test/fixtures/smarty_streets_11211 +0 -1
- data/test/fixtures/smarty_streets_madison_square_garden +0 -47
- data/test/fixtures/smarty_streets_no_results +0 -1
- data/test/fixtures/telize_10_10_10_10 +0 -1
- data/test/fixtures/telize_555_555_555_555 +0 -4
- data/test/fixtures/telize_74_200_247_59 +0 -1
- data/test/fixtures/telize_no_results +0 -1
- data/test/fixtures/yahoo_error +0 -1
- data/test/fixtures/yahoo_invalid_key +0 -2
- data/test/fixtures/yahoo_madison_square_garden +0 -52
- data/test/fixtures/yahoo_no_results +0 -10
- data/test/fixtures/yahoo_over_limit +0 -2
- data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
- data/test/fixtures/yandex_invalid_key +0 -1
- data/test/fixtures/yandex_kremlin +0 -48
- data/test/fixtures/yandex_new_york +0 -1
- data/test/fixtures/yandex_no_city_and_town +0 -112
- data/test/fixtures/yandex_no_results +0 -16
- data/test/integration/http_client_test.rb +0 -31
- data/test/mongoid_test_helper.rb +0 -43
- data/test/test_helper.rb +0 -416
- data/test/unit/active_record_test.rb +0 -16
- data/test/unit/cache_test.rb +0 -37
- data/test/unit/calculations_test.rb +0 -220
- data/test/unit/configuration_test.rb +0 -55
- data/test/unit/error_handling_test.rb +0 -56
- data/test/unit/geocoder_test.rb +0 -78
- data/test/unit/https_test.rb +0 -17
- data/test/unit/ip_address_test.rb +0 -27
- data/test/unit/lookup_test.rb +0 -153
- data/test/unit/lookups/bing_test.rb +0 -68
- data/test/unit/lookups/dstk_test.rb +0 -26
- data/test/unit/lookups/esri_test.rb +0 -48
- data/test/unit/lookups/freegeoip_test.rb +0 -27
- data/test/unit/lookups/geocoder_ca_test.rb +0 -17
- data/test/unit/lookups/geocodio_test.rb +0 -55
- data/test/unit/lookups/geoip2_test.rb +0 -27
- data/test/unit/lookups/google_places_details_test.rb +0 -122
- data/test/unit/lookups/google_premier_test.rb +0 -22
- data/test/unit/lookups/google_test.rb +0 -84
- data/test/unit/lookups/mapquest_test.rb +0 -60
- data/test/unit/lookups/maxmind_local_test.rb +0 -28
- data/test/unit/lookups/maxmind_test.rb +0 -63
- data/test/unit/lookups/nominatim_test.rb +0 -31
- data/test/unit/lookups/okf_test.rb +0 -38
- data/test/unit/lookups/opencagedata_test.rb +0 -64
- data/test/unit/lookups/pointpin_test.rb +0 -30
- data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
- data/test/unit/lookups/smarty_streets_test.rb +0 -71
- data/test/unit/lookups/telize_test.rb +0 -36
- data/test/unit/lookups/yahoo_test.rb +0 -35
- data/test/unit/method_aliases_test.rb +0 -26
- data/test/unit/model_test.rb +0 -38
- data/test/unit/mongoid_test.rb +0 -47
- data/test/unit/near_test.rb +0 -87
- data/test/unit/oauth_util_test.rb +0 -31
- data/test/unit/proxy_test.rb +0 -37
- data/test/unit/query_test.rb +0 -52
- data/test/unit/rake_task_test.rb +0 -21
- data/test/unit/request_test.rb +0 -35
- data/test/unit/result_test.rb +0 -72
- 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
|
data/test/unit/model_test.rb
DELETED
@@ -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
|
data/test/unit/mongoid_test.rb
DELETED
@@ -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
|
data/test/unit/near_test.rb
DELETED
@@ -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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
require 'cgi'
|
5
|
-
require 'uri'
|
6
|
-
|
7
|
-
class OauthUtilTest < GeocoderTestCase
|
8
|
-
def test_query_string_escapes_single_quote
|
9
|
-
base_url = "http://example.com?location=d'iberville"
|
10
|
-
|
11
|
-
o = OauthUtil.new
|
12
|
-
o.consumer_key = 'consumer_key'
|
13
|
-
o.consumer_secret = 'consumer_secret'
|
14
|
-
|
15
|
-
query_string = o.sign(URI.parse(base_url)).query_string
|
16
|
-
|
17
|
-
assert_match "location=d%27iberville", query_string
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_query_string_sorts_url_keys
|
21
|
-
base_url = "http://example.com?a_param=a&z_param=b&b_param=c&n_param=d"
|
22
|
-
|
23
|
-
o = OauthUtil.new
|
24
|
-
o.consumer_key = 'consumer_key'
|
25
|
-
o.consumer_secret = 'consumer_secret'
|
26
|
-
|
27
|
-
query_string = o.sign(URI.parse(base_url)).query_string
|
28
|
-
|
29
|
-
assert_match(/.*a_param=.*b_param=.*n_param=.*z_param=.*/, query_string)
|
30
|
-
end
|
31
|
-
end
|
data/test/unit/proxy_test.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ProxyTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def test_uses_proxy_when_specified
|
8
|
-
Geocoder.configure(:http_proxy => 'localhost')
|
9
|
-
lookup = Geocoder::Lookup::Google.new
|
10
|
-
assert lookup.send(:http_client).proxy_class?
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_doesnt_use_proxy_when_not_specified
|
14
|
-
lookup = Geocoder::Lookup::Google.new
|
15
|
-
assert !lookup.send(:http_client).proxy_class?
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_exception_raised_on_bad_proxy_url
|
19
|
-
Geocoder.configure(:http_proxy => ' \\_O< Quack Quack')
|
20
|
-
assert_raise Geocoder::ConfigurationError do
|
21
|
-
Geocoder::Lookup::Google.new.send(:http_client)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_accepts_proxy_with_http_protocol
|
26
|
-
Geocoder.configure(:http_proxy => 'http://localhost')
|
27
|
-
lookup = Geocoder::Lookup::Google.new
|
28
|
-
assert lookup.send(:http_client).proxy_class?
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_accepts_proxy_with_https_protocol
|
32
|
-
Geocoder.configure(:https_proxy => 'https://localhost')
|
33
|
-
Geocoder.configure(:use_https => true)
|
34
|
-
lookup = Geocoder::Lookup::Google.new
|
35
|
-
assert lookup.send(:http_client).proxy_class?
|
36
|
-
end
|
37
|
-
end
|
data/test/unit/query_test.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class QueryTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def test_ip_address_detection
|
8
|
-
assert Geocoder::Query.new("232.65.123.94").ip_address?
|
9
|
-
assert Geocoder::Query.new("3ffe:0b00:0000:0000:0001:0000:0000:000a").ip_address?
|
10
|
-
assert !Geocoder::Query.new("232.65.123.94.43").ip_address?
|
11
|
-
assert !Geocoder::Query.new("::ffff:123.456.789").ip_address?
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_blank_query_detection
|
15
|
-
assert Geocoder::Query.new(nil).blank?
|
16
|
-
assert Geocoder::Query.new("").blank?
|
17
|
-
assert Geocoder::Query.new("\t ").blank?
|
18
|
-
assert !Geocoder::Query.new("a").blank?
|
19
|
-
assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
|
20
|
-
assert !Geocoder::Query.new("\na").blank?
|
21
|
-
|
22
|
-
assert Geocoder::Query.new(nil, :params => {}).blank?
|
23
|
-
assert !Geocoder::Query.new(nil, :params => {:woeid => 1234567}).blank?
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_blank_query_detection_for_coordinates
|
27
|
-
assert Geocoder::Query.new([nil,nil]).blank?
|
28
|
-
assert Geocoder::Query.new([87,nil]).blank?
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_coordinates_detection
|
32
|
-
assert Geocoder::Query.new("51.178844,5").coordinates?
|
33
|
-
assert Geocoder::Query.new("51.178844, -1.826189").coordinates?
|
34
|
-
assert !Geocoder::Query.new("232.65.123").coordinates?
|
35
|
-
assert !Geocoder::Query.new("Test\n51.178844, -1.826189").coordinates?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_loopback_ip_address
|
39
|
-
assert Geocoder::Query.new("127.0.0.1").loopback_ip_address?
|
40
|
-
assert !Geocoder::Query.new("232.65.123.234").loopback_ip_address?
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_sanitized_text_with_array
|
44
|
-
q = Geocoder::Query.new([43.1313,11.3131])
|
45
|
-
assert_equal "43.1313,11.3131", q.sanitized_text
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_custom_lookup
|
49
|
-
query = Geocoder::Query.new("address", :lookup => :nominatim)
|
50
|
-
assert_equal Geocoder::Lookup::Nominatim, query.lookup.class
|
51
|
-
end
|
52
|
-
end
|
data/test/unit/rake_task_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RakeTaskTest < GeocoderTestCase
|
6
|
-
def setup
|
7
|
-
Rake.application.rake_require "tasks/geocoder"
|
8
|
-
Rake::Task.define_task(:environment)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_rake_task_geocode_raise_specify_class_message
|
12
|
-
assert_raise(RuntimeError, "Please specify a CLASS (model)") do
|
13
|
-
Rake.application.invoke_task("geocode:all")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_rake_task_geocode_specify_class
|
18
|
-
ENV['CLASS'] = 'Place'
|
19
|
-
assert_nil Rake.application.invoke_task("geocode:all")
|
20
|
-
end
|
21
|
-
end
|