geocoder 1.1.5 → 1.1.6
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.
- data/.travis.yml +4 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +90 -37
- data/README.md +96 -45
- data/examples/autoexpire_cache.rb +1 -3
- data/lib/generators/geocoder/config/templates/initializer.rb +18 -22
- data/lib/geocoder.rb +2 -4
- data/lib/geocoder/cache.rb +2 -1
- data/lib/geocoder/calculations.rb +12 -12
- data/lib/geocoder/cli.rb +10 -11
- data/lib/geocoder/configuration.rb +67 -43
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/exceptions.rb +3 -0
- data/lib/geocoder/lookup.rb +1 -1
- data/lib/geocoder/lookups/base.rb +59 -16
- data/lib/geocoder/lookups/bing.rb +21 -11
- data/lib/geocoder/lookups/freegeoip.rb +8 -4
- data/lib/geocoder/lookups/geocoder_ca.rb +11 -7
- data/lib/geocoder/lookups/google.rb +18 -9
- data/lib/geocoder/lookups/google_premier.rb +16 -8
- data/lib/geocoder/lookups/mapquest.rb +12 -5
- data/lib/geocoder/lookups/maxmind.rb +72 -0
- data/lib/geocoder/lookups/nominatim.rb +13 -8
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/yahoo.rb +38 -11
- data/lib/geocoder/lookups/yandex.rb +17 -9
- data/lib/geocoder/query.rb +17 -8
- data/lib/geocoder/request.rb +7 -1
- data/lib/geocoder/results/google.rb +6 -0
- data/lib/geocoder/results/maxmind.rb +136 -0
- data/lib/geocoder/results/nominatim.rb +0 -10
- data/lib/geocoder/sql.rb +6 -4
- data/lib/geocoder/stores/active_record.rb +5 -5
- data/lib/geocoder/stores/base.rb +3 -2
- data/lib/geocoder/version.rb +1 -1
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/oauth_util.rb +8 -2
- data/test/cache_test.rb +2 -2
- data/test/calculations_test.rb +4 -4
- data/test/configuration_test.rb +26 -51
- data/test/error_handling_test.rb +4 -4
- data/test/fixtures/bing_invalid_key +1 -0
- data/test/fixtures/{bing_madison_square_garden.json → bing_madison_square_garden} +0 -0
- data/test/fixtures/{bing_no_results.json → bing_no_results} +0 -0
- data/test/fixtures/{bing_reverse.json → bing_reverse} +0 -0
- data/test/fixtures/{freegeoip_74_200_247_59.json → freegeoip_74_200_247_59} +0 -0
- data/test/fixtures/{freegeoip_no_results.json → freegeoip_no_results} +0 -0
- data/test/fixtures/{geocoder_ca_madison_square_garden.json → geocoder_ca_madison_square_garden} +0 -0
- data/test/fixtures/{geocoder_ca_no_results.json → geocoder_ca_no_results} +0 -0
- data/test/fixtures/{geocoder_ca_reverse.json → geocoder_ca_reverse} +0 -0
- data/test/fixtures/{google_garbage.json → google_garbage} +0 -0
- data/test/fixtures/{google_madison_square_garden.json → google_madison_square_garden} +0 -0
- data/test/fixtures/{google_no_city_data.json → google_no_city_data} +0 -0
- data/test/fixtures/{google_no_locality.json → google_no_locality} +0 -0
- data/test/fixtures/{google_no_results.json → google_no_results} +0 -0
- data/test/fixtures/{mapquest_madison_square_garden.json → mapquest_madison_square_garden} +0 -0
- data/test/fixtures/{mapquest_no_results.json → mapquest_no_results} +0 -0
- data/test/fixtures/maxmind_24_24_24_21 +1 -0
- data/test/fixtures/maxmind_24_24_24_22 +1 -0
- data/test/fixtures/maxmind_24_24_24_23 +1 -0
- data/test/fixtures/maxmind_24_24_24_24 +1 -0
- data/test/fixtures/maxmind_74_200_247_59 +1 -0
- data/test/fixtures/maxmind_invalid_key +1 -0
- data/test/fixtures/maxmind_no_results +1 -0
- data/test/fixtures/{nominatim_madison_square_garden.json → nominatim_madison_square_garden} +0 -0
- data/test/fixtures/{nominatim_no_results.json → nominatim_no_results} +0 -0
- data/test/fixtures/{yahoo_error.json → yahoo_error} +0 -0
- data/test/fixtures/yahoo_invalid_key +2 -0
- data/test/fixtures/{yahoo_madison_square_garden.json → yahoo_madison_square_garden} +0 -0
- data/test/fixtures/{yahoo_no_results.json → yahoo_no_results} +0 -0
- data/test/fixtures/yahoo_over_limit +2 -0
- data/test/fixtures/{yandex_invalid_key.json → yandex_invalid_key} +0 -0
- data/test/fixtures/{yandex_kremlin.json → yandex_kremlin} +0 -0
- data/test/fixtures/{yandex_no_results.json → yandex_no_results} +0 -0
- data/test/https_test.rb +3 -3
- data/test/integration/smoke_test.rb +2 -2
- data/test/lookup_test.rb +82 -5
- data/test/oauth_util_test.rb +30 -0
- data/test/proxy_test.rb +2 -2
- data/test/query_test.rb +3 -0
- data/test/result_test.rb +2 -2
- data/test/services_test.rb +121 -44
- data/test/test_helper.rb +44 -109
- data/test/test_mode_test.rb +3 -3
- metadata +42 -33
data/test/cache_test.rb
CHANGED
@@ -4,9 +4,9 @@ require 'test_helper'
|
|
4
4
|
class CacheTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def test_second_occurrence_of_request_is_cache_hit
|
7
|
-
Geocoder
|
7
|
+
Geocoder.configure(:cache => {})
|
8
8
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
9
|
-
Geocoder
|
9
|
+
Geocoder.configure(:lookup => l)
|
10
10
|
set_api_key!(l)
|
11
11
|
results = Geocoder.search("Madison Square Garden")
|
12
12
|
assert !results.first.cache_hit,
|
data/test/calculations_test.rb
CHANGED
@@ -3,10 +3,10 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class CalculationsTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
Geocoder.configure
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
Geocoder.configure(
|
7
|
+
:units => :mi,
|
8
|
+
:distances => :linear
|
9
|
+
)
|
10
10
|
end
|
11
11
|
|
12
12
|
# --- degree distance ---
|
data/test/configuration_test.rb
CHANGED
@@ -7,69 +7,44 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_exception_raised_on_bad_lookup_config
|
10
|
-
Geocoder
|
10
|
+
Geocoder.configure(:lookup => :stoopid)
|
11
11
|
assert_raises Geocoder::ConfigurationError do
|
12
12
|
Geocoder.search "something dumb"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
Geocoder
|
19
|
-
|
20
|
-
assert_not_equal 111, distance
|
21
|
-
assert_equal 69, distance
|
22
|
-
|
23
|
-
Geocoder::Configuration.units = :km
|
24
|
-
distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
|
25
|
-
assert_equal 111, distance
|
26
|
-
assert_not_equal 69, distance
|
27
|
-
|
28
|
-
Geocoder::Configuration.distances = :spherical
|
29
|
-
angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
|
30
|
-
assert_equal 136, angle
|
31
|
-
assert_not_equal 130, angle
|
16
|
+
def test_setting_with_class_method
|
17
|
+
Geocoder::Configuration.units = :test
|
18
|
+
assert_equal :test, Geocoder.config.units
|
19
|
+
end
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
assert_equal 130, angle
|
21
|
+
def test_setting_with_configure_method
|
22
|
+
Geocoder.configure(:units => :test)
|
23
|
+
assert_equal :test, Geocoder.config.units
|
37
24
|
end
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
# DSL
|
26
|
+
def test_setting_with_block_syntax
|
27
|
+
orig = $VERBOSE; $VERBOSE = nil
|
42
28
|
Geocoder.configure do |config|
|
43
|
-
config.units
|
44
|
-
config.distances = :linear
|
29
|
+
config.units = :test
|
45
30
|
end
|
31
|
+
assert_equal :test, Geocoder.config.units
|
32
|
+
ensure
|
33
|
+
$VERBOSE = orig
|
34
|
+
end
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
assert_equal
|
56
|
-
|
57
|
-
# Direct
|
58
|
-
Geocoder.configure.units = :km
|
59
|
-
Geocoder.configure.distances = :spherical
|
60
|
-
|
61
|
-
assert_equal Geocoder::Configuration.units, :km
|
62
|
-
distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
|
63
|
-
assert_equal 111, distance
|
64
|
-
assert_not_equal 69, distance
|
65
|
-
|
66
|
-
assert_equal Geocoder::Configuration.distances, :spherical
|
67
|
-
angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
|
68
|
-
assert_equal 136, angle
|
69
|
-
assert_not_equal 130, angle
|
36
|
+
def test_config_for_lookup
|
37
|
+
Geocoder.configure(
|
38
|
+
:timeout => 5,
|
39
|
+
:api_key => "aaa",
|
40
|
+
:google => {
|
41
|
+
:timeout => 2
|
42
|
+
}
|
43
|
+
)
|
44
|
+
assert_equal 2, Geocoder.config_for_lookup(:google).timeout
|
45
|
+
assert_equal "aaa", Geocoder.config_for_lookup(:google).api_key
|
70
46
|
end
|
71
47
|
|
72
|
-
# Geocoder per-model configuration
|
73
48
|
def test_model_configuration
|
74
49
|
Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :km
|
75
50
|
assert_equal :km, Landmark.geocoder_options[:units]
|
@@ -90,7 +65,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
90
65
|
v.longitude = 0
|
91
66
|
|
92
67
|
# method option > global configuration
|
93
|
-
Geocoder.configure
|
68
|
+
Geocoder.configure(:units => :km)
|
94
69
|
assert_equal 69, v.distance_to([0,1], :mi).round
|
95
70
|
|
96
71
|
# per-model configuration > global configuration
|
data/test/error_handling_test.rb
CHANGED
@@ -4,14 +4,14 @@ require 'test_helper'
|
|
4
4
|
class ErrorHandlingTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def teardown
|
7
|
-
Geocoder
|
7
|
+
Geocoder.configure(:always_raise => [])
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_does_not_choke_on_timeout
|
11
11
|
# keep test output clean: suppress timeout warning
|
12
12
|
orig = $VERBOSE; $VERBOSE = nil
|
13
13
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
14
|
-
Geocoder
|
14
|
+
Geocoder.configure(:lookup => l)
|
15
15
|
set_api_key!(l)
|
16
16
|
assert_nothing_raised { Geocoder.search("timeout") }
|
17
17
|
end
|
@@ -20,7 +20,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_always_raise_timeout_error
|
23
|
-
Geocoder
|
23
|
+
Geocoder.configure(:always_raise => [TimeoutError])
|
24
24
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
25
25
|
lookup = Geocoder::Lookup.get(l)
|
26
26
|
set_api_key!(l)
|
@@ -31,7 +31,7 @@ class ErrorHandlingTest < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_always_raise_socket_error
|
34
|
-
Geocoder
|
34
|
+
Geocoder.configure(:always_raise => [SocketError])
|
35
35
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
36
36
|
lookup = Geocoder::Lookup.get(l)
|
37
37
|
set_api_key!(l)
|
@@ -0,0 +1 @@
|
|
1
|
+
{"authenticationResultCode":"InvalidCredentials","brandLogoUri":"http:\\/\\/dev.virtualearth.net\\/Branding\\/logo_powered_by.png","copyright":"Copyright \xC2\xA9 2012 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","errorDetails":["Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."],"resourceSets":[],"statusCode":401,"statusDescription":"Unauthorized","traceId":"5c539f6e70c44b2e858741b6c932318e|EWRM001670|02.00.83.1900|"}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/fixtures/{geocoder_ca_madison_square_garden.json → geocoder_ca_madison_square_garden}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
US,
|
@@ -0,0 +1 @@
|
|
1
|
+
US,NY,Jamaica,40.6915,-73.8057,
|
@@ -0,0 +1 @@
|
|
1
|
+
US,NY,Jamaica,,40.6915,-73.8057,501,718,"Road Runner","Road Runner",
|
@@ -0,0 +1 @@
|
|
1
|
+
US,"United States",NY,"New York",Jamaica,40.6915,-73.8057,501,718,America/New_York,NA,,"Road Runner","Road Runner",rr.com,"AS11351 Road Runner HoldCo LLC",Cable/DSL,residential,779,99,37,76,,
|
@@ -0,0 +1 @@
|
|
1
|
+
US,TX,Plano,75093,33.034698,-96.813400,623,972,"Layered Technologies , US","Layered Technologies , US",
|
@@ -0,0 +1 @@
|
|
1
|
+
,,,,,,,,,,INVALID_LICENSE_KEY
|
@@ -0,0 +1 @@
|
|
1
|
+
,,,,,,,,,,IP_NOT_FOUND
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?> <yahoo:error xmlns:yahoo="http://yahooapis.com/v1/base.rng\ <http://yahooapis.com/v1/base.rng%5C>" xml:lang="en-US">
|
2
|
+
<yahoo:description>Rate Limit Exceeded</yahoo:description> <yahoo:detail>Key has exceeded its configured rate limit.</yahoo:detail> </yahoo:error>
|
File without changes
|
File without changes
|
File without changes
|
data/test/https_test.rb
CHANGED
@@ -4,13 +4,13 @@ require 'test_helper'
|
|
4
4
|
class HttpsTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def test_uses_https_for_secure_query
|
7
|
-
Geocoder
|
7
|
+
Geocoder.configure(:use_https => true)
|
8
8
|
g = Geocoder::Lookup::Google.new
|
9
|
-
assert_match /^https:/, g.
|
9
|
+
assert_match /^https:/, g.query_url(Geocoder::Query.new("test"))
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_uses_http_by_default
|
13
13
|
g = Geocoder::Lookup::Google.new
|
14
|
-
assert_match /^http:/, g.
|
14
|
+
assert_match /^http:/, g.query_url(Geocoder::Query.new("test"))
|
15
15
|
end
|
16
16
|
end
|
@@ -14,13 +14,13 @@ class SmokeTest < Test::Unit::TestCase
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_simple_zip_code_search_with_ssl
|
17
|
-
Geocoder
|
17
|
+
Geocoder.configure(:use_https => true)
|
18
18
|
result = Geocoder.search "27701"
|
19
19
|
assert_not_nil (r = result.first)
|
20
20
|
assert_equal "Durham", r.city
|
21
21
|
assert_equal "North Carolina", r.state
|
22
22
|
ensure
|
23
|
-
Geocoder
|
23
|
+
Geocoder.configure(:use_https => false)
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
data/test/lookup_test.rb
CHANGED
@@ -3,6 +3,14 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class LookupTest < Test::Unit::TestCase
|
5
5
|
|
6
|
+
def test_responds_to_name_method
|
7
|
+
Geocoder::Lookup.all_services.each do |l|
|
8
|
+
lookup = Geocoder::Lookup.get(l)
|
9
|
+
assert lookup.respond_to?(:name),
|
10
|
+
"Lookup #{l} does not respond to #name method."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
def test_search_returns_empty_array_when_no_results
|
7
15
|
Geocoder::Lookup.all_services_except_test.each do |l|
|
8
16
|
lookup = Geocoder::Lookup.get(l)
|
@@ -12,9 +20,67 @@ class LookupTest < Test::Unit::TestCase
|
|
12
20
|
end
|
13
21
|
end
|
14
22
|
|
23
|
+
def test_query_url_contains_values_in_params_hash
|
24
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
25
|
+
next if l == :freegeoip # does not use query string
|
26
|
+
set_api_key!(l)
|
27
|
+
url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
|
28
|
+
"test", :params => {:one_in_the_hand => "two in the bush"}
|
29
|
+
))
|
30
|
+
# should be "+"s for all lookups except Yahoo
|
31
|
+
assert_match /one_in_the_hand=two(%20|\+)in(%20|\+)the(%20|\+)bush/, url,
|
32
|
+
"Lookup #{l} does not appear to support arbitrary params in URL"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
{
|
37
|
+
:bing => :key,
|
38
|
+
:geocoder_ca => :auth,
|
39
|
+
:google => :language,
|
40
|
+
:google_premier => :language,
|
41
|
+
:mapquest => :key,
|
42
|
+
:maxmind => :l,
|
43
|
+
:nominatim => :"accept-language",
|
44
|
+
:yahoo => :locale,
|
45
|
+
:yandex => :plng
|
46
|
+
}.each do |l,p|
|
47
|
+
define_method "test_passing_param_to_#{l}_query_overrides_configuration_value" do
|
48
|
+
set_api_key!(l)
|
49
|
+
url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
|
50
|
+
"test", :params => {p => "xxxx"}
|
51
|
+
))
|
52
|
+
assert_match /#{p}=xxxx/, url,
|
53
|
+
"Param passed to #{l} lookup does not override configuration value"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_raises_exception_on_invalid_key
|
58
|
+
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
|
59
|
+
#Geocoder::Lookup.all_services_except_test.each do |l|
|
60
|
+
[:bing, :yahoo, :yandex, :maxmind].each do |l|
|
61
|
+
lookup = Geocoder::Lookup.get(l)
|
62
|
+
assert_raises Geocoder::InvalidApiKey do
|
63
|
+
lookup.send(:results, Geocoder::Query.new("invalid key"))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_returns_empty_array_on_invalid_key
|
69
|
+
# keep test output clean: suppress timeout warning
|
70
|
+
orig = $VERBOSE; $VERBOSE = nil
|
71
|
+
#Geocoder::Lookup.all_services_except_test.each do |l|
|
72
|
+
[:bing, :yahoo, :yandex, :maxmind].each do |l|
|
73
|
+
Geocoder.configure(:lookup => l)
|
74
|
+
set_api_key!(l)
|
75
|
+
assert_equal [], Geocoder.search("invalid key")
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
$VERBOSE = orig
|
79
|
+
end
|
80
|
+
|
15
81
|
def test_does_not_choke_on_nil_address
|
16
82
|
Geocoder::Lookup.all_services.each do |l|
|
17
|
-
Geocoder
|
83
|
+
Geocoder.configure(:lookup => l)
|
18
84
|
assert_nothing_raised { Venue.new("Venue", nil).geocode }
|
19
85
|
end
|
20
86
|
end
|
@@ -25,15 +91,26 @@ class LookupTest < Test::Unit::TestCase
|
|
25
91
|
end
|
26
92
|
|
27
93
|
def test_google_api_key
|
28
|
-
Geocoder
|
94
|
+
Geocoder.configure(:api_key => "MY_KEY")
|
29
95
|
g = Geocoder::Lookup::Google.new
|
30
|
-
assert_match "key=MY_KEY", g.
|
96
|
+
assert_match "key=MY_KEY", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY 10001, United States"))
|
31
97
|
end
|
32
98
|
|
33
99
|
def test_geocoder_ca_showpostal
|
34
|
-
Geocoder
|
100
|
+
Geocoder.configure(:api_key => "MY_KEY")
|
35
101
|
g = Geocoder::Lookup::GeocoderCa.new
|
36
|
-
assert_match "showpostal=1", g.
|
102
|
+
assert_match "showpostal=1", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY 10001, United States"))
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_raises_configuration_error_on_missing_key
|
106
|
+
assert_raises Geocoder::ConfigurationError do
|
107
|
+
Geocoder.configure(:lookup => :bing, :api_key => nil)
|
108
|
+
Geocoder.search("Madison Square Garden, New York, NY 10001, United States")
|
109
|
+
end
|
37
110
|
end
|
38
111
|
|
112
|
+
def test_handle
|
113
|
+
assert_equal :google, Geocoder::Lookup::Google.new.handle
|
114
|
+
assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle
|
115
|
+
end
|
39
116
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'cgi'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class OauthUtilTest < Test::Unit::TestCase
|
7
|
+
def test_query_string_escapes_single_quote
|
8
|
+
base_url = "http://example.com?location=d'iberville"
|
9
|
+
|
10
|
+
o = OauthUtil.new
|
11
|
+
o.consumer_key = 'consumer_key'
|
12
|
+
o.consumer_secret = 'consumer_secret'
|
13
|
+
|
14
|
+
query_string = o.sign(URI.parse(base_url)).query_string
|
15
|
+
|
16
|
+
assert_match "location=d%27iberville", query_string
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_query_string_sorts_url_keys
|
20
|
+
base_url = "http://example.com?a_param=a&z_param=b&b_param=c&n_param=d"
|
21
|
+
|
22
|
+
o = OauthUtil.new
|
23
|
+
o.consumer_key = 'consumer_key'
|
24
|
+
o.consumer_secret = 'consumer_secret'
|
25
|
+
|
26
|
+
query_string = o.sign(URI.parse(base_url)).query_string
|
27
|
+
|
28
|
+
assert_match /.*a_param=.*b_param=.*n_param=.*z_param=.*/, query_string
|
29
|
+
end
|
30
|
+
end
|
data/test/proxy_test.rb
CHANGED
@@ -4,7 +4,7 @@ require 'test_helper'
|
|
4
4
|
class ProxyTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def test_uses_proxy_when_specified
|
7
|
-
Geocoder
|
7
|
+
Geocoder.configure(:http_proxy => 'localhost')
|
8
8
|
lookup = Geocoder::Lookup::Google.new
|
9
9
|
assert lookup.send(:http_client).proxy_class?
|
10
10
|
end
|
@@ -15,7 +15,7 @@ class ProxyTest < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_exception_raised_on_bad_proxy_url
|
18
|
-
Geocoder
|
18
|
+
Geocoder.configure(:http_proxy => ' \\_O< Quack Quack')
|
19
19
|
assert_raise Geocoder::ConfigurationError do
|
20
20
|
Geocoder::Lookup::Google.new.send(:http_client)
|
21
21
|
end
|
data/test/query_test.rb
CHANGED
@@ -18,6 +18,9 @@ class QueryTest < Test::Unit::TestCase
|
|
18
18
|
assert Geocoder::Query.new("\t ").blank?
|
19
19
|
assert !Geocoder::Query.new("a").blank?
|
20
20
|
assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
|
21
|
+
|
22
|
+
assert Geocoder::Query.new(nil, :params => {}).blank?
|
23
|
+
assert !Geocoder::Query.new(nil, :params => {:woeid => 1234567}).blank?
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_blank_query_detection_for_coordinates
|