geocoder-sgonyea 1.1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +298 -0
- data/LICENSE +20 -0
- data/README.md +656 -0
- data/Rakefile +25 -0
- data/bin/geocode +5 -0
- data/examples/autoexpire_cache.rb +28 -0
- data/gemfiles/Gemfile.mongoid-2.4.x +15 -0
- data/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +21 -0
- data/lib/geocoder.rb +55 -0
- data/lib/geocoder/cache.rb +85 -0
- data/lib/geocoder/calculations.rb +319 -0
- data/lib/geocoder/cli.rb +114 -0
- data/lib/geocoder/configuration.rb +130 -0
- data/lib/geocoder/configuration_hash.rb +11 -0
- data/lib/geocoder/exceptions.rb +21 -0
- data/lib/geocoder/lookup.rb +82 -0
- data/lib/geocoder/lookups/base.rb +250 -0
- data/lib/geocoder/lookups/bing.rb +47 -0
- data/lib/geocoder/lookups/freegeoip.rb +47 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +54 -0
- data/lib/geocoder/lookups/google.rb +62 -0
- data/lib/geocoder/lookups/google_premier.rb +47 -0
- data/lib/geocoder/lookups/mapquest.rb +43 -0
- data/lib/geocoder/lookups/maxmind.rb +88 -0
- data/lib/geocoder/lookups/nominatim.rb +45 -0
- data/lib/geocoder/lookups/ovi.rb +52 -0
- data/lib/geocoder/lookups/test.rb +38 -0
- data/lib/geocoder/lookups/yahoo.rb +84 -0
- data/lib/geocoder/lookups/yandex.rb +54 -0
- data/lib/geocoder/models/active_record.rb +46 -0
- data/lib/geocoder/models/base.rb +42 -0
- data/lib/geocoder/models/mongo_base.rb +60 -0
- data/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/lib/geocoder/models/mongoid.rb +32 -0
- data/lib/geocoder/query.rb +103 -0
- data/lib/geocoder/railtie.rb +26 -0
- data/lib/geocoder/request.rb +23 -0
- data/lib/geocoder/results/base.rb +67 -0
- data/lib/geocoder/results/bing.rb +48 -0
- data/lib/geocoder/results/freegeoip.rb +45 -0
- data/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/lib/geocoder/results/google.rb +106 -0
- data/lib/geocoder/results/google_premier.rb +6 -0
- data/lib/geocoder/results/mapquest.rb +51 -0
- data/lib/geocoder/results/maxmind.rb +136 -0
- data/lib/geocoder/results/nominatim.rb +94 -0
- data/lib/geocoder/results/ovi.rb +62 -0
- data/lib/geocoder/results/test.rb +16 -0
- data/lib/geocoder/results/yahoo.rb +55 -0
- data/lib/geocoder/results/yandex.rb +80 -0
- data/lib/geocoder/sql.rb +106 -0
- data/lib/geocoder/stores/active_record.rb +259 -0
- data/lib/geocoder/stores/base.rb +120 -0
- data/lib/geocoder/stores/mongo_base.rb +85 -0
- data/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/lib/geocoder/stores/mongoid.rb +13 -0
- data/lib/geocoder/version.rb +3 -0
- data/lib/hash_recursive_merge.rb +74 -0
- data/lib/oauth_util.rb +112 -0
- data/lib/tasks/geocoder.rake +25 -0
- data/test/active_record_test.rb +15 -0
- data/test/cache_test.rb +19 -0
- data/test/calculations_test.rb +195 -0
- data/test/configuration_test.rb +78 -0
- data/test/custom_block_test.rb +32 -0
- data/test/error_handling_test.rb +43 -0
- data/test/fixtures/bing_invalid_key +1 -0
- data/test/fixtures/bing_madison_square_garden +40 -0
- data/test/fixtures/bing_no_results +16 -0
- data/test/fixtures/bing_reverse +42 -0
- data/test/fixtures/freegeoip_74_200_247_59 +12 -0
- data/test/fixtures/freegeoip_no_results +1 -0
- data/test/fixtures/geocoder_ca_madison_square_garden +1 -0
- data/test/fixtures/geocoder_ca_no_results +1 -0
- data/test/fixtures/geocoder_ca_reverse +34 -0
- data/test/fixtures/google_garbage +456 -0
- data/test/fixtures/google_madison_square_garden +57 -0
- data/test/fixtures/google_no_city_data +44 -0
- data/test/fixtures/google_no_locality +51 -0
- data/test/fixtures/google_no_results +4 -0
- data/test/fixtures/mapquest_madison_square_garden +52 -0
- data/test/fixtures/mapquest_no_results +7 -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 +150 -0
- data/test/fixtures/nominatim_no_results +1 -0
- data/test/fixtures/ovi_madison_square_garden +72 -0
- data/test/fixtures/ovi_no_results +8 -0
- data/test/fixtures/yahoo_error +1 -0
- data/test/fixtures/yahoo_invalid_key +2 -0
- data/test/fixtures/yahoo_madison_square_garden +52 -0
- data/test/fixtures/yahoo_no_results +10 -0
- data/test/fixtures/yahoo_over_limit +2 -0
- data/test/fixtures/yandex_invalid_key +1 -0
- data/test/fixtures/yandex_kremlin +48 -0
- data/test/fixtures/yandex_no_city_and_town +112 -0
- data/test/fixtures/yandex_no_results +16 -0
- data/test/geocoder_test.rb +59 -0
- data/test/https_test.rb +16 -0
- data/test/integration/smoke_test.rb +26 -0
- data/test/lookup_test.rb +116 -0
- data/test/method_aliases_test.rb +25 -0
- data/test/mongoid_test.rb +39 -0
- data/test/mongoid_test_helper.rb +43 -0
- data/test/near_test.rb +43 -0
- data/test/oauth_util_test.rb +30 -0
- data/test/proxy_test.rb +23 -0
- data/test/query_test.rb +51 -0
- data/test/request_test.rb +29 -0
- data/test/result_test.rb +42 -0
- data/test/services_test.rb +277 -0
- data/test/test_helper.rb +279 -0
- data/test/test_mode_test.rb +50 -0
- metadata +170 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ActiveRecordTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_exclude_condition_when_model_has_a_custom_primary_key
|
7
|
+
venue = VenuePlus.new(*venue_params(:msg))
|
8
|
+
|
9
|
+
# just call private method directly so we don't have to stub .near scope
|
10
|
+
conditions = venue.class.send(:add_exclude_condition, ["fake_condition"], venue)
|
11
|
+
|
12
|
+
assert_match( /#{VenuePlus.primary_key}/, conditions.join)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/cache_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CacheTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_second_occurrence_of_request_is_cache_hit
|
7
|
+
Geocoder.configure(:cache => {})
|
8
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
9
|
+
Geocoder.configure(:lookup => l)
|
10
|
+
set_api_key!(l)
|
11
|
+
results = Geocoder.search("Madison Square Garden")
|
12
|
+
assert !results.first.cache_hit,
|
13
|
+
"Lookup #{l} returned erroneously cached result."
|
14
|
+
results = Geocoder.search("Madison Square Garden")
|
15
|
+
assert results.first.cache_hit,
|
16
|
+
"Lookup #{l} did not return cached result."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CalculationsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Geocoder.configure(
|
7
|
+
:units => :mi,
|
8
|
+
:distances => :linear
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
# --- degree distance ---
|
13
|
+
|
14
|
+
def test_longitude_degree_distance_at_equator
|
15
|
+
assert_equal 69, Geocoder::Calculations.longitude_degree_distance(0).round
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_longitude_degree_distance_at_new_york
|
19
|
+
assert_equal 53, Geocoder::Calculations.longitude_degree_distance(40).round
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_longitude_degree_distance_at_north_pole
|
23
|
+
assert_equal 0, Geocoder::Calculations.longitude_degree_distance(89.98).round
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# --- distance between ---
|
28
|
+
|
29
|
+
def test_distance_between_in_miles
|
30
|
+
assert_equal 69, Geocoder::Calculations.distance_between([0,0], [0,1]).round
|
31
|
+
la_to_ny = Geocoder::Calculations.distance_between([34.05,-118.25], [40.72,-74]).round
|
32
|
+
assert (la_to_ny - 2444).abs < 10
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_distance_between_in_kilometers
|
36
|
+
assert_equal 111, Geocoder::Calculations.distance_between([0,0], [0,1], :units => :km).round
|
37
|
+
la_to_ny = Geocoder::Calculations.distance_between([34.05,-118.25], [40.72,-74], :units => :km).round
|
38
|
+
assert (la_to_ny - 3942).abs < 10
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# --- geographic center ---
|
43
|
+
|
44
|
+
def test_geographic_center_with_arrays
|
45
|
+
assert_equal [0.0, 0.5],
|
46
|
+
Geocoder::Calculations.geographic_center([[0,0], [0,1]])
|
47
|
+
assert_equal [0.0, 1.0],
|
48
|
+
Geocoder::Calculations.geographic_center([[0,0], [0,1], [0,2]])
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_geographic_center_with_mixed_arguments
|
52
|
+
p1 = [0, 0]
|
53
|
+
p2 = Landmark.new("Some Cold Place", 0, 1)
|
54
|
+
assert_equal [0.0, 0.5], Geocoder::Calculations.geographic_center([p1, p2])
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# --- bounding box ---
|
59
|
+
|
60
|
+
def test_bounding_box_calculation_in_miles
|
61
|
+
center = [51, 7] # Cologne, DE
|
62
|
+
radius = 10 # miles
|
63
|
+
dlon = radius / Geocoder::Calculations.latitude_degree_distance
|
64
|
+
dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0])
|
65
|
+
corners = [50.86, 6.77, 51.14, 7.23]
|
66
|
+
assert_equal corners.map{ |i| (i * 100).round },
|
67
|
+
Geocoder::Calculations.bounding_box(center, radius).map{ |i| (i * 100).round }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_bounding_box_calculation_in_kilometers
|
71
|
+
center = [51, 7] # Cologne, DE
|
72
|
+
radius = 111 # kilometers (= 1 degree latitude)
|
73
|
+
dlon = radius / Geocoder::Calculations.latitude_degree_distance(:km)
|
74
|
+
dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0], :km)
|
75
|
+
corners = [50, 5.41, 52, 8.59]
|
76
|
+
assert_equal corners.map{ |i| (i * 100).round },
|
77
|
+
Geocoder::Calculations.bounding_box(center, radius, :units => :km).map{ |i| (i * 100).round }
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_bounding_box_calculation_with_object
|
81
|
+
center = [51, 7] # Cologne, DE
|
82
|
+
radius = 10 # miles
|
83
|
+
dlon = radius / Geocoder::Calculations.latitude_degree_distance
|
84
|
+
dlat = radius / Geocoder::Calculations.longitude_degree_distance(center[0])
|
85
|
+
corners = [50.86, 6.77, 51.14, 7.23]
|
86
|
+
obj = Landmark.new("Cologne", center[0], center[1])
|
87
|
+
assert_equal corners.map{ |i| (i * 100).round },
|
88
|
+
Geocoder::Calculations.bounding_box(obj, radius).map{ |i| (i * 100).round }
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_bounding_box_calculation_with_address_string
|
92
|
+
assert_nothing_raised do
|
93
|
+
Geocoder::Calculations.bounding_box("4893 Clay St, San Francisco, CA", 50)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
# --- bearing ---
|
99
|
+
|
100
|
+
def test_compass_points
|
101
|
+
assert_equal "N", Geocoder::Calculations.compass_point(0)
|
102
|
+
assert_equal "N", Geocoder::Calculations.compass_point(1.0)
|
103
|
+
assert_equal "N", Geocoder::Calculations.compass_point(360)
|
104
|
+
assert_equal "N", Geocoder::Calculations.compass_point(361)
|
105
|
+
assert_equal "N", Geocoder::Calculations.compass_point(-22)
|
106
|
+
assert_equal "NW", Geocoder::Calculations.compass_point(-23)
|
107
|
+
assert_equal "S", Geocoder::Calculations.compass_point(180)
|
108
|
+
assert_equal "S", Geocoder::Calculations.compass_point(181)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_bearing_between
|
112
|
+
bearings = {
|
113
|
+
:n => 0,
|
114
|
+
:e => 90,
|
115
|
+
:s => 180,
|
116
|
+
:w => 270
|
117
|
+
}
|
118
|
+
points = {
|
119
|
+
:n => [41, -75],
|
120
|
+
:e => [40, -74],
|
121
|
+
:s => [39, -75],
|
122
|
+
:w => [40, -76]
|
123
|
+
}
|
124
|
+
directions = [:n, :e, :s, :w]
|
125
|
+
methods = [:linear, :spherical]
|
126
|
+
|
127
|
+
methods.each do |m|
|
128
|
+
directions.each_with_index do |d,i|
|
129
|
+
opp = directions[(i + 2) % 4] # opposite direction
|
130
|
+
b = Geocoder::Calculations.bearing_between(
|
131
|
+
points[d], points[opp], :method => m)
|
132
|
+
assert (b - bearings[opp]).abs < 1,
|
133
|
+
"Bearing (#{m}) should be close to #{bearings[opp]} but was #{b}."
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_spherical_bearing_to
|
139
|
+
l = Landmark.new(*landmark_params(:msg))
|
140
|
+
assert_equal 324, l.bearing_to([50,-85], :method => :spherical).round
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_spherical_bearing_from
|
144
|
+
l = Landmark.new(*landmark_params(:msg))
|
145
|
+
assert_equal 136, l.bearing_from([50,-85], :method => :spherical).round
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_linear_bearing_from_and_to_are_exactly_opposite
|
149
|
+
l = Landmark.new(*landmark_params(:msg))
|
150
|
+
assert_equal l.bearing_from([50,-86.1]), l.bearing_to([50,-86.1]) - 180
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_extract_coordinates
|
154
|
+
result = Geocoder::Calculations.extract_coordinates([ nil, nil ])
|
155
|
+
assert is_nan_coordinates?(result)
|
156
|
+
|
157
|
+
result = Geocoder::Calculations.extract_coordinates([ 1.0 / 3, 2.0 / 3 ])
|
158
|
+
assert_in_delta 1.0 / 3, result.first, 1E-5
|
159
|
+
assert_in_delta 2.0 / 3, result.last, 1E-5
|
160
|
+
|
161
|
+
result = Geocoder::Calculations.extract_coordinates(nil)
|
162
|
+
assert is_nan_coordinates?(result)
|
163
|
+
|
164
|
+
result = Geocoder::Calculations.extract_coordinates('')
|
165
|
+
assert is_nan_coordinates?(result)
|
166
|
+
|
167
|
+
result = Geocoder::Calculations.extract_coordinates([ 'nix' ])
|
168
|
+
assert is_nan_coordinates?(result)
|
169
|
+
|
170
|
+
o = Object.new
|
171
|
+
result = Geocoder::Calculations.extract_coordinates(o)
|
172
|
+
assert is_nan_coordinates?(result)
|
173
|
+
|
174
|
+
def o.to_coordinates
|
175
|
+
[ 1.0 / 3, 2.0 / 3 ]
|
176
|
+
end
|
177
|
+
result = Geocoder::Calculations.extract_coordinates(o)
|
178
|
+
assert_in_delta 1.0 / 3, result.first, 1E-5
|
179
|
+
assert_in_delta 2.0 / 3, result.last, 1E-5
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_coordinates_present
|
183
|
+
assert Geocoder::Calculations.coordinates_present?(3.23)
|
184
|
+
assert !Geocoder::Calculations.coordinates_present?(nil)
|
185
|
+
assert !Geocoder::Calculations.coordinates_present?(Geocoder::Calculations::NAN)
|
186
|
+
assert !Geocoder::Calculations.coordinates_present?(3.23, nil)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_extract_coordinates
|
190
|
+
coords = [-23,47]
|
191
|
+
l = Landmark.new("Madagascar", coords[0], coords[1])
|
192
|
+
assert_equal coords, Geocoder::Calculations.extract_coordinates(l)
|
193
|
+
assert_equal coords, Geocoder::Calculations.extract_coordinates(coords)
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ConfigurationTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Geocoder::Configuration.set_defaults
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_exception_raised_on_bad_lookup_config
|
10
|
+
Geocoder.configure(:lookup => :stoopid)
|
11
|
+
assert_raises Geocoder::ConfigurationError do
|
12
|
+
Geocoder.search "something dumb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_setting_with_class_method
|
17
|
+
Geocoder::Configuration.units = :test
|
18
|
+
assert_equal :test, Geocoder.config.units
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_setting_with_configure_method
|
22
|
+
Geocoder.configure(:units => :test)
|
23
|
+
assert_equal :test, Geocoder.config.units
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_setting_with_block_syntax
|
27
|
+
orig = $VERBOSE; $VERBOSE = nil
|
28
|
+
Geocoder.configure do |config|
|
29
|
+
config.units = :test
|
30
|
+
end
|
31
|
+
assert_equal :test, Geocoder.config.units
|
32
|
+
ensure
|
33
|
+
$VERBOSE = orig
|
34
|
+
end
|
35
|
+
|
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
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_model_configuration
|
49
|
+
Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :km
|
50
|
+
assert_equal :km, Landmark.geocoder_options[:units]
|
51
|
+
assert_equal :spherical, Landmark.geocoder_options[:method]
|
52
|
+
|
53
|
+
v = Landmark.new(*landmark_params(:msg))
|
54
|
+
v.latitude = 0
|
55
|
+
v.longitude = 0
|
56
|
+
assert_equal 111, v.distance_to([0,1]).round
|
57
|
+
v.latitude = 40.750354
|
58
|
+
v.longitude = -73.993371
|
59
|
+
assert_equal 136, v.bearing_from([50,-85]).round
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_configuration_chain
|
63
|
+
v = Landmark.new(*landmark_params(:msg))
|
64
|
+
v.latitude = 0
|
65
|
+
v.longitude = 0
|
66
|
+
|
67
|
+
# method option > global configuration
|
68
|
+
Geocoder.configure(:units => :km)
|
69
|
+
assert_equal 69, v.distance_to([0,1], :mi).round
|
70
|
+
|
71
|
+
# per-model configuration > global configuration
|
72
|
+
Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :mi
|
73
|
+
assert_equal 69, v.distance_to([0,1]).round
|
74
|
+
|
75
|
+
# method option > per-model configuration
|
76
|
+
assert_equal 111, v.distance_to([0,1], :km).round
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CustomBlockTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_geocode_with_block_runs_block
|
7
|
+
e = Event.new(*venue_params(:msg))
|
8
|
+
coords = [40.750354, -73.993371]
|
9
|
+
e.geocode
|
10
|
+
assert_equal coords.map{ |c| c.to_s }.join(','), e.coords_string
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_geocode_with_block_doesnt_auto_assign_coordinates
|
14
|
+
e = Event.new(*venue_params(:msg))
|
15
|
+
e.geocode
|
16
|
+
assert_nil e.latitude
|
17
|
+
assert_nil e.longitude
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_reverse_geocode_with_block_runs_block
|
21
|
+
e = Party.new(*landmark_params(:msg))
|
22
|
+
e.reverse_geocode
|
23
|
+
assert_equal "US", e.country
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_reverse_geocode_with_block_doesnt_auto_assign_address
|
27
|
+
e = Party.new(*landmark_params(:msg))
|
28
|
+
e.reverse_geocode
|
29
|
+
assert_nil e.address
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ErrorHandlingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def teardown
|
7
|
+
Geocoder.configure(:always_raise => [])
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_does_not_choke_on_timeout
|
11
|
+
# keep test output clean: suppress timeout warning
|
12
|
+
orig = $VERBOSE; $VERBOSE = nil
|
13
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
14
|
+
Geocoder.configure(:lookup => l)
|
15
|
+
set_api_key!(l)
|
16
|
+
assert_nothing_raised { Geocoder.search("timeout") }
|
17
|
+
end
|
18
|
+
ensure
|
19
|
+
$VERBOSE = orig
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_always_raise_timeout_error
|
23
|
+
Geocoder.configure(:always_raise => [TimeoutError])
|
24
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
25
|
+
lookup = Geocoder::Lookup.get(l)
|
26
|
+
set_api_key!(l)
|
27
|
+
assert_raises TimeoutError do
|
28
|
+
lookup.send(:results, Geocoder::Query.new("timeout"))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_always_raise_socket_error
|
34
|
+
Geocoder.configure(:always_raise => [SocketError])
|
35
|
+
Geocoder::Lookup.all_services_except_test.each do |l|
|
36
|
+
lookup = Geocoder::Lookup.get(l)
|
37
|
+
set_api_key!(l)
|
38
|
+
assert_raises SocketError do
|
39
|
+
lookup.send(:results, Geocoder::Query.new("socket_error"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -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|"}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"authenticationResultCode":"ValidCredentials",
|
3
|
+
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
|
4
|
+
"copyright":"Copyright © 2011 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.",
|
5
|
+
"resourceSets":[
|
6
|
+
{
|
7
|
+
"estimatedTotal":1,
|
8
|
+
"resources":[
|
9
|
+
{
|
10
|
+
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
|
11
|
+
"bbox":[
|
12
|
+
40.744944289326668,
|
13
|
+
-74.002353921532631,
|
14
|
+
40.755675807595253,
|
15
|
+
-73.983625397086143
|
16
|
+
],
|
17
|
+
"name":"Madison Square Garden, NY",
|
18
|
+
"point":{
|
19
|
+
"type":"Point",
|
20
|
+
"coordinates":[
|
21
|
+
40.75031,
|
22
|
+
-73.99299
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"address":{
|
26
|
+
"adminDistrict":"NY",
|
27
|
+
"countryRegion":"United States",
|
28
|
+
"formattedAddress":"Madison Square Garden, NY",
|
29
|
+
"locality":"New York"
|
30
|
+
},
|
31
|
+
"confidence":"High",
|
32
|
+
"entityType":"Stadium"
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"statusCode":200,
|
38
|
+
"statusDescription":"OK",
|
39
|
+
"traceId":"55094ee53c8d45e789794014666328cd|CH1M001466|02.00.82.2800|CH1MSNVM001396, CH1MSNVM001370, CH1MSNVM001397"
|
40
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"authenticationResultCode":"ValidCredentials",
|
3
|
+
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
|
4
|
+
"copyright":"Copyright © 2011 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.",
|
5
|
+
"resourceSets":[
|
6
|
+
{
|
7
|
+
"estimatedTotal":0,
|
8
|
+
"resources":[
|
9
|
+
|
10
|
+
]
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"statusCode":200,
|
14
|
+
"statusDescription":"OK",
|
15
|
+
"traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397"
|
16
|
+
}
|