mongoid 5.0.2 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients.rb +1 -0
- data/lib/mongoid/clients/options.rb +119 -7
- data/lib/mongoid/config.rb +7 -0
- data/lib/mongoid/config/options.rb +15 -0
- data/lib/mongoid/contextual/geo_near.rb +12 -0
- data/lib/mongoid/contextual/mongo.rb +6 -0
- data/lib/mongoid/criteria.rb +2 -56
- data/lib/mongoid/criteria/findable.rb +4 -1
- data/lib/mongoid/criteria/includable.rb +142 -0
- data/lib/mongoid/criteria/modifiable.rb +13 -1
- data/lib/mongoid/document.rb +21 -0
- data/lib/mongoid/fields/foreign_key.rb +5 -1
- data/lib/mongoid/fields/localized.rb +16 -1
- data/lib/mongoid/fields/validators/macro.rb +1 -0
- data/lib/mongoid/findable.rb +1 -0
- data/lib/mongoid/loggable.rb +1 -1
- data/lib/mongoid/matchable.rb +6 -1
- data/lib/mongoid/persistable.rb +2 -2
- data/lib/mongoid/relations/eager.rb +12 -5
- data/lib/mongoid/relations/eager/base.rb +3 -1
- data/lib/mongoid/relations/referenced/many.rb +39 -6
- data/lib/mongoid/relations/targets/enumerable.rb +3 -3
- data/lib/mongoid/scopable.rb +5 -2
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/address.rb +2 -0
- data/spec/app/models/agent.rb +2 -0
- data/spec/app/models/alert.rb +2 -0
- data/spec/app/models/post.rb +1 -0
- data/spec/config/mongoid.yml +1 -0
- data/spec/mongoid/changeable_spec.rb +1 -1
- data/spec/mongoid/clients/options_spec.rb +57 -0
- data/spec/mongoid/config_spec.rb +38 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +19 -0
- data/spec/mongoid/criteria/findable_spec.rb +11 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +126 -0
- data/spec/mongoid/criteria_spec.rb +81 -5
- data/spec/mongoid/document_spec.rb +56 -0
- data/spec/mongoid/fields/foreign_key_spec.rb +23 -0
- data/spec/mongoid/fields/localized_spec.rb +32 -14
- data/spec/mongoid/matchable_spec.rb +127 -1
- data/spec/mongoid/persistable_spec.rb +24 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +16 -0
- data/spec/mongoid/relations/referenced/many_spec.rb +60 -0
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +40 -0
- data/spec/mongoid/scopable_spec.rb +67 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/authorization.rb +2 -1
- metadata +6 -5
- metadata.gz.sig +0 -0
@@ -168,6 +168,30 @@ describe Mongoid::Persistable do
|
|
168
168
|
|
169
169
|
it_behaves_like "an atomically updatable root document"
|
170
170
|
end
|
171
|
+
|
172
|
+
context "when nesting atomically calls" do
|
173
|
+
|
174
|
+
before do
|
175
|
+
class Band
|
176
|
+
def my_updates
|
177
|
+
atomically do |d|
|
178
|
+
d.set(name: "Placebo")
|
179
|
+
d.unset(:origin)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
let!(:update) do
|
186
|
+
document.atomically do |doc|
|
187
|
+
doc.inc(member_count: 10)
|
188
|
+
doc.bit(likes: { and: 13 })
|
189
|
+
doc.my_updates
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it_behaves_like "an atomically updatable root document"
|
194
|
+
end
|
171
195
|
end
|
172
196
|
|
173
197
|
context "when providing no block "do
|
@@ -3592,6 +3592,22 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3592
3592
|
it "properly orders the related objects" do
|
3593
3593
|
expect(criteria.to_a).to eq([message_two, message_one, message_three])
|
3594
3594
|
end
|
3595
|
+
|
3596
|
+
context "when the field to order on is an array of documents" do
|
3597
|
+
|
3598
|
+
before do
|
3599
|
+
person.aliases = [ { name: "A", priority: 3 }, { name: "B", priority: 4 }]
|
3600
|
+
person.save
|
3601
|
+
end
|
3602
|
+
|
3603
|
+
let!(:person2) do
|
3604
|
+
Person.create( aliases: [ { name: "C", priority: 1 }, { name: "D", priority: 2 }])
|
3605
|
+
end
|
3606
|
+
|
3607
|
+
it "allows ordering on a key of an embedded document" do
|
3608
|
+
expect(Person.all.order_by("aliases.0.priority" => 1).first).to eq(person2)
|
3609
|
+
end
|
3610
|
+
end
|
3595
3611
|
end
|
3596
3612
|
|
3597
3613
|
context "when using dot notation in a criteria" do
|
@@ -200,6 +200,24 @@ describe Mongoid::Relations::Referenced::Many do
|
|
200
200
|
expect(person.changed).to eq([])
|
201
201
|
end
|
202
202
|
|
203
|
+
context "when the related item has embedded relations" do
|
204
|
+
|
205
|
+
let!(:user) do
|
206
|
+
User.create
|
207
|
+
end
|
208
|
+
|
209
|
+
before do
|
210
|
+
p = Post.create(roles: [ Role.create ])
|
211
|
+
user.posts = [ p ]
|
212
|
+
user.save
|
213
|
+
end
|
214
|
+
|
215
|
+
it "add the document to the target" do
|
216
|
+
expect(user.posts.size).to eq(1)
|
217
|
+
expect(user.posts.first.roles.size).to eq(1)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
203
221
|
context "when saving another post" do
|
204
222
|
|
205
223
|
before do
|
@@ -3514,6 +3532,24 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3514
3532
|
expect(artist.albums).to eq([ album ])
|
3515
3533
|
end
|
3516
3534
|
end
|
3535
|
+
|
3536
|
+
context 'when the relation already exists' do
|
3537
|
+
|
3538
|
+
before do
|
3539
|
+
artist.albums << album
|
3540
|
+
album.save
|
3541
|
+
artist.save
|
3542
|
+
expect(artist).not_to receive(:after_add_album)
|
3543
|
+
end
|
3544
|
+
|
3545
|
+
let(:reloaded_album) do
|
3546
|
+
Album.where(artist_id: artist.id).first
|
3547
|
+
end
|
3548
|
+
|
3549
|
+
it 'does not execute the callback when the relation is accessed' do
|
3550
|
+
expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
|
3551
|
+
end
|
3552
|
+
end
|
3517
3553
|
end
|
3518
3554
|
|
3519
3555
|
context "when #delete or #clear with before_remove callback" do
|
@@ -3732,4 +3768,28 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3732
3768
|
expect(reloaded.name).to eq(new_child_name)
|
3733
3769
|
end
|
3734
3770
|
end
|
3771
|
+
|
3772
|
+
context 'when a document has referenced and embedded relations' do
|
3773
|
+
|
3774
|
+
let(:agent) do
|
3775
|
+
Agent.new
|
3776
|
+
end
|
3777
|
+
|
3778
|
+
let(:basic) do
|
3779
|
+
Basic.new
|
3780
|
+
end
|
3781
|
+
|
3782
|
+
let(:address) do
|
3783
|
+
Address.new
|
3784
|
+
end
|
3785
|
+
|
3786
|
+
before do
|
3787
|
+
agent.basics << basic
|
3788
|
+
agent.address = address
|
3789
|
+
end
|
3790
|
+
|
3791
|
+
it 'saves the document correctly' do
|
3792
|
+
expect(agent.save).to be(true)
|
3793
|
+
end
|
3794
|
+
end
|
3735
3795
|
end
|
@@ -3535,4 +3535,44 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
3535
3535
|
end
|
3536
3536
|
end
|
3537
3537
|
end
|
3538
|
+
|
3539
|
+
context "HABTM" do
|
3540
|
+
before do
|
3541
|
+
class Project
|
3542
|
+
include Mongoid::Document
|
3543
|
+
|
3544
|
+
field :n, type: String, as: :name
|
3545
|
+
|
3546
|
+
has_and_belongs_to_many :distributors,
|
3547
|
+
foreign_key: :d_ids,
|
3548
|
+
inverse_of: 'p',
|
3549
|
+
inverse_class_name: 'Distributor'
|
3550
|
+
end
|
3551
|
+
|
3552
|
+
class Distributor
|
3553
|
+
include Mongoid::Document
|
3554
|
+
|
3555
|
+
field :n, type: String, as: :name
|
3556
|
+
|
3557
|
+
has_and_belongs_to_many :projects,
|
3558
|
+
foreign_key: :p_ids,
|
3559
|
+
inverse_of: 'd',
|
3560
|
+
inverse_class_name: 'Project'
|
3561
|
+
end
|
3562
|
+
end
|
3563
|
+
|
3564
|
+
it "should assign relation from both sides" do
|
3565
|
+
p1 = Project.create name: 'Foo'
|
3566
|
+
p2 = Project.create name: 'Bar'
|
3567
|
+
d1 = Distributor.create name: 'Rock'
|
3568
|
+
d2 = Distributor.create name: 'Soul'
|
3569
|
+
|
3570
|
+
p1.distributors << d1
|
3571
|
+
expect(p1.d_ids).to match_array([d1.id])
|
3572
|
+
expect(d1.p_ids).to match_array([p1.id])
|
3573
|
+
d2.projects << p2
|
3574
|
+
expect(d2.p_ids).to match_array([p2.id])
|
3575
|
+
expect(p2.d_ids).to match_array([d2.id])
|
3576
|
+
end
|
3577
|
+
end
|
3538
3578
|
end
|
@@ -27,6 +27,29 @@ describe Mongoid::Scopable do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context "when provided a block" do
|
31
|
+
|
32
|
+
let(:criteria) do
|
33
|
+
Band.where(name: "Depeche Mode")
|
34
|
+
end
|
35
|
+
|
36
|
+
before do
|
37
|
+
Band.default_scope { criteria }
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
Band.default_scoping = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it "adds the default scope to the class" do
|
45
|
+
expect(Band.default_scoping.call).to eq(criteria)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "flags as being default scoped" do
|
49
|
+
expect(Band).to be_default_scoping
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
30
53
|
context "when provided a non proc" do
|
31
54
|
|
32
55
|
it "raises an error" do
|
@@ -135,6 +158,31 @@ describe Mongoid::Scopable do
|
|
135
158
|
it "returns an empty criteria" do
|
136
159
|
expect(Band.queryable.selector).to be_empty
|
137
160
|
end
|
161
|
+
|
162
|
+
context "when the class is not embedded" do
|
163
|
+
|
164
|
+
it "returns a criteria with embedded set to nil" do
|
165
|
+
expect(Band.queryable.embedded).to be(nil)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context "when the class is embedded" do
|
170
|
+
|
171
|
+
it "returns a criteria with embedded set to true" do
|
172
|
+
expect(Address.queryable.embedded).to be(true)
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when scopes are chained" do
|
176
|
+
|
177
|
+
let(:person) do
|
178
|
+
Person.create
|
179
|
+
end
|
180
|
+
|
181
|
+
it "constructs a criteria for an embedded relation" do
|
182
|
+
expect(person.addresses.without_postcode_ordered.embedded).to be(true)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
138
186
|
end
|
139
187
|
|
140
188
|
context "when a criteria exists on the stack" do
|
@@ -179,6 +227,25 @@ describe Mongoid::Scopable do
|
|
179
227
|
|
180
228
|
context "when provided a criteria" do
|
181
229
|
|
230
|
+
context "when the lambda includes a geo_near query" do
|
231
|
+
|
232
|
+
before do
|
233
|
+
Bar.scope(:near_by, lambda{ |location| geo_near(location) })
|
234
|
+
end
|
235
|
+
|
236
|
+
after do
|
237
|
+
class << Bar
|
238
|
+
undef_method :near_by
|
239
|
+
end
|
240
|
+
Bar._declared_scopes.clear
|
241
|
+
end
|
242
|
+
|
243
|
+
it "allows the scope to be defined" do
|
244
|
+
expect(Bar.near_by([ 51.545099, -0.0106 ])).to be_a(Mongoid::Contextual::GeoNear)
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
182
249
|
context "when a block is provided" do
|
183
250
|
|
184
251
|
before do
|
data/spec/spec_helper.rb
CHANGED
@@ -71,6 +71,10 @@ def non_legacy_server?
|
|
71
71
|
Mongoid::Clients.default.cluster.servers.first.features.write_command_enabled?
|
72
72
|
end
|
73
73
|
|
74
|
+
def testing_locally?
|
75
|
+
!(ENV['CI'] == 'travis')
|
76
|
+
end
|
77
|
+
|
74
78
|
# Set the database that the spec suite connects to.
|
75
79
|
Mongoid.configure do |config|
|
76
80
|
config.load_configuration(CONFIG)
|
@@ -7,6 +7,7 @@ MONGOID_ROOT_USER = Mongo::Auth::User.new(
|
|
7
7
|
Mongo::Auth::Roles::USER_ADMIN_ANY_DATABASE,
|
8
8
|
Mongo::Auth::Roles::DATABASE_ADMIN_ANY_DATABASE,
|
9
9
|
Mongo::Auth::Roles::READ_WRITE_ANY_DATABASE,
|
10
|
-
Mongo::Auth::Roles::HOST_MANAGER
|
10
|
+
Mongo::Auth::Roles::HOST_MANAGER,
|
11
|
+
Mongo::Auth::Roles::CLUSTER_MONITOR
|
11
12
|
]
|
12
13
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
ZIvvwAhgCjVW5QCi2I1noxXLmtZ3XDawWu8kaGtu8giHXcwL3941m8hvFZ/Wr9Yi
|
31
31
|
JvcXJt2a4/JvwnIs2hmKuyfhZmB9HEE5wQQaCMnnC14=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
33
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -80,14 +80,14 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '2.
|
83
|
+
version: '2.2'
|
84
84
|
type: :runtime
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: '2.
|
90
|
+
version: '2.2'
|
91
91
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
|
92
92
|
in Ruby.
|
93
93
|
email:
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/mongoid/copyable.rb
|
144
144
|
- lib/mongoid/criteria.rb
|
145
145
|
- lib/mongoid/criteria/findable.rb
|
146
|
+
- lib/mongoid/criteria/includable.rb
|
146
147
|
- lib/mongoid/criteria/inspectable.rb
|
147
148
|
- lib/mongoid/criteria/marshalable.rb
|
148
149
|
- lib/mongoid/criteria/modifiable.rb
|
@@ -810,7 +811,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
810
811
|
version: 1.3.6
|
811
812
|
requirements: []
|
812
813
|
rubyforge_project: mongoid
|
813
|
-
rubygems_version: 2.
|
814
|
+
rubygems_version: 2.5.1
|
814
815
|
signing_key:
|
815
816
|
specification_version: 4
|
816
817
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|