geokit-rails 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of geokit-rails might be problematic. Click here for more details.
- checksums.yaml +8 -8
- data/lib/geokit-rails/acts_as_mappable.rb +87 -68
- data/lib/geokit-rails/adapters/mysql2.rb +4 -18
- data/lib/geokit-rails/adapters/mysql2spatial.rb +8 -0
- data/lib/geokit-rails/version.rb +1 -1
- data/test/acts_as_mappable_test.rb +106 -93
- data/test/database.yml +4 -0
- data/test/mysql-debug.log +1057 -0
- data/test/mysql2-debug.log +2758 -0
- data/test/mysql2spatial-debug.log +3619 -0
- data/test/sqlite-debug.log +44802 -0
- data/test/test.sqlite3 +0 -0
- data/test/test_helper.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDM3YThmODQ4MTE4ZDFlNWJjN2UxNmY2N2Q1NzcxODYxM2E0OTA2Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDUxYzUyMWExNzNiMDBkZWJjMTRkOWI1NzExNTY3NTM3Zjk2NDRjZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGYwMTc5MWZjYTk0YmFjNTJhZGYyNTE0MjAyZmM1ZjhlYjViNTEzMWIzNmVk
|
10
|
+
NGVkMmFjMjQ0NjA3NjJhYWIzMzQyYTI3OTBmZjFkYWQxOGE3ODg0NzI2OTc1
|
11
|
+
MjliZmFkYTk0YjM4MTFkZDFmZDBhNWU2YjAzNjg3MDdiNWE1OTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTFiYTJiZmRhZTRiMTA1NjEyNDYyODU2ZWQwZDlhY2FkODQ4YzNlYTdkN2Y2
|
14
|
+
YWQ0NjkyYjg4ZjgwODdjMjMxNzM4ODk3NzQyODk3MjA0MzJlODYwNDk4YjFm
|
15
|
+
OTU3YWZlM2JmOGU1ODE1YzIyNjcyNTg0MmZjZjU2MGE3OGQwNjc=
|
@@ -53,33 +53,33 @@ module Geokit
|
|
53
53
|
end
|
54
54
|
end # Glue
|
55
55
|
|
56
|
-
class Relation < ActiveRecord::Relation
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
56
|
+
#class Relation < ActiveRecord::Relation
|
57
|
+
# attr_accessor :distance_formula
|
58
|
+
|
59
|
+
# def where(opts, *rest)
|
60
|
+
# return self if opts.blank?
|
61
|
+
# relation = clone
|
62
|
+
# where_values = build_where(opts, rest)
|
63
|
+
# relation.where_values += substitute_distance_in_values(where_values)
|
64
|
+
# relation
|
65
|
+
# end
|
66
|
+
|
67
|
+
# def order(*args)
|
68
|
+
# return self if args.blank?
|
69
|
+
# relation = clone
|
70
|
+
# order_values = args.flatten
|
71
|
+
# relation.order_values += substitute_distance_in_values(order_values)
|
72
|
+
# relation
|
73
|
+
# end
|
74
|
+
|
75
|
+
#private
|
76
|
+
# def substitute_distance_in_values(values)
|
77
|
+
# return values unless @distance_formula
|
78
|
+
# # substitute distance with the actual distance equation
|
79
|
+
# pattern = Regexp.new("\\b#{@klass.distance_column_name}\\b")
|
80
|
+
# values.map {|value| value.is_a?(String) ? value.gsub(pattern, @distance_formula) : value }
|
81
|
+
# end
|
82
|
+
#end
|
83
83
|
|
84
84
|
extend ActiveSupport::Concern
|
85
85
|
|
@@ -104,28 +104,40 @@ module Geokit
|
|
104
104
|
|
105
105
|
def within(distance, options = {})
|
106
106
|
options[:within] = distance
|
107
|
-
geo_scope(options)
|
107
|
+
#geo_scope(options)
|
108
|
+
where(distance_conditions(options))
|
108
109
|
end
|
109
110
|
alias inside within
|
110
111
|
|
111
112
|
def beyond(distance, options = {})
|
112
113
|
options[:beyond] = distance
|
113
|
-
geo_scope(options)
|
114
|
+
#geo_scope(options)
|
115
|
+
where(distance_conditions(options))
|
114
116
|
end
|
115
117
|
alias outside beyond
|
116
118
|
|
117
119
|
def in_range(range, options = {})
|
118
120
|
options[:range] = range
|
119
|
-
geo_scope(options)
|
121
|
+
#geo_scope(options)
|
122
|
+
where(distance_conditions(options))
|
120
123
|
end
|
121
124
|
|
122
125
|
def in_bounds(bounds, options = {})
|
123
126
|
options[:bounds] = bounds
|
124
|
-
geo_scope(options)
|
127
|
+
#geo_scope(options)
|
128
|
+
#where(distance_conditions(options))
|
129
|
+
bounds = extract_bounds_from_options(options)
|
130
|
+
where(bound_conditions(bounds))
|
125
131
|
end
|
126
132
|
|
127
133
|
def by_distance(options = {})
|
128
|
-
|
134
|
+
origin = extract_origin_from_options(options)
|
135
|
+
units = extract_units_from_options(options)
|
136
|
+
formula = extract_formula_from_options(options)
|
137
|
+
bounds = extract_bounds_from_options(options)
|
138
|
+
distance_column_name = distance_sql(origin, units, formula)
|
139
|
+
#geo_scope(options).order("#{distance_column_name} asc")
|
140
|
+
order("#{distance_column_name} asc")
|
129
141
|
end
|
130
142
|
|
131
143
|
def closest(options = {})
|
@@ -137,41 +149,41 @@ module Geokit
|
|
137
149
|
by_distance(options).last(1)
|
138
150
|
end
|
139
151
|
|
140
|
-
def geo_scope(options = {})
|
141
|
-
|
152
|
+
#def geo_scope(options = {})
|
153
|
+
# arel = self.is_a?(ActiveRecord::Relation) ? self : self.scoped
|
142
154
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
155
|
+
# origin = extract_origin_from_options(options)
|
156
|
+
# units = extract_units_from_options(options)
|
157
|
+
# formula = extract_formula_from_options(options)
|
158
|
+
# bounds = extract_bounds_from_options(options)
|
147
159
|
|
148
|
-
|
149
|
-
|
160
|
+
# if origin || bounds
|
161
|
+
# bounds = formulate_bounds_from_distance(options, origin, units) unless bounds
|
150
162
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
163
|
+
# if origin
|
164
|
+
# arel.distance_formula = distance_sql(origin, units, formula)
|
165
|
+
#
|
166
|
+
# if arel.select_values.blank?
|
167
|
+
# star_select = Arel::SqlLiteral.new(arel.quoted_table_name + '.*')
|
168
|
+
# arel = arel.select(star_select)
|
169
|
+
# end
|
170
|
+
# end
|
159
171
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
172
|
+
# if bounds
|
173
|
+
# bound_conditions = bound_conditions(bounds)
|
174
|
+
# arel = arel.where(bound_conditions) if bound_conditions
|
175
|
+
# end
|
164
176
|
|
165
|
-
|
166
|
-
|
177
|
+
# distance_conditions = distance_conditions(options)
|
178
|
+
# arel = arel.where(distance_conditions) if distance_conditions
|
167
179
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
180
|
+
# if self.through
|
181
|
+
# arel = arel.includes(self.through)
|
182
|
+
# end
|
183
|
+
# end
|
172
184
|
|
173
|
-
|
174
|
-
end
|
185
|
+
# arel
|
186
|
+
#end
|
175
187
|
|
176
188
|
# Returns the distance calculation to be used as a display column or a condition. This
|
177
189
|
# is provide for anyone wanting access to the raw SQL.
|
@@ -189,12 +201,12 @@ module Geokit
|
|
189
201
|
|
190
202
|
# Override ActiveRecord::Base.relation to return an instance of Geokit::ActsAsMappable::Relation.
|
191
203
|
# TODO: Do we need to override JoinDependency#relation too?
|
192
|
-
def relation
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
204
|
+
#def relation
|
205
|
+
# # NOTE: This cannot be @relation as ActiveRecord already uses this to
|
206
|
+
# # cache *its* Relation object
|
207
|
+
# @_geokit_relation ||= Relation.new(self, arel_table)
|
208
|
+
# finder_needs_type_condition? ? @_geokit_relation.where(type_condition) : @_geokit_relation
|
209
|
+
#end
|
198
210
|
|
199
211
|
# If it's a :within query, add a bounding box to improve performance.
|
200
212
|
# This only gets called if a :bounds argument is not otherwise supplied.
|
@@ -209,6 +221,12 @@ module Geokit
|
|
209
221
|
end
|
210
222
|
|
211
223
|
def distance_conditions(options)
|
224
|
+
origin = extract_origin_from_options(options)
|
225
|
+
units = extract_units_from_options(options)
|
226
|
+
formula = extract_formula_from_options(options)
|
227
|
+
bounds = extract_bounds_from_options(options)
|
228
|
+
distance_column_name = distance_sql(origin, units, formula)
|
229
|
+
|
212
230
|
res = if options.has_key?(:within)
|
213
231
|
"#{distance_column_name} <= #{options[:within]}"
|
214
232
|
elsif options.has_key?(:beyond)
|
@@ -223,7 +241,8 @@ module Geokit
|
|
223
241
|
sw,ne = bounds.sw, bounds.ne
|
224
242
|
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}"
|
225
243
|
res = "#{qualified_lat_column_name}>#{sw.lat} AND #{qualified_lat_column_name}<#{ne.lat} AND #{lng_sql}"
|
226
|
-
Arel::SqlLiteral.new("(#{res})") if res.present?
|
244
|
+
#Arel::SqlLiteral.new("(#{res})") if res.present?
|
245
|
+
res if res.present?
|
227
246
|
end
|
228
247
|
|
229
248
|
# Extracts the origin instance out of the options if it exists and returns
|
@@ -353,4 +372,4 @@ end # Geokit
|
|
353
372
|
|
354
373
|
|
355
374
|
|
356
|
-
# ActiveRecord::Base.extend Geokit::ActsAsMappable
|
375
|
+
# ActiveRecord::Base.extend Geokit::ActsAsMappable
|
@@ -1,22 +1,8 @@
|
|
1
|
+
require 'geokit-rails/adapters/mysql'
|
2
|
+
|
1
3
|
module Geokit
|
2
4
|
module Adapters
|
3
|
-
class Mysql2 <
|
4
|
-
|
5
|
-
def sphere_distance_sql(lat, lng, multiplier)
|
6
|
-
%|
|
7
|
-
(ACOS(least(1,COS(#{lat})*COS(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*COS(RADIANS(#{qualified_lng_column_name}))+
|
8
|
-
COS(#{lat})*SIN(#{lng})*COS(RADIANS(#{qualified_lat_column_name}))*SIN(RADIANS(#{qualified_lng_column_name}))+
|
9
|
-
SIN(#{lat})*SIN(RADIANS(#{qualified_lat_column_name}))))*#{multiplier})
|
10
|
-
|
|
11
|
-
end
|
12
|
-
|
13
|
-
def flat_distance_sql(origin, lat_degree_units, lng_degree_units)
|
14
|
-
%|
|
15
|
-
SQRT(POW(#{lat_degree_units}*(#{origin.lat}-#{qualified_lat_column_name}),2)+
|
16
|
-
POW(#{lng_degree_units}*(#{origin.lng}-#{qualified_lng_column_name}),2))
|
17
|
-
|
|
18
|
-
end
|
19
|
-
|
5
|
+
class Mysql2 < MySQL
|
20
6
|
end
|
21
7
|
end
|
22
|
-
end
|
8
|
+
end
|
data/lib/geokit-rails/version.rb
CHANGED
@@ -29,26 +29,18 @@ class ActsAsMappableTest < GeokitTestCase
|
|
29
29
|
@address = mock_addresses(:address_barnes_and_noble)
|
30
30
|
end
|
31
31
|
|
32
|
-
def test_sort_by_distance_from
|
33
|
-
locations = Location.all
|
34
|
-
unsorted = [locations(:a), locations(:b), locations(:c), locations(:d), locations(:e), locations(:f)]
|
35
|
-
sorted = [locations(:a), locations(:b), locations(:c), locations(:f), locations(:d), locations(:e)]
|
36
|
-
assert_equal unsorted, locations
|
37
|
-
assert_equal sorted, locations.sort_by{|l| l.distance_to(locations(:a))}
|
38
|
-
assert_equal sorted, locations.sort_by_distance_from(locations(:a))
|
39
|
-
assert_equal sorted, locations # last action desctructive
|
40
|
-
end
|
41
|
-
|
42
32
|
def test_override_default_units_the_hard_way
|
43
33
|
Location.default_units = :kms
|
44
|
-
locations = Location.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
45
|
-
|
34
|
+
#locations = Location.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
35
|
+
locations = Location.within(3.9, :origin => @loc_a)
|
36
|
+
assert_equal 5, locations.to_a.size
|
46
37
|
assert_equal 5, locations.count
|
47
38
|
Location.default_units = :miles
|
48
39
|
end
|
49
40
|
|
50
41
|
def test_include
|
51
|
-
locations = Location.geo_scope(:origin => @loc_a).includes(:company).where("company_id = 1").all
|
42
|
+
#locations = Location.geo_scope(:origin => @loc_a).includes(:company).where("company_id = 1").all
|
43
|
+
locations = Location.includes(:company).where("company_id = 1").to_a
|
52
44
|
assert !locations.empty?
|
53
45
|
assert_equal 1, locations[0].company.id
|
54
46
|
assert_equal 'Starbucks', locations[0].company.name
|
@@ -76,94 +68,102 @@ class ActsAsMappableTest < GeokitTestCase
|
|
76
68
|
end
|
77
69
|
|
78
70
|
def test_distance_column_in_select
|
79
|
-
locations = Location.geo_scope(:origin => @loc_a).order("distance ASC")
|
80
|
-
|
71
|
+
#locations = Location.geo_scope(:origin => @loc_a).order("distance ASC")
|
72
|
+
locations = Location.by_distance(:origin => @loc_a)
|
73
|
+
assert_equal 6, locations.to_a.size
|
81
74
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
82
75
|
assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
|
83
76
|
end
|
84
77
|
|
85
78
|
def test_find_with_distance_condition
|
86
|
-
locations = Location.geo_scope(:origin => @loc_a, :within => 3.97)
|
87
|
-
|
79
|
+
#locations = Location.geo_scope(:origin => @loc_a, :within => 3.97)
|
80
|
+
locations = Location.within(3.97, :origin => @loc_a)
|
81
|
+
assert_equal 5, locations.to_a.size
|
88
82
|
assert_equal 5, locations.count
|
89
83
|
end
|
90
84
|
|
91
85
|
def test_find_with_distance_condition_with_units_override
|
92
|
-
locations = Location.geo_scope(:origin => @loc_a, :units => :kms, :within => 6.387)
|
93
|
-
|
86
|
+
#locations = Location.geo_scope(:origin => @loc_a, :units => :kms, :within => 6.387)
|
87
|
+
locations = Location.within(6.387, :origin => @loc_a, :units => :kms)
|
88
|
+
assert_equal 5, locations.to_a.size
|
94
89
|
assert_equal 5, locations.count
|
95
90
|
end
|
96
91
|
|
97
92
|
def test_find_with_distance_condition_with_formula_override
|
98
|
-
locations = Location.geo_scope(:origin => @loc_a, :formula => :flat, :within => 6.387)
|
99
|
-
|
93
|
+
#locations = Location.geo_scope(:origin => @loc_a, :formula => :flat, :within => 6.387)
|
94
|
+
locations = Location.within(6.387, :origin => @loc_a, :formula => :flat)
|
95
|
+
assert_equal 6, locations.to_a.size
|
100
96
|
assert_equal 6, locations.count
|
101
97
|
end
|
102
98
|
|
103
99
|
def test_find_within
|
104
100
|
locations = Location.within(3.97, :origin => @loc_a)
|
105
|
-
assert_equal 5, locations.
|
101
|
+
assert_equal 5, locations.to_a.size
|
106
102
|
assert_equal 5, locations.count
|
107
103
|
end
|
108
104
|
|
109
105
|
def test_find_within_with_coordinates
|
110
106
|
locations = Location.within(3.97, :origin =>[@loc_a.lat,@loc_a.lng])
|
111
|
-
assert_equal 5, locations.
|
107
|
+
assert_equal 5, locations.to_a.size
|
112
108
|
assert_equal 5, locations.count
|
113
109
|
end
|
114
110
|
|
115
111
|
def test_find_with_compound_condition
|
116
|
-
locations = Location.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
|
117
|
-
|
112
|
+
#locations = Location.geo_scope(:origin => @loc_a).where("distance < 5 and city = 'Coppell'")
|
113
|
+
locations = Location.within(5, :origin => @loc_a).where("city = 'Coppell'")
|
114
|
+
assert_equal 2, locations.to_a.size
|
118
115
|
assert_equal 2, locations.count
|
119
116
|
end
|
120
117
|
|
121
118
|
def test_find_with_secure_compound_condition
|
122
|
-
locations = Location.geo_scope(:origin => @loc_a).where(["distance < ? and city = ?", 5, 'Coppell'])
|
123
|
-
|
119
|
+
#locations = Location.geo_scope(:origin => @loc_a).where(["distance < ? and city = ?", 5, 'Coppell'])
|
120
|
+
locations = Location.within(5, :origin => @loc_a).where(["city = ?", 'Coppell'])
|
121
|
+
assert_equal 2, locations.to_a.size
|
124
122
|
assert_equal 2, locations.count
|
125
123
|
end
|
126
124
|
|
127
125
|
def test_find_beyond
|
128
126
|
locations = Location.beyond(3.95, :origin => @loc_a)
|
129
|
-
assert_equal 1, locations.
|
127
|
+
assert_equal 1, locations.to_a.size
|
130
128
|
assert_equal 1, locations.count
|
131
129
|
end
|
132
130
|
|
133
131
|
def test_find_beyond_with_token
|
134
132
|
# locations = Location.find(:all, :beyond => 3.95, :origin => @loc_a)
|
135
|
-
locations = Location.geo_scope(:beyond => 3.95, :origin => @loc_a)
|
136
|
-
|
133
|
+
#locations = Location.geo_scope(:beyond => 3.95, :origin => @loc_a)
|
134
|
+
locations = Location.beyond(3.95, :origin => @loc_a)
|
135
|
+
assert_equal 1, locations.to_a.size
|
137
136
|
assert_equal 1, locations.count
|
138
137
|
end
|
139
138
|
|
140
139
|
def test_find_beyond_with_coordinates
|
141
140
|
locations = Location.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
142
|
-
assert_equal 1, locations.
|
141
|
+
assert_equal 1, locations.to_a.size
|
143
142
|
assert_equal 1, locations.count
|
144
143
|
end
|
145
144
|
|
146
145
|
def test_find_range_with_token
|
147
|
-
locations = Location.
|
148
|
-
assert_equal 6, locations.
|
146
|
+
locations = Location.in_range(0..10, :origin => @loc_a)
|
147
|
+
assert_equal 6, locations.to_a.size
|
149
148
|
assert_equal 6, locations.count
|
150
149
|
end
|
151
150
|
|
152
151
|
def test_find_range_with_token_with_conditions
|
153
|
-
locations = Location.
|
154
|
-
assert_equal 2, locations.
|
152
|
+
locations = Location.in_range(0..10, :origin => @loc_a).where(["city = ?", 'Coppell'])
|
153
|
+
assert_equal 2, locations.to_a.size
|
155
154
|
assert_equal 2, locations.count
|
156
155
|
end
|
157
156
|
|
158
157
|
def test_find_range_with_token_with_hash_conditions
|
159
|
-
locations = Location.
|
160
|
-
assert_equal 2, locations.
|
158
|
+
locations = Location.in_range(0..10, :origin => @loc_a).where(:city => 'Coppell')
|
159
|
+
assert_equal 2, locations.to_a.size
|
161
160
|
assert_equal 2, locations.count
|
162
161
|
end
|
163
162
|
|
164
163
|
def test_find_range_with_token_excluding_end
|
165
|
-
locations = Location.geo_scope(:range => 0...10, :origin => @loc_a)
|
166
|
-
|
164
|
+
#locations = Location.geo_scope(:range => 0...10, :origin => @loc_a)
|
165
|
+
locations = Location.in_range(0...10, :origin => @loc_a)
|
166
|
+
assert_equal 6, locations.to_a.size
|
167
167
|
assert_equal 6, locations.count
|
168
168
|
end
|
169
169
|
|
@@ -184,33 +184,35 @@ class ActsAsMappableTest < GeokitTestCase
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def test_scoped_distance_column_in_select
|
187
|
-
locations = @starbucks.locations.geo_scope(:origin => @loc_a).order("distance ASC")
|
188
|
-
|
187
|
+
#locations = @starbucks.locations.geo_scope(:origin => @loc_a).order("distance ASC")
|
188
|
+
locations = @starbucks.locations.by_distance(:origin => @loc_a)
|
189
|
+
assert_equal 5, locations.to_a.size
|
189
190
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
190
191
|
assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
|
191
192
|
end
|
192
193
|
|
193
194
|
def test_scoped_find_with_distance_condition
|
194
|
-
locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
195
|
-
|
195
|
+
#locations = @starbucks.locations.geo_scope(:origin => @loc_a).where("distance < 3.97")
|
196
|
+
locations = @starbucks.locations.within(3.97, :origin => @loc_a)
|
197
|
+
assert_equal 4, locations.to_a.size
|
196
198
|
assert_equal 4, locations.count
|
197
199
|
end
|
198
200
|
|
199
201
|
def test_scoped_find_within
|
200
202
|
locations = @starbucks.locations.within(3.97, :origin => @loc_a)
|
201
|
-
assert_equal 4, locations.
|
203
|
+
assert_equal 4, locations.to_a.size
|
202
204
|
assert_equal 4, locations.count
|
203
205
|
end
|
204
206
|
|
205
207
|
def test_scoped_find_with_compound_condition
|
206
|
-
locations = @starbucks.locations.
|
207
|
-
assert_equal 2, locations.
|
208
|
+
locations = @starbucks.locations.within(5, :origin => @loc_a).where("city = 'Coppell'")
|
209
|
+
assert_equal 2, locations.to_a.size
|
208
210
|
assert_equal 2, locations.count
|
209
211
|
end
|
210
212
|
|
211
213
|
def test_scoped_find_beyond
|
212
214
|
locations = @starbucks.locations.beyond(3.95, :origin => @loc_a)
|
213
|
-
assert_equal 1, locations.
|
215
|
+
assert_equal 1, locations.to_a.size
|
214
216
|
assert_equal 1, locations.count
|
215
217
|
end
|
216
218
|
|
@@ -224,44 +226,44 @@ class ActsAsMappableTest < GeokitTestCase
|
|
224
226
|
|
225
227
|
def test_ip_geocoded_distance_column_in_select
|
226
228
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
227
|
-
locations = Location.
|
228
|
-
assert_equal 6, locations.
|
229
|
+
locations = Location.by_distance(:origin => LOCATION_A_IP)
|
230
|
+
assert_equal 6, locations.to_a.size
|
229
231
|
assert_equal 0, @loc_a.distance_to(locations.first)
|
230
232
|
assert_in_delta 3.97, @loc_a.distance_to(locations.last, :units => :miles, :formula => :sphere), 0.01
|
231
233
|
end
|
232
234
|
|
233
235
|
def test_ip_geocoded_find_with_distance_condition
|
234
236
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
235
|
-
locations = Location.
|
236
|
-
assert_equal 5, locations.
|
237
|
+
locations = Location.within(3.97, :origin => LOCATION_A_IP)
|
238
|
+
assert_equal 5, locations.to_a.size
|
237
239
|
assert_equal 5, locations.count
|
238
240
|
end
|
239
241
|
|
240
242
|
def test_ip_geocoded_find_within
|
241
243
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
242
244
|
locations = Location.within(3.97, :origin => LOCATION_A_IP)
|
243
|
-
assert_equal 5, locations.
|
245
|
+
assert_equal 5, locations.to_a.size
|
244
246
|
assert_equal 5, locations.count
|
245
247
|
end
|
246
248
|
|
247
249
|
def test_ip_geocoded_find_with_compound_condition
|
248
250
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
249
|
-
locations = Location.
|
250
|
-
assert_equal 2, locations.
|
251
|
+
locations = Location.within(5, :origin => LOCATION_A_IP).where("city = 'Coppell'")
|
252
|
+
assert_equal 2, locations.to_a.size
|
251
253
|
assert_equal 2, locations.count
|
252
254
|
end
|
253
255
|
|
254
256
|
def test_ip_geocoded_find_with_secure_compound_condition
|
255
257
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
256
|
-
locations = Location.
|
257
|
-
assert_equal 2, locations.
|
258
|
+
locations = Location.within(5, :origin => LOCATION_A_IP).where(["city = ?", 'Coppell'])
|
259
|
+
assert_equal 2, locations.to_a.size
|
258
260
|
assert_equal 2, locations.count
|
259
261
|
end
|
260
262
|
|
261
263
|
def test_ip_geocoded_find_beyond
|
262
264
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with(LOCATION_A_IP).returns(@location_a)
|
263
265
|
locations = Location.beyond(3.95, :origin => LOCATION_A_IP)
|
264
|
-
assert_equal 1, locations.
|
266
|
+
assert_equal 1, locations.to_a.size
|
265
267
|
assert_equal 1, locations.count
|
266
268
|
end
|
267
269
|
|
@@ -284,56 +286,60 @@ class ActsAsMappableTest < GeokitTestCase
|
|
284
286
|
|
285
287
|
def test_address_geocode
|
286
288
|
GeoKit::Geocoders::MultiGeocoder.expects(:geocode).with('Irving, TX').returns(@location_a)
|
287
|
-
locations = Location.geo_scope(:origin => 'Irving, TX').where(["distance < ? and city = ?", 5, 'Coppell'])
|
288
|
-
|
289
|
+
#locations = Location.geo_scope(:origin => 'Irving, TX').where(["distance < ? and city = ?", 5, 'Coppell'])
|
290
|
+
locations = Location.within(5, :origin => 'Irving, TX').where(["city = ?", 'Coppell'])
|
291
|
+
assert_equal 2, locations.to_a.size
|
289
292
|
assert_equal 2, locations.count
|
290
293
|
end
|
291
294
|
|
292
295
|
def test_find_with_custom_distance_condition
|
293
|
-
locations = CustomLocation.
|
294
|
-
assert_equal 5, locations.
|
296
|
+
locations = CustomLocation.within(3.97, :origin => @loc_a)
|
297
|
+
assert_equal 5, locations.to_a.size
|
295
298
|
assert_equal 5, locations.count
|
296
299
|
end
|
297
300
|
|
298
301
|
def test_find_with_custom_distance_condition_using_custom_origin
|
299
|
-
locations = CustomLocation.geo_scope(:origin => @custom_loc_a).where("dist < 3.97")
|
300
|
-
|
302
|
+
#locations = CustomLocation.geo_scope(:origin => @custom_loc_a).where("dist < 3.97")
|
303
|
+
locations = CustomLocation.within(3.97, :origin => @custom_loc_a)
|
304
|
+
assert_equal 5, locations.to_a.size
|
301
305
|
assert_equal 5, locations.count
|
302
306
|
end
|
303
307
|
|
304
308
|
def test_find_within_with_custom
|
305
309
|
locations = CustomLocation.within(3.97, :origin => @loc_a)
|
306
|
-
assert_equal 5, locations.
|
310
|
+
assert_equal 5, locations.to_a.size
|
307
311
|
assert_equal 5, locations.count
|
308
312
|
end
|
309
313
|
|
310
314
|
def test_find_within_with_coordinates_with_custom
|
311
315
|
locations = CustomLocation.within(3.97, :origin =>[@loc_a.lat, @loc_a.lng])
|
312
|
-
assert_equal 5, locations.
|
316
|
+
assert_equal 5, locations.to_a.size
|
313
317
|
assert_equal 5, locations.count
|
314
318
|
end
|
315
319
|
|
316
320
|
def test_find_with_compound_condition_with_custom
|
317
|
-
locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 5 and city = 'Coppell'")
|
318
|
-
|
321
|
+
#locations = CustomLocation.geo_scope(:origin => @loc_a).where("dist < 5 and city = 'Coppell'")
|
322
|
+
locations = CustomLocation.within(5, :origin => @loc_a).where("city = 'Coppell'")
|
323
|
+
assert_equal 1, locations.to_a.size
|
319
324
|
assert_equal 1, locations.count
|
320
325
|
end
|
321
326
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
+
# REMOVED AS SAME AS BELOW
|
328
|
+
#def test_find_with_secure_compound_condition_with_custom
|
329
|
+
# locations = CustomLocation.geo_scope(:origin => @loc_a).where(["dist < ? and city = ?", 5, 'Coppell'])
|
330
|
+
# assert_equal 1, locations.all.size
|
331
|
+
# assert_equal 1, locations.count
|
332
|
+
#end
|
327
333
|
|
328
334
|
def test_find_beyond_with_custom
|
329
335
|
locations = CustomLocation.beyond(3.95, :origin => @loc_a)
|
330
|
-
assert_equal 1, locations.
|
336
|
+
assert_equal 1, locations.to_a.size
|
331
337
|
assert_equal 1, locations.count
|
332
338
|
end
|
333
339
|
|
334
340
|
def test_find_beyond_with_coordinates_with_custom
|
335
341
|
locations = CustomLocation.beyond(3.95, :origin =>[@loc_a.lat, @loc_a.lng])
|
336
|
-
assert_equal 1, locations.
|
342
|
+
assert_equal 1, locations.to_a.size
|
337
343
|
assert_equal 1, locations.count
|
338
344
|
end
|
339
345
|
|
@@ -354,8 +360,9 @@ class ActsAsMappableTest < GeokitTestCase
|
|
354
360
|
end
|
355
361
|
|
356
362
|
def test_find_with_array_origin
|
357
|
-
locations = Location.geo_scope(:origin =>[@loc_a.lat,@loc_a.lng]).where("distance < 3.97")
|
358
|
-
|
363
|
+
#locations = Location.geo_scope(:origin =>[@loc_a.lat,@loc_a.lng]).where("distance < 3.97")
|
364
|
+
locations = Location.within(3.97, :origin =>[@loc_a.lat,@loc_a.lng])
|
365
|
+
assert_equal 5, locations.to_a.size
|
359
366
|
assert_equal 5, locations.count
|
360
367
|
end
|
361
368
|
|
@@ -364,35 +371,40 @@ class ActsAsMappableTest < GeokitTestCase
|
|
364
371
|
|
365
372
|
def test_find_within_bounds
|
366
373
|
locations = Location.in_bounds([@sw,@ne])
|
367
|
-
assert_equal 2, locations.
|
374
|
+
assert_equal 2, locations.to_a.size
|
368
375
|
assert_equal 2, locations.count
|
369
376
|
end
|
370
377
|
|
371
378
|
def test_find_within_bounds_ordered_by_distance
|
372
|
-
locations = Location.in_bounds([@sw,@ne], :origin=>@bounds_center).order('distance asc')
|
379
|
+
#locations = Location.in_bounds([@sw,@ne], :origin=>@bounds_center).order('distance asc')
|
380
|
+
locations = Location.in_bounds([@sw,@ne]).by_distance(:origin => @bounds_center)
|
373
381
|
assert_equal locations[0], locations(:d)
|
374
382
|
assert_equal locations[1], locations(:a)
|
375
383
|
end
|
376
384
|
|
377
385
|
def test_find_within_bounds_with_token
|
378
|
-
locations = Location.geo_scope(:bounds=>[@sw,@ne])
|
379
|
-
|
386
|
+
#locations = Location.geo_scope(:bounds=>[@sw,@ne])
|
387
|
+
locations = Location.in_bounds([@sw,@ne])
|
388
|
+
assert_equal 2, locations.to_a.size
|
380
389
|
assert_equal 2, locations.count
|
381
390
|
end
|
382
391
|
|
383
392
|
def test_find_within_bounds_with_string_conditions
|
384
|
-
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where("id !=#{locations(:a).id}")
|
385
|
-
|
393
|
+
#locations = Location.geo_scope(:bounds=>[@sw,@ne]).where("id !=#{locations(:a).id}")
|
394
|
+
locations = Location.in_bounds([@sw,@ne]).where("id !=#{locations(:a).id}")
|
395
|
+
assert_equal 1, locations.to_a.size
|
386
396
|
end
|
387
397
|
|
388
398
|
def test_find_within_bounds_with_array_conditions
|
389
|
-
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where(["id != ?", locations(:a).id])
|
390
|
-
|
399
|
+
#locations = Location.geo_scope(:bounds=>[@sw,@ne]).where(["id != ?", locations(:a).id])
|
400
|
+
locations = Location.in_bounds([@sw,@ne]).where(["id != ?", locations(:a).id])
|
401
|
+
assert_equal 1, locations.to_a.size
|
391
402
|
end
|
392
403
|
|
393
404
|
def test_find_within_bounds_with_hash_conditions
|
394
|
-
locations = Location.geo_scope(:bounds=>[@sw,@ne]).where({:id => locations(:a).id})
|
395
|
-
|
405
|
+
#locations = Location.geo_scope(:bounds=>[@sw,@ne]).where({:id => locations(:a).id})
|
406
|
+
locations = Location.in_bounds([@sw,@ne]).where({:id => locations(:a).id})
|
407
|
+
assert_equal 1, locations.to_a.size
|
396
408
|
end
|
397
409
|
|
398
410
|
def test_auto_geocode
|
@@ -414,15 +426,16 @@ class ActsAsMappableTest < GeokitTestCase
|
|
414
426
|
|
415
427
|
# Test :through
|
416
428
|
|
417
|
-
def test_find_with_through
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
end
|
429
|
+
#def test_find_with_through
|
430
|
+
# organizations = MockOrganization.geo_scope(:origin => @location_a).order('distance ASC')
|
431
|
+
# assert_equal 2, organizations.all.size
|
432
|
+
# organizations = MockOrganization.geo_scope(:origin => @location_a).where("distance < 3.97")
|
433
|
+
# assert_equal 1, organizations.count
|
434
|
+
#end
|
423
435
|
|
424
436
|
def test_find_with_through_with_hash
|
425
|
-
people = MockPerson.geo_scope(:origin => @location_a).order('distance ASC')
|
437
|
+
#people = MockPerson.geo_scope(:origin => @location_a).order('distance ASC')
|
438
|
+
people = MockPerson.order('distance ASC')
|
426
439
|
assert_equal 2, people.size
|
427
440
|
assert_equal 2, people.count
|
428
441
|
end
|