mongoid_geospatial 1.0.0 → 2.0.0

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.
Files changed (97) hide show
  1. data/Gemfile +5 -4
  2. data/Guardfile +24 -0
  3. data/README.md +9 -3
  4. data/lib/mongoid_geospatial/{contexts → contextual}/mongo.rb +11 -6
  5. data/lib/mongoid_geospatial/criterion/complex.rb +7 -0
  6. data/lib/mongoid_geospatial/criterion/inclusion.rb +12 -12
  7. data/lib/mongoid_geospatial/extensions/rgeo_spherical_point_impl.rb +13 -0
  8. data/lib/mongoid_geospatial/fields/line_string.rb +7 -6
  9. data/lib/mongoid_geospatial/fields/point.rb +24 -11
  10. data/lib/mongoid_geospatial/fields/polygon.rb +14 -10
  11. data/lib/mongoid_geospatial/geospatial/geo_near_results.rb +1 -1
  12. data/lib/mongoid_geospatial/geospatial.rb +1 -29
  13. data/lib/mongoid_geospatial/version.rb +1 -1
  14. data/lib/mongoid_geospatial.rb +9 -5
  15. data/mongoid_geospatial.gemspec +4 -5
  16. data/spec/models/address.rb +19 -14
  17. data/spec/models/bar.rb +3 -1
  18. data/spec/models/event.rb +2 -2
  19. data/spec/models/farm.rb +3 -4
  20. data/spec/models/person.rb +18 -60
  21. data/spec/models/phone.rb +3 -1
  22. data/spec/models/river.rb +2 -2
  23. data/spec/{functional/contexts → mongoid_geospatial/contextual}/mongo_spec.rb +16 -8
  24. data/spec/mongoid_geospatial/criterion/inclusion_spec.rb +375 -0
  25. data/spec/mongoid_geospatial/fields/point_spec.rb +34 -0
  26. data/spec/mongoid_geospatial/fields/polygon_spec.rb +6 -0
  27. data/spec/{functional → mongoid_geospatial}/geospatial/geo_near_results_spec.rb +0 -0
  28. data/spec/mongoid_geospatial/geospatial_spec.rb +2 -0
  29. data/spec/mongoid_geospatial/mongoid_geospatial_spec.rb +83 -0
  30. data/spec/spec_helper.rb +36 -20
  31. data/spec/support/authentication.rb +23 -23
  32. metadata +23 -161
  33. data/spec/functional/criterion/inclusion_spec.rb +0 -360
  34. data/spec/functional/mongoid_geospatial_spec.rb +0 -54
  35. data/spec/models/account.rb +0 -19
  36. data/spec/models/acolyte.rb +0 -9
  37. data/spec/models/address_component.rb +0 -5
  38. data/spec/models/agent.rb +0 -10
  39. data/spec/models/alert.rb +0 -5
  40. data/spec/models/animal.rb +0 -21
  41. data/spec/models/answer.rb +0 -4
  42. data/spec/models/birthday.rb +0 -13
  43. data/spec/models/book.rb +0 -5
  44. data/spec/models/business.rb +0 -7
  45. data/spec/models/callbacks.rb +0 -57
  46. data/spec/models/category.rb +0 -13
  47. data/spec/models/circus.rb +0 -7
  48. data/spec/models/comment.rb +0 -13
  49. data/spec/models/country_code.rb +0 -6
  50. data/spec/models/description.rb +0 -11
  51. data/spec/models/division.rb +0 -5
  52. data/spec/models/drug.rb +0 -5
  53. data/spec/models/employer.rb +0 -5
  54. data/spec/models/entry.rb +0 -6
  55. data/spec/models/favorite.rb +0 -6
  56. data/spec/models/fruits.rb +0 -11
  57. data/spec/models/game.rb +0 -18
  58. data/spec/models/ghost.rb +0 -7
  59. data/spec/models/house.rb +0 -4
  60. data/spec/models/inheritance.rb +0 -90
  61. data/spec/models/league.rb +0 -5
  62. data/spec/models/location.rb +0 -5
  63. data/spec/models/login.rb +0 -6
  64. data/spec/models/membership.rb +0 -4
  65. data/spec/models/mixed_drink.rb +0 -4
  66. data/spec/models/name.rb +0 -13
  67. data/spec/models/namespacing.rb +0 -11
  68. data/spec/models/observed.rb +0 -41
  69. data/spec/models/override.rb +0 -16
  70. data/spec/models/owner.rb +0 -6
  71. data/spec/models/page.rb +0 -5
  72. data/spec/models/page_question.rb +0 -4
  73. data/spec/models/paranoid_post.rb +0 -18
  74. data/spec/models/parents.rb +0 -32
  75. data/spec/models/patient.rb +0 -15
  76. data/spec/models/pet.rb +0 -7
  77. data/spec/models/pet_owner.rb +0 -6
  78. data/spec/models/player.rb +0 -23
  79. data/spec/models/post.rb +0 -26
  80. data/spec/models/preference.rb +0 -9
  81. data/spec/models/question.rb +0 -8
  82. data/spec/models/quiz.rb +0 -6
  83. data/spec/models/rating.rb +0 -8
  84. data/spec/models/role.rb +0 -5
  85. data/spec/models/service.rb +0 -6
  86. data/spec/models/shelf.rb +0 -5
  87. data/spec/models/slave_address_numbers.rb +0 -14
  88. data/spec/models/survey.rb +0 -5
  89. data/spec/models/tag.rb +0 -6
  90. data/spec/models/tracking_id_validation_history.rb +0 -25
  91. data/spec/models/translation.rb +0 -5
  92. data/spec/models/tree.rb +0 -9
  93. data/spec/models/user.rb +0 -9
  94. data/spec/models/user_account.rb +0 -10
  95. data/spec/models/vet_visit.rb +0 -5
  96. data/spec/models/video.rb +0 -9
  97. data/spec/models/wiki_page.rb +0 -6
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_geospatial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-13 00:00:00.000000000 Z
13
+ date: 2012-09-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rgeo
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.3.5
22
+ version: 0.3.15
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
- version: 0.3.5
30
+ version: 0.3.15
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: mongoid
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: 2.0.0
38
+ version: 3.0.0
39
39
  type: :runtime
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: 2.0.0
46
+ version: 3.0.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: '3.2'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: '3.0'
62
+ version: '3.2'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: yard
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  requirements:
84
84
  - - ~>
