geokit-rails3 0.1.2 → 0.1.3
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/lib/geokit-rails3/acts_as_mappable.rb +13 -5
- data/lib/geokit-rails3/version.rb +1 -1
- data/test/acts_as_mappable_test.rb +0 -111
- data/test/boot.rb +1 -1
- data/test/ip_geocode_lookup_test.disabled.rb +82 -0
- data/test/mysql-debug.log +11490 -0
- metadata +29 -48
@@ -14,7 +14,7 @@ module Geokit
|
|
14
14
|
def acts_as_mappable(options = {})
|
15
15
|
metaclass = (class << self; self; end)
|
16
16
|
|
17
|
-
|
17
|
+
include Geokit::ActsAsMappable
|
18
18
|
|
19
19
|
cattr_accessor :through
|
20
20
|
self.through = options[:through]
|
@@ -118,8 +118,14 @@ module Geokit
|
|
118
118
|
|
119
119
|
if origin
|
120
120
|
@distance_formula = distance_sql(origin, units, formula)
|
121
|
-
|
122
|
-
|
121
|
+
|
122
|
+
if arel.select_values.blank?
|
123
|
+
star_select = Arel::SqlLiteral.new(arel.quoted_table_name + '.*')
|
124
|
+
arel = arel.select(star_select)
|
125
|
+
end
|
126
|
+
|
127
|
+
distance_select = Arel::SqlLiteral.new("#{@distance_formula} AS #{distance_column_name}")
|
128
|
+
arel = arel.select(distance_select)
|
123
129
|
end
|
124
130
|
|
125
131
|
if bounds
|
@@ -165,19 +171,21 @@ module Geokit
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def distance_conditions(options)
|
168
|
-
if options.has_key?(:within)
|
174
|
+
res = if options.has_key?(:within)
|
169
175
|
"#{distance_column_name} <= #{options[:within]}"
|
170
176
|
elsif options.has_key?(:beyond)
|
171
177
|
"#{distance_column_name} > #{options[:beyond]}"
|
172
178
|
elsif options.has_key?(:range)
|
173
179
|
"#{distance_column_name} >= #{options[:range].first} AND #{distance_column_name} <#{'=' unless options[:range].exclude_end?} #{options[:range].last}"
|
174
180
|
end
|
181
|
+
Arel::SqlLiteral.new("(#{res})") if res.present?
|
175
182
|
end
|
176
183
|
|
177
184
|
def bound_conditions(bounds)
|
178
185
|
sw,ne = bounds.sw, bounds.ne
|
179
186
|
lng_sql = bounds.crosses_meridian? ? "(#{qualified_lng_column_name}<#{ne.lng} OR #{qualified_lng_column_name}>#{sw.lng})" : "#{qualified_lng_column_name}>#{sw.lng} AND #{qualified_lng_column_name}<#{ne.lng}"
|
180
|
-
"#{qualified_lat_column_name}>#{sw.lat} AND #{qualified_lat_column_name}<#{ne.lat} AND #{lng_sql}"
|
187
|
+
res = "#{qualified_lat_column_name}>#{sw.lat} AND #{qualified_lat_column_name}<#{ne.lat} AND #{lng_sql}"
|
188
|
+
Arel::SqlLiteral.new("(#{res})") if res.present?
|
181
189
|
end
|
182
190
|
|
183
191
|
# Extracts the origin instance out of the options if it exists and returns
|
@@ -31,10 +31,8 @@ class ActsAsMappableTest < GeokitTestCase
|
|
31
31
|
|
32
32
|
def test_override_default_units_the_hard_way
|
33
33
|
Location.default_units = :kms
|
34
|
-
# locations = Location.find(:all, :origin => @loc_a, :conditions => "distance < 3.97")
|
35
34
|
locations = Location.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
36
35
|
assert_equal 5, locations.all.size
|
37
|
-
# locations = Location.count(:origin => @loc_a, :conditions => "distance < 3.97")
|
38
36
|
assert_equal 5, locations.count
|
39
37
|
Location.default_units = :miles
|
40
38
|
end
|
@@ -68,7 +66,6 @@ class ActsAsMappableTest < GeokitTestCase
|
|
68
66
|
end
|
69
67
|
|
70
68
|
def test_distance_column_in_select
|
71
|
-
# locations = Location.find(:all, :origin => @loc_a, :order => "distance ASC")
|
72
69
|
locations = Location.geo_scope(:origin => @loc_a).order("distance ASC")
|
73
70
|
assert_equal 6, locations.all.size
|
74
71
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
@@ -76,71 +73,50 @@ class ActsAsMappableTest < GeokitTestCase
|
|
76
73
|
end
|
77
74
|
|
78
75
|
def test_find_with_distance_condition
|
79
|
-
# locations = Location.find(:all, :origin => @loc_a, :conditions => "distance < 3.97")
|
80
76
|
locations = Location.geo_scope(:origin => @loc_a, :within => 3.97)
|
81
77
|
assert_equal 5, locations.all.size
|
82
|
-
# locations = Location.count(:origin => @loc_a, :conditions => "distance < 3.97")
|
83
78
|
assert_equal 5, locations.count
|
84
79
|
end
|
85
80
|
|
86
81
|
def test_find_with_distance_condition_with_units_override
|
87
|
-
# locations = Location.find(:all, :origin => @loc_a, :units => :kms, :conditions => "distance < 6.387")
|
88
82
|
locations = Location.geo_scope(:origin => @loc_a, :units => :kms, :within => 6.387)
|
89
83
|
assert_equal 5, locations.all.size
|
90
|
-
# locations = Location.count(:origin => @loc_a, :units => :kms, :conditions => "distance < 6.387")
|
91
84
|
assert_equal 5, locations.count
|
92
85
|
end
|
93
86
|
|
94
87
|
def test_find_with_distance_condition_with_formula_override
|
95
|
-
# locations = Location.find(:all, :origin => @loc_a, :formula => :flat, :conditions => "distance < 6.387")
|
96
88
|
locations = Location.geo_scope(:origin => @loc_a, :formula => :flat, :within => 6.387)
|
97
89
|
assert_equal 6, locations.all.size
|
98
|
-
# locations = Location.count(:origin => @loc_a, :formula => :flat, :conditions => "distance < 6.387")
|
99
90
|
assert_equal 6, locations.count
|
100
91
|
end
|
101
92
|
|
102
93
|
def test_find_within
|
103
94
|
locations = Location.within(3.97, :origin => @loc_a)
|
104
95
|
assert_equal 5, locations.all.size
|
105
|
-
# locations = Location.count_within(3.97, :origin => @loc_a)
|
106
96
|
assert_equal 5, locations.count
|
107
97
|
end
|
108
98
|
|
109
|
-
# def test_find_within_with_token
|
110
|
-
# locations = Location.find(:all, :within => 3.97, :origin => @loc_a)
|
111
|
-
# assert_equal 5, locations.size
|
112
|
-
# locations = Location.count(:within => 3.97, :origin => @loc_a)
|
113
|
-
# assert_equal 5, locations
|
114
|
-
# end
|
115
|
-
|
116
99
|
def test_find_within_with_coordinates
|
117
100
|
locations = Location.within(3.97, :origin =>[@loc_a.lat,@loc_a.lng])
|
118
101
|
assert_equal 5, locations.all.size
|
119
|
-
# locations = Location.count_within(3.97, :origin =>[@loc_a.lat,@loc_a.lng])
|
120
102
|
assert_equal 5, locations.count
|
121
103
|
end
|
122
104
|
|
123
105
|
def test_find_with_compound_condition
|
124
|
-
# locations = Location.find(:all, :origin => @loc_a, :conditions => "distance < 5 and city = 'Coppell'")
|
125
106
|
locations = Location.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
|
126
107
|
assert_equal 2, locations.all.size
|
127
|
-
# locations = Location.count(:origin => @loc_a, :conditions => "distance < 5 and city = 'Coppell'")
|
128
108
|
assert_equal 2, locations.count
|
129
109
|
end
|
130
110
|
|
131
111
|
def test_find_with_secure_compound_condition
|
132
|
-
# locations = Location.find(:all, :origin => @loc_a, :conditions => ["distance < ? and city = ?", 5, 'Coppell'])
|
133
112
|
locations = Location.geo_scope(:origin => @loc_a).where(["distance < ? and city = ?", 5, 'Coppell'])
|
134
113
|
assert_equal 2, locations.all.size
|
135
|
-
# locations = Location.count(:origin => @loc_a, :conditions => ["distance < ? and city = ?", 5, 'Coppell'])
|
136
114
|
assert_equal 2, locations.count
|
137
115
|
end
|
138
116
|
|
139
117
|
def test_find_beyond
|
140
|
-
# locations = Location.find_beyond(3.95, :origin => @loc_a)
|
141
118
|
locations = Location.beyond(3.95, :origin => @loc_a)
|
142
119
|
assert_equal 1, locations.all.size
|
143
|
-
# locations = Location.count_beyond(3.95, :origin => @loc_a)
|
144
120
|
assert_equal 1, locations.count
|
145
121
|
end
|
146
122
|
|
@@ -148,80 +124,56 @@ class ActsAsMappableTest < GeokitTestCase
|
|
148
124
|
# locations = Location.find(:all, :beyond => 3.95, :origin => @loc_a)
|
149
125
|
locations = Location.geo_scope(:beyond => 3.95, :origin => @loc_a)
|
150
126
|
assert_equal 1, locations.all.size
|
151
|
-
# locations = Location.count(:beyond => 3.95, :origin => @loc_a)
|
152
127
|
assert_equal 1, locations.count
|
153
128
|
end
|
154
129
|
|
155
130
|
def test_find_beyond_with_coordinates
|
156
|
-
# locations = Location.find_beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
157
131
|
locations = Location.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
158
132
|
assert_equal 1, locations.all.size
|
159
|
-
# locations = Location.count_beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
160
133
|
assert_equal 1, locations.count
|
161
134
|
end
|
162
135
|
|
163
136
|
def test_find_range_with_token
|
164
|
-
# locations = Location.find(:all, :range => 0..10, :origin => @loc_a)
|
165
137
|
locations = Location.geo_scope(:range => 0..10, :origin => @loc_a)
|
166
138
|
assert_equal 6, locations.all.size
|
167
|
-
# locations = Location.count(:range => 0..10, :origin => @loc_a)
|
168
139
|
assert_equal 6, locations.count
|
169
140
|
end
|
170
141
|
|
171
142
|
def test_find_range_with_token_with_conditions
|
172
|
-
# locations = Location.find(:all, :origin => @loc_a, :range => 0..10, :conditions => ["city = ?", 'Coppell'])
|
173
143
|
locations = Location.geo_scope(:origin => @loc_a, :range => 0..10).where(["city = ?", 'Coppell'])
|
174
144
|
assert_equal 2, locations.all.size
|
175
|
-
# locations = Location.count(:origin => @loc_a, :range => 0..10, :conditions => ["city = ?", 'Coppell'])
|
176
145
|
assert_equal 2, locations.count
|
177
146
|
end
|
178
147
|
|
179
148
|
def test_find_range_with_token_with_hash_conditions
|
180
|
-
# locations = Location.find(:all, :origin => @loc_a, :range => 0..10, :conditions => {:city => 'Coppell'})
|
181
149
|
locations = Location.geo_scope(:origin => @loc_a, :range => 0..10).where(:city => 'Coppell')
|
182
150
|
assert_equal 2, locations.all.size
|
183
|
-
# locations = Location.count(:origin => @loc_a, :range => 0..10, :conditions => {:city => 'Coppell'})
|
184
151
|
assert_equal 2, locations.count
|
185
152
|
end
|
186
153
|
|
187
154
|
def test_find_range_with_token_excluding_end
|
188
|
-
# locations = Location.find(:all, :range => 0...10, :origin => @loc_a)
|
189
155
|
locations = Location.geo_scope(:range => 0...10, :origin => @loc_a)
|
190
156
|
assert_equal 6, locations.all.size
|
191
|
-
# locations = Location.count(:range => 0...10, :origin => @loc_a)
|
192
157
|
assert_equal 6, locations.count
|
193
158
|
end
|
194
159
|
|
195
160
|
def test_find_nearest
|
196
|
-
# assert_equal @loc_a, Location.find_nearest(:origin => @loc_a)
|
197
161
|
assert_equal @loc_a, Location.nearest(:origin => @loc_a).first
|
198
162
|
end
|
199
163
|
|
200
|
-
# def test_find_nearest_through_find
|
201
|
-
# assert_equal @loc_a, Location.find(:nearest, :origin => @loc_a)
|
202
|
-
# end
|
203
|
-
|
204
164
|
def test_find_nearest_with_coordinates
|
205
|
-
# assert_equal @loc_a, Location.find_nearest(:origin =>[@loc_a.lat, @loc_a.lng])
|
206
165
|
assert_equal @loc_a, Location.nearest(:origin =>[@loc_a.lat, @loc_a.lng]).first
|
207
166
|
end
|
208
167
|
|
209
168
|
def test_find_farthest
|
210
|
-
# assert_equal @loc_e, Location.find_farthest(:origin => @loc_a)
|
211
169
|
assert_equal @loc_e, Location.farthest(:origin => @loc_a).first
|
212
170
|
end
|
213
171
|
|
214
|
-
# def test_find_farthest_through_find
|
215
|
-
# assert_equal @loc_e, Location.find(:farthest, :origin => @loc_a)
|
216
|
-
# end
|
217
|
-
|
218
172
|
def test_find_farthest_with_coordinates
|
219
|
-
# assert_equal @loc_e, Location.find_farthest(:origin =>[@loc_a.lat, @loc_a.lng])
|
220
173
|
assert_equal @loc_e, Location.farthest(:origin =>[@loc_a.lat, @loc_a.lng]).first
|
221
174
|
end
|
222
175
|
|
223
176
|
def test_scoped_distance_column_in_select
|
224
|
-
# locations = @starbucks.locations.find(:all, :origin => @loc_a, :order => "distance ASC")
|
225
177
|
locations = @starbucks.locations.geo_scope(:origin => @loc_a).order("distance ASC")
|
226
178
|
assert_equal 5, locations.all.size
|
227
179
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
@@ -229,50 +181,39 @@ class ActsAsMappableTest < GeokitTestCase
|
|
229
181
|
end
|
230
182
|
|
231
183
|
def test_scoped_find_with_distance_condition
|
232
|
-
# locations = @starbucks.locations.find(:all, :origin => @loc_a, :conditions => "distance < 3.97")
|
233
184
|
locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
234
185
|
assert_equal 4, locations.all.size
|
235
|
-
# locations = @starbucks.locations.count(:origin => @loc_a, :conditions => "distance < 3.97")
|
236
186
|
assert_equal 4, locations.count
|
237
187
|
end
|
238
188
|
|
239
189
|
def test_scoped_find_within
|
240
|
-
# locations = @starbucks.locations.find_within(3.97, :origin => @loc_a)
|
241
190
|
locations = @starbucks.locations.within(3.97, :origin => @loc_a)
|
242
191
|
assert_equal 4, locations.all.size
|
243
|
-
# locations = @starbucks.locations.count_within(3.97, :origin => @loc_a)
|
244
192
|
assert_equal 4, locations.count
|
245
193
|
end
|
246
194
|
|
247
195
|
def test_scoped_find_with_compound_condition
|
248
|
-
# locations = @starbucks.locations.find(:all, :origin => @loc_a, :conditions => "distance < 5 and city = 'Coppell'")
|
249
196
|
locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
|
250
197
|
assert_equal 2, locations.all.size
|
251
|
-
# locations = @starbucks.locations.count( :origin => @loc_a, :conditions => "distance < 5 and city = 'Coppell'")
|
252
198
|
assert_equal 2, locations.count
|
253
199
|
end
|
254
200
|
|
255
201
|
def test_scoped_find_beyond
|
256
|
-
# locations = @starbucks.locations.find_beyond(3.95, :origin => @loc_a)
|
257
202
|
locations = @starbucks.locations.beyond(3.95, :origin => @loc_a)
|
258
203
|
assert_equal 1, locations.all.size
|
259
|
-
# locations = @starbucks.locations.count_beyond(3.95, :origin => @loc_a)
|
260
204
|
assert_equal 1, locations.count
|
261
205
|
end
|
262
206
|
|
263
207
|
def test_scoped_find_nearest
|
264
|
-
# assert_equal @loc_a, @starbucks.locations.find_nearest(:origin => @loc_a).first
|
265
208
|
assert_equal @loc_a, @starbucks.locations.nearest(:origin => @loc_a).first
|
266
209
|
end
|
267
210
|
|
268
211
|
def test_scoped_find_farthest
|
269
|
-
# assert_equal @loc_e, @starbucks.locations.find_farthest(:origin => @loc_a).first
|
270
212
|
assert_equal @loc_e, @starbucks.locations.farthest(:origin => @loc_a).first
|
271
213
|
end
|
272
214
|
|
273
215
|
def test_ip_geocoded_distance_column_in_select
|
274
216
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
275
|
-
# locations = Location.find(:all, :origin => LOCATION_A_IP, :order => "distance ASC")
|
276
217
|
locations = Location.geo_scope(:origin => LOCATION_A_IP).order("distance ASC")
|
277
218
|
assert_equal 6, locations.all.size
|
278
219
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
@@ -281,92 +222,70 @@ class ActsAsMappableTest < GeokitTestCase
|
|
281
222
|
|
282
223
|
def test_ip_geocoded_find_with_distance_condition
|
283
224
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
284
|
-
# locations = Location.find(:all, :origin => LOCATION_A_IP, :conditions => "distance < 3.97")
|
285
225
|
locations = Location.geo_scope(:origin => LOCATION_A_IP).where2("distance < 3.97")
|
286
226
|
assert_equal 5, locations.all.size
|
287
|
-
# GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
288
|
-
# locations = Location.count(:origin => LOCATION_A_IP, :conditions => "distance < 3.97")
|
289
227
|
assert_equal 5, locations.count
|
290
228
|
end
|
291
229
|
|
292
230
|
def test_ip_geocoded_find_within
|
293
231
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
294
|
-
# locations = Location.find_within(3.97, :origin => LOCATION_A_IP)
|
295
232
|
locations = Location.within(3.97, :origin => LOCATION_A_IP)
|
296
233
|
assert_equal 5, locations.all.size
|
297
|
-
# GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
298
|
-
# locations = Location.count_within(3.97, :origin => LOCATION_A_IP)
|
299
234
|
assert_equal 5, locations.count
|
300
235
|
end
|
301
236
|
|
302
237
|
def test_ip_geocoded_find_with_compound_condition
|
303
238
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
304
|
-
# locations = Location.find(:all, :origin => LOCATION_A_IP, :conditions => "distance < 5 and city = 'Coppell'")
|
305
239
|
locations = Location.geo_scope(:origin => LOCATION_A_IP).where("distance < 5 and city = 'Coppell'")
|
306
240
|
assert_equal 2, locations.all.size
|
307
|
-
# GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
308
|
-
# locations = Location.count(:origin => LOCATION_A_IP, :conditions => "distance < 5 and city = 'Coppell'")
|
309
241
|
assert_equal 2, locations.count
|
310
242
|
end
|
311
243
|
|
312
244
|
def test_ip_geocoded_find_with_secure_compound_condition
|
313
245
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
314
|
-
# locations = Location.find(:all, :origin => LOCATION_A_IP, :conditions => ["distance < ? and city = ?", 5, 'Coppell'])
|
315
246
|
locations = Location.geo_scope(:origin => LOCATION_A_IP).where(["distance < ? and city = ?", 5, 'Coppell'])
|
316
247
|
assert_equal 2, locations.all.size
|
317
|
-
# GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
318
|
-
# locations = Location.count(:origin => LOCATION_A_IP, :conditions => ["distance < ? and city = ?", 5, 'Coppell'])
|
319
248
|
assert_equal 2, locations.count
|
320
249
|
end
|
321
250
|
|
322
251
|
def test_ip_geocoded_find_beyond
|
323
252
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
324
|
-
# locations = Location.find_beyond(3.95, :origin => LOCATION_A_IP)
|
325
253
|
locations = Location.beyond(3.95, :origin => LOCATION_A_IP)
|
326
254
|
assert_equal 1, locations.all.size
|
327
|
-
# GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
328
|
-
# locations = Location.count_beyond(3.95, :origin => LOCATION_A_IP)
|
329
255
|
assert_equal 1, locations.count
|
330
256
|
end
|
331
257
|
|
332
258
|
def test_ip_geocoded_find_nearest
|
333
259
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
334
|
-
# assert_equal @loc_a, Location.find_nearest(:origin => LOCATION_A_IP)
|
335
260
|
assert_equal @loc_a, Location.nearest(:origin => LOCATION_A_IP).first
|
336
261
|
end
|
337
262
|
|
338
263
|
def test_ip_geocoded_find_farthest
|
339
264
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
340
|
-
# assert_equal @loc_e, Location.find_farthest(:origin => LOCATION_A_IP)
|
341
265
|
assert_equal @loc_e, Location.farthest(:origin => LOCATION_A_IP).first
|
342
266
|
end
|
343
267
|
|
344
268
|
def test_ip_geocoder_exception
|
345
269
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with('127.0.0.1').returns(GeoKit::GeoLoc.new)
|
346
270
|
assert_raises GeoKit::Geocoders::GeocodeError do
|
347
|
-
# Location.find_farthest(:origin => '127.0.0.1')
|
348
271
|
Location.farthest(:origin => '127.0.0.1').first
|
349
272
|
end
|
350
273
|
end
|
351
274
|
|
352
275
|
def test_address_geocode
|
353
276
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with('Irving, TX').returns(@location_a)
|
354
|
-
# locations = Location.find(:all, :origin => 'Irving, TX', :conditions => ["distance < ? and city = ?", 5, 'Coppell'])
|
355
277
|
locations = Location.geo_scope(:origin => 'Irving, TX').where(["distance < ? and city = ?", 5, 'Coppell'])
|
356
278
|
assert_equal 2, locations.all.size
|
357
279
|
assert_equal 2, locations.count
|
358
280
|
end
|
359
281
|
|
360
282
|
def test_find_with_custom_distance_condition
|
361
|
-
# locations = CustomLocation.find(:all, :origin => @loc_a, :conditions => "dist < 3.97")
|
362
283
|
locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 3.97")
|
363
284
|
assert_equal 5, locations.all.size
|
364
|
-
# locations = CustomLocation.count(:origin => @loc_a, :conditions => "dist < 3.97")
|
365
285
|
assert_equal 5, locations.count
|
366
286
|
end
|
367
287
|
|
368
288
|
def test_find_with_custom_distance_condition_using_custom_origin
|
369
|
-
# locations = CustomLocation.find(:all, :origin => @custom_loc_a, :conditions => "dist < 3.97")
|
370
289
|
locations = CustomLocation.geo_scope(:origin => @custom_loc_a).where("dist < 3.97")
|
371
290
|
assert_equal 5, locations.all.size
|
372
291
|
locations = CustomLocation.count(:origin => @custom_loc_a).where("dist < 3.97")
|
@@ -374,78 +293,60 @@ class ActsAsMappableTest < GeokitTestCase
|
|
374
293
|
end
|
375
294
|
|
376
295
|
def test_find_within_with_custom
|
377
|
-
# locations = CustomLocation.find_within(3.97, :origin => @loc_a)
|
378
296
|
locations = CustomLocation.within(3.97, :origin => @loc_a)
|
379
297
|
assert_equal 5, locations.all.size
|
380
|
-
# locations = CustomLocation.count_within(3.97, :origin => @loc_a)
|
381
298
|
assert_equal 5, locations.count
|
382
299
|
end
|
383
300
|
|
384
301
|
def test_find_within_with_coordinates_with_custom
|
385
|
-
# locations = CustomLocation.find_within(3.97, :origin =>[@loc_a.lat, @loc_a.lng])
|
386
302
|
locations = CustomLocation.within(3.97, :origin =>[@loc_a.lat, @loc_a.lng])
|
387
303
|
assert_equal 5, locations.all.size
|
388
|
-
# locations = CustomLocation.count_within(3.97, :origin =>[@loc_a.lat, @loc_a.lng])
|
389
304
|
assert_equal 5, locations.count
|
390
305
|
end
|
391
306
|
|
392
307
|
def test_find_with_compound_condition_with_custom
|
393
|
-
# locations = CustomLocation.find(:all, :origin => @loc_a, :conditions => "dist < 5 and city = 'Coppell'")
|
394
308
|
locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 5 and city = 'Coppell'")
|
395
309
|
assert_equal 1, locations.all.size
|
396
|
-
# locations = CustomLocation.count(:origin => @loc_a, :conditions => "dist < 5 and city = 'Coppell'")
|
397
310
|
assert_equal 1, locations.count
|
398
311
|
end
|
399
312
|
|
400
313
|
def test_find_with_secure_compound_condition_with_custom
|
401
|
-
# locations = CustomLocation.find(:all, :origin => @loc_a, :conditions => ["dist < ? and city = ?", 5, 'Coppell'])
|
402
314
|
locations = CustomLocation.geo_scope(:origin => @loc_a).where(["dist < ? and city = ?", 5, 'Coppell'])
|
403
315
|
assert_equal 1, locations.all.size
|
404
|
-
# locations = CustomLocation.count(:origin => @loc_a, :conditions => ["dist < ? and city = ?", 5, 'Coppell'])
|
405
316
|
assert_equal 1, locations.count
|
406
317
|
end
|
407
318
|
|
408
319
|
def test_find_beyond_with_custom
|
409
|
-
# locations = CustomLocation.find_beyond(3.95, :origin => @loc_a)
|
410
320
|
locations = CustomLocation.beyond(3.95, :origin => @loc_a)
|
411
321
|
assert_equal 1, locations.all.size
|
412
|
-
# locations = CustomLocation.count_beyond(3.95, :origin => @loc_a)
|
413
322
|
assert_equal 1, locations.count
|
414
323
|
end
|
415
324
|
|
416
325
|
def test_find_beyond_with_coordinates_with_custom
|
417
|
-
# locations = CustomLocation.find_beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
418
326
|
locations = CustomLocation.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
419
327
|
assert_equal 1, locations.all.size
|
420
|
-
# locations = CustomLocation.count_beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
421
328
|
assert_equal 1, locations.count
|
422
329
|
end
|
423
330
|
|
424
331
|
def test_find_nearest_with_custom
|
425
|
-
# assert_equal @custom_loc_a, CustomLocation.find_nearest(:origin => @loc_a)
|
426
332
|
assert_equal @custom_loc_a, CustomLocation.nearest(:origin => @loc_a).first
|
427
333
|
end
|
428
334
|
|
429
335
|
def test_find_nearest_with_coordinates_with_custom
|
430
|
-
# assert_equal @custom_loc_a, CustomLocation.find_nearest(:origin =>[@loc_a.lat, @loc_a.lng])
|
431
336
|
assert_equal @custom_loc_a, CustomLocation.nearest(:origin =>[@loc_a.lat, @loc_a.lng]).first
|
432
337
|
end
|
433
338
|
|
434
339
|
def test_find_farthest_with_custom
|
435
|
-
# assert_equal @custom_loc_e, CustomLocation.find_farthest(:origin => @loc_a)
|
436
340
|
assert_equal @custom_loc_e, CustomLocation.farthest(:origin => @loc_a).first
|
437
341
|
end
|
438
342
|
|
439
343
|
def test_find_farthest_with_coordinates_with_custom
|
440
|
-
# assert_equal @custom_loc_e, CustomLocation.find_farthest(:origin =>[@loc_a.lat, @loc_a.lng])
|
441
344
|
assert_equal @custom_loc_e, CustomLocation.farthest(:origin =>[@loc_a.lat, @loc_a.lng]).first
|
442
345
|
end
|
443
346
|
|
444
347
|
def test_find_with_array_origin
|
445
|
-
# locations = Location.find(:all, :origin =>[@loc_a.lat,@loc_a.lng], :conditions => "distance < 3.97")
|
446
348
|
locations = Location.geo_scope(:origin =>[@loc_a.lat,@loc_a.lng]).where("distance < 3.97")
|
447
349
|
assert_equal 5, locations.all.size
|
448
|
-
# locations = Location.count(:origin =>[@loc_a.lat,@loc_a.lng], :conditions => "distance < 3.97")
|
449
350
|
assert_equal 5, locations.count
|
450
351
|
end
|
451
352
|
|
@@ -453,42 +354,34 @@ class ActsAsMappableTest < GeokitTestCase
|
|
453
354
|
# Bounding box tests
|
454
355
|
|
455
356
|
def test_find_within_bounds
|
456
|
-
# locations = Location.find_within_bounds([@sw,@ne])
|
457
357
|
locations = Location.in_bounds([@sw,@ne])
|
458
358
|
assert_equal 2, locations.all.size
|
459
|
-
# locations = Location.count_within_bounds([@sw,@ne])
|
460
359
|
assert_equal 2, locations.count
|
461
360
|
end
|
462
361
|
|
463
362
|
def test_find_within_bounds_ordered_by_distance
|
464
|
-
# locations = Location.find_within_bounds([@sw,@ne], :origin=>@bounds_center, :order=>'distance asc')
|
465
363
|
locations = Location.in_bounds([@sw,@ne], :origin=>@bounds_center).order('distance asc')
|
466
364
|
assert_equal locations[0], locations(:d)
|
467
365
|
assert_equal locations[1], locations(:a)
|
468
366
|
end
|
469
367
|
|
470
368
|
def test_find_within_bounds_with_token
|
471
|
-
# locations = Location.find(:all, :bounds=>[@sw,@ne])
|
472
369
|
locations = Location.geo_scope(:bounds=>[@sw,@ne])
|
473
370
|
assert_equal 2, locations.all.size
|
474
|
-
# locations = Location.count(:bounds=>[@sw,@ne])
|
475
371
|
assert_equal 2, locations.count
|
476
372
|
end
|
477
373
|
|
478
374
|
def test_find_within_bounds_with_string_conditions
|
479
|
-
# locations = Location.find(:all, :bounds=>[@sw,@ne], :conditions=>"id !=#{locations(:a).id}")
|
480
375
|
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where("id !=#{locations(:a).id}")
|
481
376
|
assert_equal 1, locations.all.size
|
482
377
|
end
|
483
378
|
|
484
379
|
def test_find_within_bounds_with_array_conditions
|
485
|
-
# locations = Location.find(:all, :bounds=>[@sw,@ne], :conditions=>["id != ?", locations(:a).id])
|
486
380
|
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where(["id != ?", locations(:a).id])
|
487
381
|
assert_equal 1, locations.all.size
|
488
382
|
end
|
489
383
|
|
490
384
|
def test_find_within_bounds_with_hash_conditions
|
491
|
-
# locations = Location.find(:all, :bounds=>[@sw,@ne], :conditions=>{:id => locations(:a).id})
|
492
385
|
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where({:id => locations(:a).id})
|
493
386
|
assert_equal 1, locations.all.size
|
494
387
|
end
|
@@ -513,19 +406,15 @@ class ActsAsMappableTest < GeokitTestCase
|
|
513
406
|
# Test :through
|
514
407
|
|
515
408
|
def test_find_with_through
|
516
|
-
# organizations = MockOrganization.find(:all, :origin => @location_a, :order => 'distance ASC')
|
517
409
|
organizations = MockOrganization.geo_scope(:origin => @location_a).order('distance ASC')
|
518
410
|
assert_equal 2, organizations.all.size
|
519
|
-
# organizations = MockOrganization.count(:origin => @location_a, :conditions => "distance < 3.97")
|
520
411
|
organizations = MockOrganization.geo_scope(:origin => @location_a).where("distance < 3.97")
|
521
412
|
assert_equal 1, organizations.count
|
522
413
|
end
|
523
414
|
|
524
415
|
def test_find_with_through_with_hash
|
525
|
-
# people = MockPerson.find(:all, :origin => @location_a, :order => 'distance ASC')
|
526
416
|
people = MockPerson.geo_scope(:origin => @location_a).order('distance ASC')
|
527
417
|
assert_equal 2, people.size
|
528
|
-
# people = MockPerson.count(:origin => @location_a, :conditions => "distance < 3.97")
|
529
418
|
assert_equal 2, people
|
530
419
|
end
|
531
420
|
end
|