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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +31 -28
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/geocoder.rb +1 -0
- data/lib/geocoder/configuration.rb +5 -1
- data/lib/geocoder/exceptions.rb +3 -0
- data/lib/geocoder/ip_address.rb +2 -10
- data/lib/geocoder/logger.rb +55 -0
- data/lib/geocoder/lookup.rb +2 -1
- data/lib/geocoder/lookups/baidu.rb +5 -5
- data/lib/geocoder/lookups/baidu_ip.rb +5 -5
- data/lib/geocoder/lookups/base.rb +21 -16
- data/lib/geocoder/lookups/bing.rb +15 -2
- data/lib/geocoder/lookups/esri.rb +1 -1
- data/lib/geocoder/lookups/geocoder_ca.rb +1 -2
- data/lib/geocoder/lookups/geocodio.rb +3 -3
- data/lib/geocoder/lookups/google.rb +3 -3
- data/lib/geocoder/lookups/google_places_details.rb +3 -3
- data/lib/geocoder/lookups/mapquest.rb +3 -3
- data/lib/geocoder/lookups/maxmind.rb +1 -1
- data/lib/geocoder/lookups/maxmind_geoip2.rb +69 -0
- data/lib/geocoder/lookups/nominatim.rb +1 -1
- data/lib/geocoder/lookups/opencagedata.rb +4 -4
- data/lib/geocoder/lookups/pointpin.rb +4 -4
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +3 -3
- data/lib/geocoder/lookups/yahoo.rb +3 -3
- data/lib/geocoder/lookups/yandex.rb +3 -3
- data/lib/geocoder/query.rb +1 -1
- data/lib/geocoder/request.rb +70 -12
- data/lib/geocoder/results/geoip2.rb +8 -14
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/yandex.rb +5 -5
- data/lib/geocoder/version.rb +1 -1
- metadata +6 -147
- data/.gitignore +0 -6
- data/.travis.yml +0 -32
- data/Rakefile +0 -25
- data/examples/sidekiq_worker.rb +0 -16
- data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
- 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_administrative_area +0 -53
- 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 -423
- 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 -79
- 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 -56
- 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 -81
- data/test/unit/test_mode_test.rb +0 -70
@@ -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
|
data/test/unit/request_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RequestTest < GeocoderTestCase
|
6
|
-
class MockRequest
|
7
|
-
include Geocoder::Request
|
8
|
-
attr_accessor :env, :ip
|
9
|
-
def initialize(env={}, ip="")
|
10
|
-
@env = env
|
11
|
-
@ip = ip
|
12
|
-
end
|
13
|
-
end
|
14
|
-
def test_http_x_real_ip
|
15
|
-
req = MockRequest.new({"HTTP_X_REAL_IP" => "74.200.247.59"})
|
16
|
-
assert req.location.is_a?(Geocoder::Result::Freegeoip)
|
17
|
-
end
|
18
|
-
def test_http_x_forwarded_for_without_proxy
|
19
|
-
req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59"})
|
20
|
-
assert req.location.is_a?(Geocoder::Result::Freegeoip)
|
21
|
-
end
|
22
|
-
def test_http_x_forwarded_for_with_proxy
|
23
|
-
req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59, 74.200.247.59"})
|
24
|
-
assert req.location.is_a?(Geocoder::Result::Freegeoip)
|
25
|
-
end
|
26
|
-
def test_with_request_ip
|
27
|
-
req = MockRequest.new({}, "74.200.247.59")
|
28
|
-
assert req.location.is_a?(Geocoder::Result::Freegeoip)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_with_loopback_x_forwarded_for
|
32
|
-
req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "127.0.0.1"}, "74.200.247.59")
|
33
|
-
assert_equal "US", req.location.country_code
|
34
|
-
end
|
35
|
-
end
|
data/test/unit/result_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ResultTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def test_result_has_required_attributes
|
8
|
-
Geocoder::Lookup.all_services_except_test.each do |l|
|
9
|
-
Geocoder.configure(:lookup => l)
|
10
|
-
set_api_key!(l)
|
11
|
-
result = Geocoder.search([45.423733, -75.676333]).first
|
12
|
-
assert_result_has_required_attributes(result)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_yandex_result_without_city_does_not_raise_exception
|
17
|
-
assert_nothing_raised do
|
18
|
-
Geocoder.configure(:lookup => :yandex)
|
19
|
-
set_api_key!(:yandex)
|
20
|
-
result = Geocoder.search("no city and town").first
|
21
|
-
assert_equal "", result.city
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_yandex_result_without_admin_area_no_exception
|
26
|
-
assert_nothing_raised do
|
27
|
-
Geocoder.configure(:lookup => :yandex)
|
28
|
-
set_api_key!(:yandex)
|
29
|
-
result = Geocoder.search("no administrative area").first
|
30
|
-
assert_equal "", result.city
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_yandex_result_new_york
|
35
|
-
assert_nothing_raised do
|
36
|
-
Geocoder.configure(:lookup => :yandex)
|
37
|
-
set_api_key!(:yandex)
|
38
|
-
result = Geocoder.search("new york").first
|
39
|
-
assert_equal "", result.city
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_yandex_result_kind
|
44
|
-
assert_nothing_raised do
|
45
|
-
Geocoder.configure(:lookup => :yandex)
|
46
|
-
set_api_key!(:yandex)
|
47
|
-
["new york", [45.423733, -75.676333], "no city and town"].each do |query|
|
48
|
-
Geocoder.search("new york").first.kind
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_yandex_result_without_locality_name
|
54
|
-
assert_nothing_raised do
|
55
|
-
Geocoder.configure(:lookup => :yandex)
|
56
|
-
set_api_key!(:yandex)
|
57
|
-
result = Geocoder.search("canada rue dupuis 14")[6]
|
58
|
-
assert_equal "", result.city
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
private # ------------------------------------------------------------------
|
63
|
-
|
64
|
-
def assert_result_has_required_attributes(result)
|
65
|
-
m = "Lookup #{Geocoder.config.lookup} does not support %s attribute."
|
66
|
-
assert result.coordinates.is_a?(Array), m % "coordinates"
|
67
|
-
assert result.latitude.is_a?(Float), m % "latitude"
|
68
|
-
assert result.latitude != 0.0, m % "latitude"
|
69
|
-
assert result.longitude.is_a?(Float), m % "longitude"
|
70
|
-
assert result.longitude != 0.0, m % "longitude"
|
71
|
-
assert result.city.is_a?(String), m % "city"
|
72
|
-
assert result.state.is_a?(String), m % "state"
|
73
|
-
assert result.state_code.is_a?(String), m % "state_code"
|
74
|
-
assert result.province.is_a?(String), m % "province"
|
75
|
-
assert result.province_code.is_a?(String), m % "province_code"
|
76
|
-
assert result.postal_code.is_a?(String), m % "postal_code"
|
77
|
-
assert result.country.is_a?(String), m % "country"
|
78
|
-
assert result.country_code.is_a?(String), m % "country_code"
|
79
|
-
assert_not_nil result.address, m % "address"
|
80
|
-
end
|
81
|
-
end
|
data/test/unit/test_mode_test.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
$: << File.join(File.dirname(__FILE__), "..")
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestModeTest < GeocoderTestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@_original_lookup = Geocoder.config.lookup
|
9
|
-
Geocoder.configure(:lookup => :test)
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
Geocoder::Lookup::Test.reset
|
14
|
-
Geocoder.configure(:lookup => @_original_lookup)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_search_with_known_stub
|
18
|
-
Geocoder::Lookup::Test.add_stub("New York, NY", [mock_attributes])
|
19
|
-
|
20
|
-
results = Geocoder.search("New York, NY")
|
21
|
-
result = results.first
|
22
|
-
|
23
|
-
assert_equal 1, results.size
|
24
|
-
mock_attributes.each_key do |attr|
|
25
|
-
assert_equal mock_attributes[attr], result.send(attr)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_search_with_unknown_stub_without_default
|
30
|
-
assert_raise ArgumentError do
|
31
|
-
Geocoder.search("New York, NY")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_search_with_unknown_stub_with_default
|
36
|
-
Geocoder::Lookup::Test.set_default_stub([mock_attributes])
|
37
|
-
|
38
|
-
results = Geocoder.search("Atlantis, OC")
|
39
|
-
result = results.first
|
40
|
-
|
41
|
-
assert_equal 1, results.size
|
42
|
-
mock_attributes.keys.each do |attr|
|
43
|
-
assert_equal mock_attributes[attr], result.send(attr)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_search_with_custom_attributes
|
48
|
-
custom_attributes = mock_attributes.merge(:custom => 'NY, NY')
|
49
|
-
Geocoder::Lookup::Test.add_stub("New York, NY", [custom_attributes])
|
50
|
-
|
51
|
-
result = Geocoder.search("New York, NY").first
|
52
|
-
|
53
|
-
assert_equal 'NY, NY', result.custom
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
def mock_attributes
|
58
|
-
coordinates = [40.7143528, -74.0059731]
|
59
|
-
@mock_attributes ||= {
|
60
|
-
'coordinates' => coordinates,
|
61
|
-
'latitude' => coordinates[0],
|
62
|
-
'longitude' => coordinates[1],
|
63
|
-
'address' => 'New York, NY, USA',
|
64
|
-
'state' => 'New York',
|
65
|
-
'state_code' => 'NY',
|
66
|
-
'country' => 'United States',
|
67
|
-
'country_code' => 'US',
|
68
|
-
}
|
69
|
-
end
|
70
|
-
end
|