85
85
  - !ruby/object:Gem::Version
86
- version: '2.3'
86
+ version: '2.11'
87
87
  type: :development
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,23 +91,7 @@ dependencies:
91
91
  requirements:
92
92
  - - ~>
93
93
  - !ruby/object:Gem::Version
94
- version: '2.3'
95
- - !ruby/object:Gem::Dependency
96
- name: rcov
97
- requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
94
+ version: '2.11'
111
95
  - !ruby/object:Gem::Dependency
112
96
  name: mocha
113
97
  requirement: !ruby/object:Gem::Requirement
@@ -169,15 +153,17 @@ files:
169
153
  - .gitignore
170
154
  - .rspec
171
155
  - Gemfile
156
+ - Guardfile
172
157
  - README.md
173
158
  - Rakefile
174
159
  - lib/mongoid_geospatial.rb
175
- - lib/mongoid_geospatial/contexts/mongo.rb
160
+ - lib/mongoid_geospatial/contextual/mongo.rb
176
161
  - lib/mongoid_geospatial/criteria.rb
177
162
  - lib/mongoid_geospatial/criterion/complex.rb
178
163
  - lib/mongoid_geospatial/criterion/inclusion.rb
179
164
  - lib/mongoid_geospatial/criterion/near_spatial.rb
180
165
  - lib/mongoid_geospatial/criterion/within_spatial.rb
166
+ - lib/mongoid_geospatial/extensions/rgeo_spherical_point_impl.rb
181
167
  - lib/mongoid_geospatial/extensions/symbol.rb
