cb_mongoid_spacial 0.2.16
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/.document +5 -0
- data/.gitignore +49 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +180 -0
- data/Rakefile +18 -0
- data/lib/mongoid_spacial.rb +11 -0
- data/lib/mongoid_spacial/contexts/mongo.rb +115 -0
- data/lib/mongoid_spacial/criteria.rb +5 -0
- data/lib/mongoid_spacial/criterion.rb +3 -0
- data/lib/mongoid_spacial/criterion/complex.rb +19 -0
- data/lib/mongoid_spacial/criterion/inclusion.rb +14 -0
- data/lib/mongoid_spacial/criterion/near_spacial.rb +50 -0
- data/lib/mongoid_spacial/criterion/within_spacial.rb +60 -0
- data/lib/mongoid_spacial/extentions/hash/criteria_helpers.rb +22 -0
- data/lib/mongoid_spacial/extentions/symbol/inflections.rb +46 -0
- data/lib/mongoid_spacial/field_option.rb +38 -0
- data/lib/mongoid_spacial/finders.rb +5 -0
- data/lib/mongoid_spacial/spacial.rb +56 -0
- data/lib/mongoid_spacial/spacial/core_ext.rb +27 -0
- data/lib/mongoid_spacial/spacial/document.rb +29 -0
- data/lib/mongoid_spacial/spacial/formulas.rb +52 -0
- data/lib/mongoid_spacial/spacial/geo_near_results.rb +140 -0
- data/lib/mongoid_spacial/spacial/version.rb +5 -0
- data/mongoid_spacial.gemspec +27 -0
- data/spec/config/mongod.conf +3 -0
- data/spec/config/mongoid.yml +18 -0
- data/spec/functional/mongoid/contexts/mongo_spec.rb +125 -0
- data/spec/functional/mongoid/criterion/inclusion_spec.rb +356 -0
- data/spec/functional/mongoid/spacial/geo_near_results_spec.rb +73 -0
- data/spec/functional/mongoid/spacial_spec.rb +18 -0
- data/spec/models/account.rb +19 -0
- data/spec/models/acolyte.rb +9 -0
- data/spec/models/address.rb +62 -0
- data/spec/models/address_component.rb +5 -0
- data/spec/models/agent.rb +10 -0
- data/spec/models/alert.rb +5 -0
- data/spec/models/animal.rb +21 -0
- data/spec/models/answer.rb +4 -0
- data/spec/models/bar.rb +9 -0
- data/spec/models/birthday.rb +13 -0
- data/spec/models/book.rb +5 -0
- data/spec/models/business.rb +7 -0
- data/spec/models/callbacks.rb +57 -0
- data/spec/models/category.rb +13 -0
- data/spec/models/circus.rb +7 -0
- data/spec/models/comment.rb +13 -0
- data/spec/models/country_code.rb +6 -0
- data/spec/models/description.rb +11 -0
- data/spec/models/division.rb +5 -0
- data/spec/models/drug.rb +5 -0
- data/spec/models/employer.rb +5 -0
- data/spec/models/entry.rb +6 -0
- data/spec/models/event.rb +20 -0
- data/spec/models/favorite.rb +6 -0
- data/spec/models/fruits.rb +11 -0
- data/spec/models/game.rb +18 -0
- data/spec/models/ghost.rb +7 -0
- data/spec/models/house.rb +4 -0
- data/spec/models/inheritance.rb +90 -0
- data/spec/models/league.rb +5 -0
- data/spec/models/location.rb +5 -0
- data/spec/models/login.rb +6 -0
- data/spec/models/membership.rb +4 -0
- data/spec/models/mixed_drink.rb +4 -0
- data/spec/models/name.rb +13 -0
- data/spec/models/namespacing.rb +11 -0
- data/spec/models/observed.rb +41 -0
- data/spec/models/override.rb +16 -0
- data/spec/models/owner.rb +6 -0
- data/spec/models/page.rb +5 -0
- data/spec/models/page_question.rb +4 -0
- data/spec/models/paranoid_post.rb +18 -0
- data/spec/models/parents.rb +32 -0
- data/spec/models/patient.rb +15 -0
- data/spec/models/person.rb +146 -0
- data/spec/models/pet.rb +7 -0
- data/spec/models/pet_owner.rb +6 -0
- data/spec/models/phone.rb +7 -0
- data/spec/models/player.rb +23 -0
- data/spec/models/post.rb +26 -0
- data/spec/models/preference.rb +9 -0
- data/spec/models/question.rb +8 -0
- data/spec/models/quiz.rb +6 -0
- data/spec/models/rating.rb +8 -0
- data/spec/models/river.rb +20 -0
- data/spec/models/role.rb +5 -0
- data/spec/models/service.rb +6 -0
- data/spec/models/shelf.rb +5 -0
- data/spec/models/slave_address_numbers.rb +14 -0
- data/spec/models/survey.rb +5 -0
- data/spec/models/tag.rb +6 -0
- data/spec/models/tracking_id_validation_history.rb +25 -0
- data/spec/models/translation.rb +5 -0
- data/spec/models/tree.rb +9 -0
- data/spec/models/user.rb +9 -0
- data/spec/models/user_account.rb +10 -0
- data/spec/models/vet_visit.rb +5 -0
- data/spec/models/video.rb +9 -0
- data/spec/models/wiki_page.rb +6 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/authentication.rb +29 -0
- data/spec/unit/mongoid/criterion/complex_spec.rb +15 -0
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +0 -0
- data/spec/unit/mongoid/criterion/near_spacial_spec.rb +39 -0
- data/spec/unit/mongoid/criterion/within_spacial_spec.rb +52 -0
- data/spec/unit/mongoid/spacial/formulas_spec.rb +37 -0
- data/spec/unit/mongoid/spacial_spec.rb +6 -0
- metadata +374 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/mongoid_spacial/spacial/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Ryan Ong"]
|
|
6
|
+
gem.email = ["ryanong@gmail.com"]
|
|
7
|
+
gem.description = %q{mongoid_spacial simplifies spacial calculations. Adds integration into mongoid so pagination and other function continue to work. It adds symbol extentions to simplify query creation.}
|
|
8
|
+
gem.summary = %q{A Mongoid Extention that simplifies and adds support for MongoDB Geo Spacial Calculations.}
|
|
9
|
+
gem.homepage = "https://github.com/ryanong/mongoid_spacial"
|
|
10
|
+
|
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
14
|
+
gem.name = "cb_mongoid_spacial"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = Mongoid::Spacial::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_dependency("mongoid", ['>= 2.1.0'])
|
|
19
|
+
gem.add_dependency('activesupport', ["~> 3.0"])
|
|
20
|
+
gem.add_development_dependency('yard', ["~>0.6.0"])
|
|
21
|
+
gem.add_development_dependency('rspec', ['~>2.3'])
|
|
22
|
+
gem.add_development_dependency('simplecov', ['>= 0'])
|
|
23
|
+
gem.add_development_dependency('mocha', ['>= 0'])
|
|
24
|
+
gem.add_development_dependency('will_paginate', ['>= 0'])
|
|
25
|
+
gem.add_development_dependency('kaminari', ['>= 0'])
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
test:
|
|
2
|
+
database: mongoid_config_test
|
|
3
|
+
host: localhost
|
|
4
|
+
slaves:
|
|
5
|
+
# - host: localhost
|
|
6
|
+
# port: 27018
|
|
7
|
+
# - host: localhost
|
|
8
|
+
# port: 27019
|
|
9
|
+
allow_dynamic_fields: false
|
|
10
|
+
include_root_in_json: true
|
|
11
|
+
parameterize_keys: false
|
|
12
|
+
persist_in_safe_mode: false
|
|
13
|
+
raise_not_found_error: false
|
|
14
|
+
reconnect_time: 5
|
|
15
|
+
autocreate_indexes: false
|
|
16
|
+
persist_types: false
|
|
17
|
+
option_no_exist: false
|
|
18
|
+
skip_version_check: false
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Contexts::Mongo do
|
|
4
|
+
describe "#geo_near" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
Bar.delete_all
|
|
8
|
+
Bar.create_indexes
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
let!(:jfk) do
|
|
12
|
+
Bar.create(:name => 'jfk', :location => [-73.77694444, 40.63861111 ])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let!(:lax) do
|
|
16
|
+
Bar.create(:name => 'lax', :location => [-118.40, 33.94])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should work with specifying specific center and different location attribute on collction" do
|
|
20
|
+
Bar.geo_near(lax.location, :spherical => true).should == [lax, jfk]
|
|
21
|
+
Bar.geo_near(jfk.location, :spherical => true).should == [jfk, lax]
|
|
22
|
+
end
|
|
23
|
+
context 'option' do
|
|
24
|
+
context ':num' do
|
|
25
|
+
it "should limit number of results to 1" do
|
|
26
|
+
Bar.geo_near(jfk.location, :num => 1).size.should == 1
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context ':maxDistance' do
|
|
31
|
+
it "should get 1 item" do
|
|
32
|
+
Bar.geo_near(lax.location, :spherical => true, :max_distance => 2465/Mongoid::Spacial.earth_radius[:mi]).size.should == 1
|
|
33
|
+
end
|
|
34
|
+
it "should get 2 items" do
|
|
35
|
+
Bar.geo_near(lax.location, :spherical => true, :max_distance => 2480/Mongoid::Spacial.earth_radius[:mi]).size.should == 2
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context ':distance_multiplier' do
|
|
41
|
+
it "should multiply returned distance with multiplier" do
|
|
42
|
+
Bar.geo_near(lax.location, :spherical => true, :distance_multiplier=> Mongoid::Spacial.earth_radius[:mi]).second.geo[:distance].to_i.should be_within(1).of(2469)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context ':unit' do
|
|
47
|
+
it "should multiply returned distance with multiplier" do
|
|
48
|
+
Bar.geo_near(lax.location, :spherical => true, :unit => :mi).second.geo[:distance].to_i.should be_within(1).of(2469)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should convert max_distance to radians with unit" do
|
|
52
|
+
Bar.geo_near(lax.location, :spherical => true, :max_distance => 2465, :unit => :mi).size.should == 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
context ':query' do
|
|
58
|
+
it "should filter using extra query option" do
|
|
59
|
+
# two record in the collection, only one's name is Munich
|
|
60
|
+
Bar.geo_near(jfk.location, :query => {:name => jfk.name}).should == [jfk]
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context 'criteria chaining' do
|
|
67
|
+
it "should filter by where" do
|
|
68
|
+
Bar.where(:name => jfk.name).geo_near(jfk.location).should == [jfk]
|
|
69
|
+
Bar.any_of({:name => jfk.name},{:name => lax.name}).geo_near(jfk.location).should == [jfk,lax]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'should skip 1' do
|
|
73
|
+
Bar.skip(1).geo_near(jfk.location).size.should == 1
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'should limit 1' do
|
|
77
|
+
Bar.limit(1).geo_near(jfk.location).size.should == 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context ':page' do
|
|
85
|
+
before(:all) do
|
|
86
|
+
Bar.delete_all
|
|
87
|
+
Bar.create_indexes
|
|
88
|
+
|
|
89
|
+
50.times do
|
|
90
|
+
Bar.create({:location => [rand(360)-180,rand(360)-180]})
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
context ":paginator :array" do
|
|
94
|
+
[nil,1,2].each do |page|
|
|
95
|
+
it "page=#{page} should have 25" do
|
|
96
|
+
Bar.geo_near([1,1], :page => page).size.should == 25
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "page=3 should have 0" do
|
|
101
|
+
Bar.geo_near([1,1], :page => 20).size.should == 0
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "per_page=5" do
|
|
105
|
+
Bar.geo_near([1,1], :page => 1, :per_page => 5).size.should == 5
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context ":paginator :kaminari" do
|
|
110
|
+
let(:near) {Bar.geo_near([1,1], :page => 1)}
|
|
111
|
+
it "should have current_page" do
|
|
112
|
+
near.current_page.should == 1
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should have num_pages" do
|
|
116
|
+
near.num_pages.should == 2
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should have limit_value" do
|
|
120
|
+
near.limit_value.should == 25
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
@@ -0,0 +1,356 @@
|
|
|
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 Spacial 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(:location => [ 52.30, 13.25 ])
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
let!(:prague) do
|
|
256
|
+
Bar.create(:location => [ 50.5, 14.26 ])
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
let!(:paris) do
|
|
260
|
+
Bar.create(: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
|
+
end
|
|
276
|
+
|
|
277
|
+
context "#within" do
|
|
278
|
+
|
|
279
|
+
context ":box, :polygon" do
|
|
280
|
+
before do
|
|
281
|
+
Bar.delete_all
|
|
282
|
+
Bar.create_indexes
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
let!(:berlin) do
|
|
286
|
+
Bar.create(:name => 'berlin', :location => [ 52.30, 13.25 ])
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
let!(:prague) do
|
|
290
|
+
Bar.create(:name => 'prague',:location => [ 50.5, 14.26 ])
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
let!(:paris) do
|
|
294
|
+
Bar.create(:name => 'prague',:location => [ 48.48, 2.20 ])
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "returns the documents within a box" do
|
|
298
|
+
Bar.where(:location.within(:box) => [[ 47, 1 ],[ 49, 3 ]]).should == [ paris ]
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
it "returns the documents within a polygon", :if => (Mongoid.master.connection.server_version >= '1.9') do
|
|
302
|
+
Bar.where(:location.within(:polygon) => [[ 47, 1 ],[49,1.5],[ 49, 3 ],[46,5]]).should == [ paris ]
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
it "returns the documents within a center" do
|
|
306
|
+
Bar.where(:location.within(:center) => [[ 47, 1 ],4]).should == [ paris ]
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
it "returns the documents within a center_sphere" do
|
|
310
|
+
Bar.where(:location.within(:center_sphere) => [[ 48, 2 ],0.1]).should == [ paris ]
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
end
|
|
314
|
+
context ":circle :center_sphere" do
|
|
315
|
+
before do
|
|
316
|
+
Bar.delete_all
|
|
317
|
+
Bar.create_indexes
|
|
318
|
+
end
|
|
319
|
+
let!(:mile1) do
|
|
320
|
+
Bar.create(:name => 'mile1', :location => [-73.997345, 40.759382])
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
let!(:mile3) do
|
|
324
|
+
Bar.create(:name => 'mile2', :location => [-73.927088, 40.752151])
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
let!(:mile7) do
|
|
328
|
+
Bar.create(:name => 'mile3', :location => [-74.0954913, 40.7161472])
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
let!(:mile11) do
|
|
332
|
+
Bar.create(:name => 'mile4', :location => [-74.0604951, 40.9178011])
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
it "returns the documents within a center_sphere" do
|
|
336
|
+
Bar.where(:location.within(:center_sphere) => {:point => home,:max => 2, :unit => :mi}).should == [ mile1 ]
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it "returns the documents within a center_sphere" do
|
|
340
|
+
Bar.where(:location.within(:center_sphere) => {:point => home,:max => 4, :unit => :mi}).should include(mile3)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it "returns the documents within a center_sphere" do
|
|
344
|
+
Bar.where(:location.within(:center_sphere) => {:point => home,:max => 8, :unit => :mi}).should include(mile7)
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
it "returns the documents within a center_sphere" do
|
|
348
|
+
Bar.where(:location.within(:center_sphere) => {:point => home,:max => 12, :unit => :mi}).should include(mile11)
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
end
|