geokit 1.6.0 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +7 -21
- data/lib/geokit.rb +1 -2
- data/lib/geokit/geocoders.rb +219 -194
- data/lib/geokit/mappable.rb +98 -89
- data/test/test_base_geocoder.rb +11 -11
- data/test/test_bounds.rb +22 -22
- data/test/test_ca_geocoder.rb +17 -17
- data/test/test_geoloc.rb +15 -15
- data/test/test_geoplugin_geocoder.rb +5 -5
- data/test/test_google_geocoder.rb +30 -30
- data/test/test_google_geocoder3.rb +107 -86
- data/test/test_google_reverse_geocoder.rb +16 -16
- data/test/test_inflector.rb +3 -3
- data/test/test_ipgeocoder.rb +13 -13
- data/test/test_latlng.rb +48 -36
- data/test/test_multi_geocoder.rb +17 -17
- data/test/test_multi_ip_geocoder.rb +5 -5
- data/test/test_us_geocoder.rb +17 -17
- data/test/test_yahoo_geocoder.rb +27 -31
- metadata +29 -38
- data/History.txt +0 -77
- data/Manifest.txt +0 -21
- data/geokit.gemspec +0 -38
data/test/test_latlng.rb
CHANGED
@@ -3,13 +3,13 @@ require 'lib/geokit'
|
|
3
3
|
require 'mocha'
|
4
4
|
|
5
5
|
class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
@loc_a = Geokit::LatLng.new(32.918593,-96.958444)
|
9
9
|
@loc_e = Geokit::LatLng.new(32.969527,-96.990159)
|
10
10
|
@point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def valid_reverse_geocoding_result
|
14
14
|
location = Geokit::GeoLoc.new({
|
15
15
|
:city => "Essen",
|
@@ -21,19 +21,19 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
21
21
|
:street_address => "Porscheplatz 1",
|
22
22
|
:zip => "45127"
|
23
23
|
})
|
24
|
-
|
24
|
+
|
25
25
|
location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
|
26
26
|
location.precision = 'address'
|
27
27
|
location.provider = 'google'
|
28
28
|
location.success = true
|
29
29
|
location
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_distance_between_same_using_defaults
|
33
33
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
|
34
34
|
assert_equal 0, @loc_a.distance_to(@loc_a)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def test_distance_between_same_with_miles_and_flat
|
38
38
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :flat)
|
39
39
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :flat)
|
@@ -43,32 +43,32 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
43
43
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :flat)
|
44
44
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :flat)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_distance_between_same_with_nms_and_flat
|
48
48
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :flat)
|
49
49
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :flat)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def test_distance_between_same_with_miles_and_sphere
|
53
53
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :miles, :formula => :sphere)
|
54
54
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :miles, :formula => :sphere)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def test_distance_between_same_with_kms_and_sphere
|
58
58
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :kms, :formula => :sphere)
|
59
59
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :kms, :formula => :sphere)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_distance_between_same_with_nms_and_sphere
|
63
63
|
assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a, :units => :nms, :formula => :sphere)
|
64
64
|
assert_equal 0, @loc_a.distance_to(@loc_a, :units => :nms, :formula => :sphere)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def test_distance_between_diff_using_defaults
|
68
68
|
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e), 0.01
|
69
69
|
assert_in_delta 3.97, @loc_a.distance_to(@loc_e), 0.01
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def test_distance_between_diff_with_miles_and_flat
|
73
73
|
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :flat), 0.2
|
74
74
|
assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :flat), 0.2
|
@@ -78,27 +78,27 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
78
78
|
assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :flat), 0.4
|
79
79
|
assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def test_distance_between_diff_with_nms_and_flat
|
83
83
|
assert_in_delta 3.334, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :flat), 0.4
|
84
84
|
assert_in_delta 3.334, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def test_distance_between_diff_with_miles_and_sphere
|
88
88
|
assert_in_delta 3.97, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :miles, :formula => :sphere), 0.01
|
89
89
|
assert_in_delta 3.97, @loc_a.distance_to(@loc_e, :units => :miles, :formula => :sphere), 0.01
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def test_distance_between_diff_with_kms_and_sphere
|
93
93
|
assert_in_delta 6.39, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :kms, :formula => :sphere), 0.01
|
94
94
|
assert_in_delta 6.39, @loc_a.distance_to(@loc_e, :units => :kms, :formula => :sphere), 0.01
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def test_distance_between_diff_with_nms_and_sphere
|
98
98
|
assert_in_delta 3.454, Geokit::LatLng.distance_between(@loc_a, @loc_e, :units => :nms, :formula => :sphere), 0.01
|
99
99
|
assert_in_delta 3.454, @loc_a.distance_to(@loc_e, :units => :nms, :formula => :sphere), 0.01
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def test_manually_mixed_in
|
103
103
|
assert_equal 0, Geokit::LatLng.distance_between(@point, @point)
|
104
104
|
assert_equal 0, @point.distance_to(@point)
|
@@ -107,15 +107,15 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
107
107
|
assert_in_delta 6.39, @point.distance_to(@loc_e, :units => :kms, :formula => :flat), 0.4
|
108
108
|
assert_in_delta 3.334, @point.distance_to(@loc_e, :units => :nms, :formula => :flat), 0.4
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def test_heading_between
|
112
112
|
assert_in_delta 332, Geokit::LatLng.heading_between(@loc_a,@loc_e), 0.5
|
113
113
|
end
|
114
114
|
|
115
115
|
def test_heading_to
|
116
116
|
assert_in_delta 332, @loc_a.heading_to(@loc_e), 0.5
|
117
|
-
end
|
118
|
-
|
117
|
+
end
|
118
|
+
|
119
119
|
def test_class_endpoint
|
120
120
|
endpoint=Geokit::LatLng.endpoint(@loc_a, 332, 3.97)
|
121
121
|
assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
|
@@ -126,29 +126,29 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
126
126
|
endpoint=@loc_a.endpoint(332, 3.97)
|
127
127
|
assert_in_delta @loc_e.lat, endpoint.lat, 0.0005
|
128
128
|
assert_in_delta @loc_e.lng, endpoint.lng, 0.0005
|
129
|
-
end
|
130
|
-
|
129
|
+
end
|
130
|
+
|
131
131
|
def test_midpoint
|
132
132
|
midpoint=@loc_a.midpoint_to(@loc_e)
|
133
133
|
assert_in_delta 32.944061, midpoint.lat, 0.0005
|
134
134
|
assert_in_delta(-96.974296, midpoint.lng, 0.0005)
|
135
|
-
end
|
136
|
-
|
135
|
+
end
|
136
|
+
|
137
137
|
def test_normalize
|
138
138
|
lat=37.7690
|
139
139
|
lng=-122.443
|
140
140
|
res=Geokit::LatLng.normalize(lat,lng)
|
141
|
-
assert_equal res,Geokit::LatLng.new(lat,lng)
|
141
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
142
142
|
res=Geokit::LatLng.normalize("#{lat}, #{lng}")
|
143
|
-
assert_equal res,Geokit::LatLng.new(lat,lng)
|
143
|
+
assert_equal res,Geokit::LatLng.new(lat,lng)
|
144
144
|
res=Geokit::LatLng.normalize("#{lat} #{lng}")
|
145
145
|
assert_equal res,Geokit::LatLng.new(lat,lng)
|
146
146
|
res=Geokit::LatLng.normalize("#{lat.to_i} #{lng.to_i}")
|
147
|
-
assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
|
147
|
+
assert_equal res,Geokit::LatLng.new(lat.to_i,lng.to_i)
|
148
148
|
res=Geokit::LatLng.normalize([lat,lng])
|
149
149
|
assert_equal res,Geokit::LatLng.new(lat,lng)
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
def test_hash
|
153
153
|
lat=37.7690
|
154
154
|
lng=-122.443
|
@@ -156,7 +156,7 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
156
156
|
second = Geokit::LatLng.new(lat,lng)
|
157
157
|
assert_equal first.hash, second.hash
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
def test_eql?
|
161
161
|
lat=37.7690
|
162
162
|
lng=-122.443
|
@@ -165,45 +165,57 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
|
|
165
165
|
assert first.eql?(second)
|
166
166
|
assert second.eql?(first)
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
|
+
def test_valid_when_lat_and_lng_defined
|
170
|
+
assert Geokit::LatLng.new(37.7690,-122.443).valid?
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_not_valid_when_lat_is_nil
|
174
|
+
assert ! Geokit::LatLng.new(nil,-122.443).valid?
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_not_valid_when_lng_is_nil
|
178
|
+
assert ! Geokit::LatLng.new(37.7690,nil).valid?
|
179
|
+
end
|
180
|
+
|
169
181
|
def test_reverse_geocode
|
170
182
|
point = Geokit::LatLng.new(51.4578329, 7.0166848)
|
171
183
|
Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
|
172
184
|
res = point.reverse_geocode
|
173
|
-
|
185
|
+
|
174
186
|
assert_equal "Nordrhein-Westfalen", res.state
|
175
|
-
assert_equal "Essen", res.city
|
187
|
+
assert_equal "Essen", res.city
|
176
188
|
assert_equal "45127", res.zip
|
177
189
|
assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
|
178
190
|
assert res.is_us? == false
|
179
191
|
assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
|
180
192
|
end
|
181
|
-
|
193
|
+
|
182
194
|
def test_reverse_geocoding_using_specific_geocoder
|
183
195
|
point = Geokit::LatLng.new(51.4578329, 7.0166848)
|
184
196
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
|
185
197
|
res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder)
|
186
198
|
|
187
199
|
assert_equal "Nordrhein-Westfalen", res.state
|
188
|
-
assert_equal "Essen", res.city
|
200
|
+
assert_equal "Essen", res.city
|
189
201
|
assert_equal "45127", res.zip
|
190
202
|
assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
|
191
203
|
assert res.is_us? == false
|
192
204
|
assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
|
193
205
|
assert_equal "google", res.provider
|
194
206
|
end
|
195
|
-
|
207
|
+
|
196
208
|
def test_reverse_geocoding_using_specific_geocoder_short_syntax
|
197
209
|
point = Geokit::LatLng.new(51.4578329, 7.0166848)
|
198
210
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
|
199
211
|
res = point.reverse_geocode(:using => :google)
|
200
212
|
|
201
213
|
assert_equal "Nordrhein-Westfalen", res.state
|
202
|
-
assert_equal "Essen", res.city
|
214
|
+
assert_equal "Essen", res.city
|
203
215
|
assert_equal "45127", res.zip
|
204
216
|
assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
|
205
217
|
assert res.is_us? == false
|
206
218
|
assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
|
207
219
|
assert_equal "google", res.provider
|
208
220
|
end
|
209
|
-
end
|
221
|
+
end
|
data/test/test_multi_geocoder.rb
CHANGED
@@ -3,41 +3,41 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
|
3
3
|
Geokit::Geocoders::provider_order=[:google,:yahoo,:us]
|
4
4
|
|
5
5
|
class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
super
|
9
9
|
@failure = Geokit::GeoLoc.new
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_successful_first
|
13
13
|
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@success)
|
14
14
|
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_failover
|
18
18
|
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
19
19
|
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@success)
|
20
|
-
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
20
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_double_failover
|
24
24
|
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
25
25
|
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
26
26
|
Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@success)
|
27
|
-
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
27
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def test_failure
|
31
31
|
Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
32
32
|
Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
33
33
|
Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
|
34
|
-
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
34
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_invalid_provider
|
38
38
|
temp = Geokit::Geocoders::provider_order
|
39
39
|
Geokit::Geocoders.provider_order = [:bogus]
|
40
|
-
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
40
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
|
41
41
|
Geokit::Geocoders.provider_order = temp
|
42
42
|
end
|
43
43
|
|
@@ -55,31 +55,31 @@ class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
55
55
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
|
56
56
|
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def test_reverse_geocode_failover
|
60
60
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
61
61
|
Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
|
62
|
-
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
62
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def test_reverse_geocode_double_failover
|
66
66
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
67
67
|
Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
68
68
|
Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
|
69
|
-
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
69
|
+
assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def test_reverse_geocode_failure
|
73
73
|
Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
74
74
|
Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
75
75
|
Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
|
76
|
-
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
76
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_reverse_geocode_with_invalid_provider
|
80
80
|
temp = Geokit::Geocoders::provider_order
|
81
81
|
Geokit::Geocoders.provider_order = [:bogus]
|
82
|
-
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
82
|
+
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
|
83
83
|
Geokit::Geocoders.provider_order = temp
|
84
84
|
end
|
85
85
|
|
@@ -90,4 +90,4 @@ class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
90
90
|
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode("")
|
91
91
|
Geokit::Geocoders.provider_order = t1 # reset to orig values
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
@@ -3,31 +3,31 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
|
3
3
|
Geokit::Geocoders::ip_provider_order=[:geo_plugin,:ip]
|
4
4
|
|
5
5
|
class MultiIpGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
8
|
@ip_address = '10.10.10.10'
|
9
9
|
@success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
|
10
10
|
@success.success = true
|
11
11
|
@failure = Geokit::GeoLoc.new
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_successful_first
|
15
15
|
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
|
16
16
|
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_failover
|
20
20
|
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
21
21
|
Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
|
22
22
|
assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_failure
|
26
26
|
Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
27
27
|
Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
|
28
28
|
assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_invalid_provider
|
32
32
|
temp = Geokit::Geocoders::ip_provider_order
|
33
33
|
Geokit::Geocoders.ip_provider_order = [:bogus]
|
data/test/test_us_geocoder.rb
CHANGED
@@ -3,15 +3,15 @@ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
|
|
3
3
|
Geokit::Geocoders::geocoder_us = nil
|
4
4
|
|
5
5
|
class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
|
-
|
7
|
-
GEOCODER_US_FULL='37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'
|
8
|
-
|
6
|
+
|
7
|
+
GEOCODER_US_FULL='37.792528,-122.393981,100 Spear St,San Francisco,CA,94105'
|
8
|
+
|
9
9
|
def setup
|
10
10
|
super
|
11
11
|
@us_full_hash = {:city=>"San Francisco", :state=>"CA"}
|
12
12
|
@us_full_loc = Geokit::GeoLoc.new(@us_full_hash)
|
13
|
-
end
|
14
|
-
|
13
|
+
end
|
14
|
+
|
15
15
|
def test_geocoder_us
|
16
16
|
response = MockSuccess.new
|
17
17
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
@@ -19,22 +19,22 @@ class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
19
19
|
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
20
20
|
verify(Geokit::Geocoders::UsGeocoder.geocode(@address))
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_geocoder_with_geo_loc
|
24
24
|
response = MockSuccess.new
|
25
25
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
26
26
|
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
27
27
|
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
28
|
-
verify(Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc))
|
28
|
+
verify(Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc))
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_service_unavailable
|
32
32
|
response = MockFailure.new
|
33
33
|
url = "http://geocoder.us/service/csv/geocode?address=#{Geokit::Inflector.url_escape(@address)}"
|
34
34
|
Geokit::Geocoders::UsGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
35
|
-
assert !Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc).success
|
36
|
-
end
|
37
|
-
|
35
|
+
assert !Geokit::Geocoders::UsGeocoder.geocode(@us_full_loc).success
|
36
|
+
end
|
37
|
+
|
38
38
|
def test_all_method
|
39
39
|
response = MockSuccess.new
|
40
40
|
response.expects(:body).returns(GEOCODER_US_FULL)
|
@@ -43,14 +43,14 @@ class UsGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
43
43
|
res=Geokit::Geocoders::UsGeocoder.geocode(@address)
|
44
44
|
assert_equal 1, res.all.size
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
private
|
48
|
-
|
48
|
+
|
49
49
|
def verify(location)
|
50
50
|
assert_equal "CA", location.state
|
51
|
-
assert_equal "San Francisco", location.city
|
52
|
-
assert_equal "37.792528,-122.393981", location.ll
|
51
|
+
assert_equal "San Francisco", location.city
|
52
|
+
assert_equal "37.792528,-122.393981", location.ll
|
53
53
|
assert location.is_us?
|
54
|
-
assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address #slightly different from yahoo
|
54
|
+
assert_equal "100 Spear St, San Francisco, CA, 94105, US", location.full_address #slightly different from yahoo
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
data/test/test_yahoo_geocoder.rb
CHANGED
@@ -4,17 +4,13 @@ Geokit::Geocoders::yahoo = 'Yahoo'
|
|
4
4
|
|
5
5
|
class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
6
6
|
YAHOO_FULL=<<-EOF.strip
|
7
|
-
|
8
|
-
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="address"><Latitude>37.792406</Latitude><Longitude>-122.39411</Longitude><Address>100 SPEAR ST</Address><City>SAN FRANCISCO</City><State>CA</State><Zip>94105-1522</Zip><Country>US</Country></Result></ResultSet>
|
9
|
-
<!-- ws01.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 16:23:43 PST 2007 -->
|
7
|
+
{"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":87,"Found":1,"Results":[{"quality":87,"latitude":"37.792406","longitude":"-122.39411","offsetlat":"37.792332","offsetlon":"-122.394027","radius":500,"name":"","line1":"100 Spear St","line2":"San Francisco, CA 94105-1522","line3":"","line4":"United States","house":"100","street":"Spear St","xstreet":"","unittype":"","unit":"","postal":"94105-1522","neighborhood":"","city":"San Francisco","county":"San Francisco County","state":"California","country":"United States","countrycode":"US","statecode":"CA","countycode":"","uzip":"94105","hash":"0FA06819B5F53E75","woeid":12797156,"woetype":11}]}}
|
10
8
|
EOF
|
11
9
|
|
12
10
|
YAHOO_CITY=<<-EOF.strip
|
13
|
-
|
14
|
-
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"><Result precision="city"><Latitude>37.7742</Latitude><Longitude>-122.417068</Longitude><Address></Address><City>SAN FRANCISCO</City><State>CA</State><Zip></Zip><Country>US</Country></Result></ResultSet>
|
15
|
-
<!-- ws02.search.scd.yahoo.com uncompressed/chunked Mon Jan 29 18:00:28 PST 2007 -->
|
11
|
+
{"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":40,"Found":1,"Results":[{"quality":40,"latitude":"37.7742","longitude":"-122.417068","offsetlat":"37.7742","offsetlon":"-122.417068","radius":10700,"name":"","line1":"","line2":"San Francisco, CA","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"San Francisco","county":"San Francisco County","state":"California","country":"United States","countrycode":"US","statecode":"CA","countycode":"","uzip":"94102","hash":"","woeid":2487956,"woetype":7}]}}
|
16
12
|
EOF
|
17
|
-
|
13
|
+
|
18
14
|
def setup
|
19
15
|
super
|
20
16
|
@yahoo_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105-1522", :country_code=>"US"}
|
@@ -22,64 +18,64 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
22
18
|
@yahoo_full_loc = Geokit::GeoLoc.new(@yahoo_full_hash)
|
23
19
|
@yahoo_city_loc = Geokit::GeoLoc.new(@yahoo_city_hash)
|
24
20
|
end
|
25
|
-
|
21
|
+
|
26
22
|
# the testing methods themselves
|
27
23
|
def test_yahoo_full_address
|
28
24
|
response = MockSuccess.new
|
29
25
|
response.expects(:body).returns(YAHOO_FULL)
|
30
|
-
url = "http://
|
26
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@full_address)}"
|
31
27
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
32
|
-
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@
|
33
|
-
end
|
34
|
-
|
28
|
+
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@full_address))
|
29
|
+
end
|
30
|
+
|
35
31
|
def test_yahoo_full_address_accuracy
|
36
32
|
response = MockSuccess.new
|
37
33
|
response.expects(:body).returns(YAHOO_FULL)
|
38
|
-
url = "http://
|
34
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@full_address)}"
|
39
35
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
40
|
-
res = Geokit::Geocoders::YahooGeocoder.geocode(@
|
36
|
+
res = Geokit::Geocoders::YahooGeocoder.geocode(@full_address)
|
41
37
|
assert_equal 8, res.accuracy
|
42
38
|
end
|
43
|
-
|
39
|
+
|
44
40
|
def test_yahoo_full_address_with_geo_loc
|
45
41
|
response = MockSuccess.new
|
46
42
|
response.expects(:body).returns(YAHOO_FULL)
|
47
|
-
url = "http://
|
43
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@full_address)}"
|
48
44
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
49
45
|
do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_full_loc))
|
50
|
-
end
|
46
|
+
end
|
51
47
|
|
52
48
|
def test_yahoo_city
|
53
49
|
response = MockSuccess.new
|
54
50
|
response.expects(:body).returns(YAHOO_CITY)
|
55
|
-
url = "http://
|
51
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@address)}"
|
56
52
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
57
53
|
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
|
58
54
|
end
|
59
|
-
|
55
|
+
|
60
56
|
def test_yahoo_city_accuracy
|
61
57
|
response = MockSuccess.new
|
62
58
|
response.expects(:body).returns(YAHOO_CITY)
|
63
|
-
url = "http://
|
59
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@address)}"
|
64
60
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
65
61
|
res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
|
66
62
|
assert_equal 4, res.accuracy
|
67
63
|
end
|
68
|
-
|
64
|
+
|
69
65
|
def test_yahoo_city_with_geo_loc
|
70
66
|
response = MockSuccess.new
|
71
67
|
response.expects(:body).returns(YAHOO_CITY)
|
72
|
-
url = "http://
|
68
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@address)}"
|
73
69
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
74
70
|
do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
|
75
|
-
end
|
76
|
-
|
71
|
+
end
|
72
|
+
|
77
73
|
def test_service_unavailable
|
78
74
|
response = MockFailure.new
|
79
|
-
url = "http://
|
75
|
+
url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@address)}"
|
80
76
|
Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
|
81
77
|
assert !Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc).success
|
82
|
-
end
|
78
|
+
end
|
83
79
|
|
84
80
|
private
|
85
81
|
|
@@ -92,14 +88,14 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
|
|
92
88
|
assert_equal "100 Spear St, San Francisco, CA, 94105-1522, US", res.full_address
|
93
89
|
assert_equal "yahoo", res.provider
|
94
90
|
end
|
95
|
-
|
91
|
+
|
96
92
|
def do_city_assertions(res)
|
97
93
|
assert_equal "CA", res.state
|
98
|
-
assert_equal "San Francisco", res.city
|
94
|
+
assert_equal "San Francisco", res.city
|
99
95
|
assert_equal "37.7742,-122.417068", res.ll
|
100
96
|
assert res.is_us?
|
101
|
-
assert_equal "San Francisco, CA, US", res.full_address
|
97
|
+
assert_equal "San Francisco, CA, US", res.full_address
|
102
98
|
assert_nil res.street_address
|
103
99
|
assert_equal "yahoo", res.provider
|
104
|
-
end
|
105
|
-
end
|
100
|
+
end
|
101
|
+
end
|