182
168
  - lib/mongoid_geospatial/field_option.rb
183
169
  - lib/mongoid_geospatial/fields/line_string.rb
@@ -189,85 +175,23 @@ files:
189
175
  - lib/mongoid_geospatial/geospatial/geo_near_results.rb
190
176
  - lib/mongoid_geospatial/version.rb
191
177
  - mongoid_geospatial.gemspec
192
- - spec/functional/contexts/mongo_spec.rb
193
- - spec/functional/criterion/inclusion_spec.rb
194
- - spec/functional/geospatial/geo_near_results_spec.rb
195
- - spec/functional/mongoid_geospatial_spec.rb
196
- - spec/models/account.rb
197
- - spec/models/acolyte.rb
198
178
  - spec/models/address.rb
199
- - spec/models/address_component.rb
200
- - spec/models/agent.rb
201
- - spec/models/alert.rb
202
- - spec/models/animal.rb
203
- - spec/models/answer.rb
204
179
  - spec/models/bar.rb
205
- - spec/models/birthday.rb
206
- - spec/models/book.rb
207
- - spec/models/business.rb
208
- - spec/models/callbacks.rb
209
- - spec/models/category.rb
210
- - spec/models/circus.rb
211
- - spec/models/comment.rb
212
- - spec/models/country_code.rb
213
- - spec/models/description.rb
214
- - spec/models/division.rb
215
- - spec/models/drug.rb
216
- - spec/models/employer.rb
217
- - spec/models/entry.rb
218
180
  - spec/models/event.rb
219
181
  - spec/models/farm.rb
220
- - spec/models/favorite.rb
221
- - spec/models/fruits.rb
222
- - spec/models/game.rb
223
- - spec/models/ghost.rb
224
- - spec/models/house.rb
225
- - spec/models/inheritance.rb
226
- - spec/models/league.rb
227
- - spec/models/location.rb
228
- - spec/models/login.rb
229
- - spec/models/membership.rb
230
- - spec/models/mixed_drink.rb
231
- - spec/models/name.rb
232
- - spec/models/namespacing.rb
233
- - spec/models/observed.rb
234
- - spec/models/override.rb
235
- - spec/models/owner.rb
236
- - spec/models/page.rb
237
- - spec/models/page_question.rb
238
- - spec/models/paranoid_post.rb
239
- - spec/models/parents.rb
240
- - spec/models/patient.rb
241
182
  - spec/models/person.rb
242
- - spec/models/pet.rb
243
- - spec/models/pet_owner.rb
244
183
  - spec/models/phone.rb
245
- - spec/models/player.rb
246
- - spec/models/post.rb
247
- - spec/models/preference.rb
248
- - spec/models/question.rb
249
- - spec/models/quiz.rb
250
- - spec/models/rating.rb
251
184
  - spec/models/river.rb
252
- - spec/models/role.rb
253
- - spec/models/service.rb
254
- - spec/models/shelf.rb
255
- - spec/models/slave_address_numbers.rb
256
- - spec/models/survey.rb
257
- - spec/models/tag.rb
258
- - spec/models/tracking_id_validation_history.rb
259
- - spec/models/translation.rb
260
- - spec/models/tree.rb
261
- - spec/models/user.rb
262
- - spec/models/user_account.rb
263
- - spec/models/vet_visit.rb
264
- - spec/models/video.rb
265
- - spec/models/wiki_page.rb
185
+ - spec/mongoid_geospatial/contextual/mongo_spec.rb
266
186
  - spec/mongoid_geospatial/criterion/complex_spec.rb
267
187
  - spec/mongoid_geospatial/criterion/inclusion_spec.rb
268
188
  - spec/mongoid_geospatial/criterion/near_spatial_spec.rb
269
189
  - spec/mongoid_geospatial/criterion/within_spatial_spec.rb
190
+ - spec/mongoid_geospatial/fields/point_spec.rb
191
+ - spec/mongoid_geospatial/fields/polygon_spec.rb
192
+ - spec/mongoid_geospatial/geospatial/geo_near_results_spec.rb
270
193
  - spec/mongoid_geospatial/geospatial_spec.rb
194
+ - spec/mongoid_geospatial/mongoid_geospatial_spec.rb
271
195
  - spec/spec_helper.rb
272
196
  - spec/support/authentication.rb
273
197
  - spec/support/mongod.conf
@@ -298,85 +222,23 @@ specification_version: 3
298
222
  summary: A Mongoid Extension that simplifies and adds support for MongoDB Geo Spatial
299
223
  Calculations.
300
224
  test_files:
301
- - spec/functional/contexts/mongo_spec.rb
302
- - spec/functional/criterion/inclusion_spec.rb
303
- - spec/functional/geospatial/geo_near_results_spec.rb
304
- - spec/functional/mongoid_geospatial_spec.rb
305
- - spec/models/account.rb
306
- - spec/models/acolyte.rb
307
225
  - spec/models/address.rb
308
- - spec/models/address_component.rb
309
- - spec/models/agent.rb
310
- - spec/models/alert.rb
311
- - spec/models/animal.rb
312
- - spec/models/answer.rb
313
226
  - spec/models/bar.rb
314
- - spec/models/birthday.rb
315
- - spec/models/book.rb
316
- - spec/models/business.rb
317
- - spec/models/callbacks.rb
318
- - spec/models/category.rb
319
- - spec/models/circus.rb
320
- - spec/models/comment.rb
321
- - spec/models/country_code.rb
322
- - spec/models/description.rb
323
- - spec/models/division.rb
324
- - spec/models/drug.rb
325
- - spec/models/employer.rb
326
- - spec/models/entry.rb
327
227
  - spec/models/event.rb
328
228
  - spec/models/farm.rb
329
- - spec/models/favorite.rb
330
- - spec/models/fruits.rb
331
- - spec/models/game.rb
332
- - spec/models/ghost.rb
333
- - spec/models/house.rb
334
- - spec/models/inheritance.rb
335
- - spec/models/league.rb
336
- - spec/models/location.rb
337
- - spec/models/login.rb
338
- - spec/models/membership.rb
339
- - spec/models/mixed_drink.rb
340
- - spec/models/name.rb
341
- - spec/models/namespacing.rb
342
- - spec/models/observed.rb
343
- - spec/models/override.rb
344
- - spec/models/owner.rb
345
- - spec/models/page.rb
346
- - spec/models/page_question.rb
347
- - spec/models/paranoid_post.rb
348
- - spec/models/parents.rb
349
- - spec/models/patient.rb
350
229
  - spec/models/person.rb
351
- - spec/models/pet.rb
352
- - spec/models/pet_owner.rb
353
230
  - spec/models/phone.rb
354
- - spec/models/player.rb
355
- - spec/models/post.rb
356
- - spec/models/preference.rb
357
- - spec/models/question.rb
358
- - spec/models/quiz.rb
359
- - spec/models/rating.rb
360
231
  - spec/models/river.rb
361
- - spec/models/role.rb
362
- - spec/models/service.rb
363
- - spec/models/shelf.rb
364
- - spec/models/slave_address_numbers.rb
365
- - spec/models/survey.rb
366
- - spec/models/tag.rb
367
- - spec/models/tracking_id_validation_history.rb
368
- - spec/models/translation.rb
369
- - spec/models/tree.rb
370
- - spec/models/user.rb
371
- - spec/models/user_account.rb
372
- - spec/models/vet_visit.rb
373
- - spec/models/video.rb
374
- - spec/models/wiki_page.rb
232
+ - spec/mongoid_geospatial/contextual/mongo_spec.rb
375
233
  - spec/mongoid_geospatial/criterion/complex_spec.rb
376
234
  - spec/mongoid_geospatial/criterion/inclusion_spec.rb
377
235
  - spec/mongoid_geospatial/criterion/near_spatial_spec.rb
378
236
  - spec/mongoid_geospatial/criterion/within_spatial_spec.rb
237
+ - spec/mongoid_geospatial/fields/point_spec.rb
238
+ - spec/mongoid_geospatial/fields/polygon_spec.rb
239
+ - spec/mongoid_geospatial/geospatial/geo_near_results_spec.rb
379
240
  - spec/mongoid_geospatial/geospatial_spec.rb
241
+ - spec/mongoid_geospatial/mongoid_geospatial_spec.rb
380
242
  - spec/spec_helper.rb
381
243
  - spec/support/authentication.rb
382
244
  - spec/support/mongod.conf
@@ -1,360 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mongoid::Criterion::Inclusion do
4
-
5
- before do
6
- Person.delete_all
7
- end
8
-
9
- describe "#where" do
10
-
11
- let(:dob) do
12
- 33.years.ago.to_date
13
- end
14
-
15
- let(:lunch_time) do
16
- 30.minutes.ago
17
- end
18
-
19
- let!(:person) do
20
- Person.create(
21
- :title => "Sir",
22
- :dob => dob,
23
- :lunch_time => lunch_time,
24
- :age => 33,
25
- :aliases => [ "D", "Durran" ],
26
- :things => [ { :phone => 'HTC Incredible' } ]
27
- )
28
- end
29
-
30
- context "when providing 24 character strings" do
31
-
32
- context "when the field is not an id field" do
33
-
34
- let(:string) do
35
- BSON::ObjectId.new.to_s
36
- end
37
-
38
- let!(:person) do
39
- Person.create(:title => string)
40
- end
41
-
42
- let(:from_db) do
43
- Person.where(:title => string)
44
- end
45
-
46
- it "does not convert the field to a bson id" do
47
- from_db.should == [ person ]
48
- end
49
- end
50
- end
51
-
52
- context "when providing string object ids" do
53
-
54
- context "when providing a single id" do
55
-
56
- let(:from_db) do
57
- Person.where(:_id => person.id.to_s).first
58
- end
59
-
60
- it "returns the matching documents" do
61
- from_db.should == person
62
- end
63
- end
64
- end
65
-
66
- context "chaining multiple wheres" do
67
-
68
- context "when chaining on the same key" do
69
-
70
- let(:from_db) do
71
- Person.where(:title => "Maam").where(:title => "Sir")
72
- end
73
-
74
- it "overrides the previous key" do
75
- from_db.should == [ person ]
76
- end
77
- end
78
-
79
- context "with different criteria on the same key" do
80
-
81
- it "merges criteria" do
82
- Person.where(:age.gt => 30).where(:age.lt => 40).should == [person]
83
- end
84
-
85
- it "typecasts criteria" do
86
- before_dob = (dob - 1.month).to_s
87
- after_dob = (dob + 1.month).to_s
88
- Person.where(:dob.gt => before_dob).and(:dob.lt => after_dob).should == [person]
89
- end
90
-
91
- end
92
- end
93
-
94
- context "with untyped criteria" do
95
-
96
- it "typecasts integers" do
97
- Person.where(:age => "33").should == [ person ]
98
- end
99
-
100
- it "typecasts datetimes" do
101
- Person.where(:lunch_time => lunch_time.to_s).should == [ person ]
102
- end
103
-
104
- it "typecasts dates" do
105
- Person.where({:dob => dob.to_s}).should == [ person ]
106
- end
107
-
108
- it "typecasts times with zones" do
109
- time = lunch_time.in_time_zone("Alaska")
110
- Person.where(:lunch_time => time).should == [ person ]
111
- end
112
-
113
- it "typecasts array elements" do
114
- Person.where(:age.in => [17, "33"]).should == [ person ]
115
- end
116
-
117
- it "typecasts size criterion to integer" do
118
- Person.where(:aliases.size => "2").should == [ person ]
119
- end
120
-
121
- it "typecasts exists criterion to boolean" do
122
- Person.where(:score.exists => "f").should == [ person ]
123
- end
124
- end
125
-
126
- context "with multiple complex criteria" do
127
-
128
- before do
129
- Person.create(:title => "Mrs", :age => 29)
130
- Person.create(:title => "Ms", :age => 41)
131
- end
132
-
133
- it "returns those matching both criteria" do
134
- Person.where(:age.gt => 30, :age.lt => 40).should == [person]
135
- end
136
-
137
- it "returns nothing if in and nin clauses cancel each other out" do
138
- Person.any_in(:title => ["Sir"]).not_in(:title => ["Sir"]).should == []
139
- end
140
-
141
- it "returns nothing if in and nin clauses cancel each other out ordered the other way" do
142
- Person.not_in(:title => ["Sir"]).any_in(:title => ["Sir"]).should == []
143
- end
144
-
145
- it "returns the intersection of in and nin clauses" do
146
- Person.any_in(:title => ["Sir", "Mrs"]).not_in(:title => ["Mrs"]).should == [person]
147
- end
148
-
149
- it "returns the intersection of two in clauses" do
150
- Person.where(:title.in => ["Sir", "Mrs"]).where(:title.in => ["Sir", "Ms"]).should == [person]
151
- end
152
- end
153
-
154
- context "with complex criterion" do
155
-
156
- context "#all" do
157
-
158
- it "returns those matching an all clause" do
159
- Person.where(:aliases.all => ["D", "Durran"]).should == [person]
160
- end
161
- end
162
-
163
- context "#exists" do
164
-
165
- it "returns those matching an exists clause" do
166
- Person.where(:title.exists => true).should == [person]
167
- end
168
- end
169
-
170
- context "#gt" do
171
-
172
- it "returns those matching a gt clause" do
173
- Person.where(:age.gt => 30).should == [person]
174
- end
175
- end
176
-
177
- context "#gte" do
178
-
179
- it "returns those matching a gte clause" do
180
- Person.where(:age.gte => 33).should == [person]
181
- end
182
- end
183
-
184
- context "#in" do
185
-
186
- it "returns those matching an in clause" do
187
- Person.where(:title.in => ["Sir", "Madam"]).should == [person]
188
- end
189
-
190
- it "allows nil" do
191
- Person.where(:ssn.in => [nil]).should == [person]
192
- end
193
- end
194
-
195
- context "#lt" do
196
-
197
- it "returns those matching a lt clause" do
198
- Person.where(:age.lt => 34).should == [person]
199
- end
200
- end
201
-
202
- context "#lte" do
203
-
204
- it "returns those matching a lte clause" do
205
- Person.where(:age.lte => 33).should == [person]
206
- end
207
- end
208
-
209
- context "#ne" do
210
-
211
- it "returns those matching a ne clause" do
212
- Person.where(:age.ne => 50).should == [person]
213
- end
214
- end
215
-
216
- context "#nin" do
217
-
218
- it "returns those matching a nin clause" do
219
- Person.where(:title.nin => ["Esquire", "Congressman"]).should == [person]
220
- end
221
- end
222
-
223
- context "#size" do
224
-
225
- it "returns those matching a size clause" do
226
- Person.where(:aliases.size => 2).should == [person]
227
- end
228
- end
229
-
230
- context "#match" do
231
-
232
- it "returns those matching a partial element in a list" do
233
- Person.where(:things.matches => { :phone => "HTC Incredible" }).should == [person]
234
- end
235
- end
236
-
237
- end
238
-
239
- context "Geo Spatial Complex Where" do
240
-
241
- let!(:home) do
242
- [-73.98,40.77]
243
- end
244
-
245
- describe "#near" do
246
- before do
247
- Bar.delete_all
248
- Bar.create_indexes
249
- end
250
-
251
- let!(:berlin) do
252
- Bar.create(:name => :berlin, :location => [ 52.30, 13.25 ])
253
- end
254
-
255
- let!(:prague) do
256
- Bar.create(:name => :prague, :location => [ 50.5, 14.26 ])
257
- end
258
-
259
- let!(:paris) do
260
- Bar.create(:name => :paris, :location => [ 48.48, 2.20 ])
261
- end
262
-
263
- it "returns the documents sorted closest to furthest" do
264
- Bar.where(:location.near => [ 41.23, 2.9 ]).should == [ paris, prague, berlin ]
265
- end
266
-
267
- it "returns the documents sorted closest to furthest" do
268
- Bar.where(:location.near => {:point=>[ 41.23, 2.9 ],:max => 20}).should == [ paris, prague, berlin ]
269
- end
270
-
271
- it "returns the documents sorted closest to furthest" do
272
- Bar.where(:location.near_sphere => [ 41.23, 2.9 ]).should == [ paris, prague, berlin ]
273
- end
274
-
275
- it "should find closest using rgeo point" do
276
- Bar.where(:location.near => paris.location).should == [ paris, prague, berlin ]
277
- end
278
-
279
- end
280
-
281
- context "#within" do
282
-
283
- context ":box, :polygon" do
284
- before do
285
- Bar.delete_all
286
- Bar.create_indexes
287
- end
288
-
289
- let!(:berlin) do
290
- Bar.create(:name => 'berlin', :location => [ 52.30, 13.25 ])
291
- end
292
-
293
- let!(:prague) do
294
- Bar.create(:name => 'prague',:location => [ 50.5, 14.26 ])
295
- end
296
-
297
- let!(:paris) do
298
- Bar.create(:name => 'prague',:location => [ 48.48, 2.20 ])
299
- end
300
-
301
- it "returns the documents within a box" do
302
- Bar.where(:location.within(:box) => [[ 47, 1 ],[ 49, 3 ]]).should == [ paris ]
303
- end
304
-
305
- it "returns the documents within a polygon", :if => (Mongoid.master.connection.server_version >= '1.9') do
306
- Bar.where(:location.within(:polygon) => [[ 47, 1 ],[49,1.5],[ 49, 3 ],[46,5]]).should == [ paris ]
307
- end
308
-
309
- it "returns the documents within a center" do
310
- Bar.where(:location.within(:center) => [[ 47, 1 ],4]).should == [ paris ]
311
- end
312
-
313
- it "returns the documents within a center_sphere" do
314
- Bar.where(:location.within(:center_sphere) => [[ 48, 2 ],0.1]).should == [ paris ]
315
- end
316
-
317
- end
318
- context ":circle :center_sphere" do
319
- before do
320
- Bar.delete_all
321
- Bar.create_indexes
322
- end
323
- let!(:mile1) do
324
- Bar.create(:name => 'mile1', :location => [-73.997345, 40.759382])
325
- end
326
-
327
- let!(:mile3) do
328
- Bar.create(:name => 'mile2', :location => [-73.927088, 40.752151])
329
- end
330
-
331
- let!(:mile7) do
332
- Bar.create(:name => 'mile3', :location => [-74.0954913, 40.7161472])
333
- end
334
-
335
- let!(:mile11) do
336
- Bar.create(:name => 'mile4', :location => [-74.0604951, 40.9178011])
337
- end
338
-
339
- it "returns the documents within a center_sphere" do
340
- Bar.where(:location.within(:center_sphere) => {:point => home,:max => 2, :unit => :mi}).should == [ mile1 ]
341
- end
342
-
343
- it "returns the documents within a center_sphere" do
344
- Bar.where(:location.within(:center_sphere) => {:point => home,:max => 4, :unit => :mi}).should include(mile3)
345
- end
346
-
347
- it "returns the documents within a center_sphere" do
348
- Bar.where(:location.within(:center_sphere) => {:point => home,:max => 8, :unit => :mi}).should include(mile7)
349
- end
350
-
351
- it "returns the documents within a center_sphere" do
352
- Bar.where(:location.within(:center_sphere) => {:point => home,:max => 12, :unit => :mi}).should include(mile11)
353
- end
354
- end
355
- end
356
- end
357
-
358
- end
359
-
360
- end