mongoid 7.0.7 → 7.0.8
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/lib/mongoid.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/atomic.rb +13 -3
- data/lib/mongoid/criteria.rb +7 -1
- data/lib/mongoid/criteria/modifiable.rb +2 -1
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +4 -2
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/fields.rb +2 -1
- data/lib/mongoid/matchable/regexp.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +4 -1
- data/lib/mongoid/persistence_context.rb +6 -6
- data/lib/mongoid/query_cache.rb +2 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/integration/app_spec.rb +192 -0
- data/spec/integration/associations/embedded_spec.rb +62 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/lite_spec_helper.rb +11 -4
- data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +2 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
- data/spec/mongoid/clients/options_spec.rb +4 -4
- data/spec/mongoid/clients/sessions_spec.rb +8 -4
- data/spec/mongoid/clients/transactions_spec.rb +20 -8
- data/spec/mongoid/clients_spec.rb +2 -2
- data/spec/mongoid/contextual/atomic_spec.rb +20 -10
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
- data/spec/mongoid/contextual/mongo_spec.rb +76 -53
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
- data/spec/mongoid/criteria_spec.rb +4 -2
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/indexable_spec.rb +6 -4
- data/spec/mongoid/matchable/default_spec.rb +1 -1
- data/spec/mongoid/matchable/regexp_spec.rb +2 -2
- data/spec/mongoid/matchable_spec.rb +2 -2
- data/spec/mongoid/query_cache_spec.rb +2 -1
- data/spec/mongoid/relations/proxy_spec.rb +1 -1
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -31
- data/spec/support/child_process_helper.rb +76 -0
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +29 -19
- data/spec/support/spec_config.rb +12 -4
- metadata +16 -2
- metadata.gz.sig +2 -2
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require_relative '../../mongoid/association/embedded/embeds_many_models'
|
6
|
+
require_relative '../../mongoid/association/embedded/embeds_one_models'
|
7
|
+
|
8
|
+
describe 'embedded associations' do
|
9
|
+
|
10
|
+
describe 'parent association' do
|
11
|
+
let(:parent) do
|
12
|
+
parent_cls.new
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'embeds_one' do
|
16
|
+
|
17
|
+
shared_examples 'is set' do
|
18
|
+
it 'is set' do
|
19
|
+
parent.child = child_cls.new
|
20
|
+
parent.child.parent.should == parent
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'class_name set without leading ::' do
|
25
|
+
let(:parent_cls) { EomParent }
|
26
|
+
let(:child_cls) { EomChild }
|
27
|
+
|
28
|
+
it_behaves_like 'is set'
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'class_name set with leading ::' do
|
32
|
+
let(:parent_cls) { EomCcParent }
|
33
|
+
let(:child_cls) { EomCcChild }
|
34
|
+
|
35
|
+
it_behaves_like 'is set'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'embeds_many' do
|
40
|
+
|
41
|
+
let(:child) { parent.legislators.new }
|
42
|
+
|
43
|
+
shared_examples 'is set' do
|
44
|
+
it 'is set' do
|
45
|
+
child.congress.should == parent
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'class_name set without leading ::' do
|
50
|
+
let(:parent_cls) { EmmCongress }
|
51
|
+
|
52
|
+
it_behaves_like 'is set'
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'class_name set with leading ::' do
|
56
|
+
let(:parent_cls) { EmmCcCongress }
|
57
|
+
|
58
|
+
it_behaves_like 'is set'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Mongoid::Document do
|
7
|
+
context 'when including class uses delegate' do
|
8
|
+
let(:patient) do
|
9
|
+
DelegatingPatient.new(
|
10
|
+
email: Email.new(address: 'test@example.com'),
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'works for instance level delegation' do
|
15
|
+
patient.address.should == 'test@example.com'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'works for class level delegation' do
|
19
|
+
DelegatingPatient.default_client.should be Mongoid.default_client
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -44,11 +44,18 @@ RSpec.configure do |config|
|
|
44
44
|
end
|
45
45
|
|
46
46
|
if SpecConfig.instance.ci?
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
timeout = if SpecConfig.instance.app_tests?
|
48
|
+
# Allow 5 minutes per test for the app tests, since they install
|
49
|
+
# gems for Rails applications which can take a long time.
|
50
|
+
300
|
51
|
+
else
|
52
|
+
# Allow a max of 30 seconds per test.
|
53
|
+
# Tests should take under 10 seconds ideally but it seems
|
54
|
+
# we have some that run for more than 10 seconds in CI.
|
55
|
+
30
|
56
|
+
end
|
50
57
|
config.around(:each) do |example|
|
51
|
-
TimeoutInterrupt.timeout(
|
58
|
+
TimeoutInterrupt.timeout(timeout) do
|
52
59
|
example.run
|
53
60
|
end
|
54
61
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
class EmmCongress
|
5
|
+
include Mongoid::Document
|
6
|
+
|
7
|
+
embeds_many :legislators, class_name: 'EmmLegislator'
|
8
|
+
|
9
|
+
field :name, type: String
|
10
|
+
end
|
11
|
+
|
12
|
+
class EmmLegislator
|
13
|
+
include Mongoid::Document
|
14
|
+
|
15
|
+
embedded_in :congress, class_name: 'EmmCongress'
|
16
|
+
|
17
|
+
field :a, type: Integer, default: 0
|
18
|
+
field :b, type: Integer, default: 0
|
19
|
+
end
|
20
|
+
|
21
|
+
# Models with associations with :class_name as a :: prefixed string
|
22
|
+
|
23
|
+
class EmmCcCongress
|
24
|
+
include Mongoid::Document
|
25
|
+
|
26
|
+
embeds_many :legislators, class_name: '::EmmCcLegislator'
|
27
|
+
|
28
|
+
field :name, type: String
|
29
|
+
end
|
30
|
+
|
31
|
+
class EmmCcLegislator
|
32
|
+
include Mongoid::Document
|
33
|
+
|
34
|
+
embedded_in :congress, class_name: '::EmmCcCongress'
|
35
|
+
|
36
|
+
field :a, type: Integer, default: 0
|
37
|
+
field :b, type: Integer, default: 0
|
38
|
+
end
|
39
|
+
|
40
|
+
class EmmManufactory
|
41
|
+
include Mongoid::Document
|
42
|
+
|
43
|
+
embeds_many :products, order: :id.desc, class_name: 'EmmProduct'
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
class EmmProduct
|
48
|
+
include Mongoid::Document
|
49
|
+
|
50
|
+
embedded_in :manufactory, class_name: 'EmmManufactory'
|
51
|
+
|
52
|
+
field :name, type: String
|
53
|
+
end
|
@@ -646,6 +646,16 @@ describe Mongoid::Association::Embedded::EmbedsMany do
|
|
646
646
|
it 'returns the class name option' do
|
647
647
|
expect(association.klass).to eq(_class)
|
648
648
|
end
|
649
|
+
|
650
|
+
context 'when the class name is prefixed with ::' do
|
651
|
+
let(:options) do
|
652
|
+
{ class_name: '::OtherEmbeddedObject' }
|
653
|
+
end
|
654
|
+
|
655
|
+
it 'returns the class name option' do
|
656
|
+
expect(association.klass).to eq(_class)
|
657
|
+
end
|
658
|
+
end
|
649
659
|
end
|
650
660
|
|
651
661
|
context 'when the class_name option is not specified' do
|
@@ -2686,7 +2686,8 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2686
2686
|
expect(preferences).to eq([ preference_one ])
|
2687
2687
|
end
|
2688
2688
|
|
2689
|
-
context 'when providing a collation'
|
2689
|
+
context 'when providing a collation' do
|
2690
|
+
min_server_version '3.4'
|
2690
2691
|
|
2691
2692
|
let(:preferences) do
|
2692
2693
|
person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
|
@@ -2904,7 +2904,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2904
2904
|
expect(posts).to eq([ post_one ])
|
2905
2905
|
end
|
2906
2906
|
|
2907
|
-
context 'when providing a collation'
|
2907
|
+
context 'when providing a collation' do
|
2908
|
+
min_server_version '3.4'
|
2908
2909
|
|
2909
2910
|
let(:posts) do
|
2910
2911
|
person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
|
@@ -11,7 +11,7 @@ describe Mongoid::Clients::Options do
|
|
11
11
|
Mongoid::Clients.clients.clear
|
12
12
|
end
|
13
13
|
|
14
|
-
describe '#with'
|
14
|
+
describe '#with' do
|
15
15
|
|
16
16
|
context 'when passing some options' do
|
17
17
|
|
@@ -72,7 +72,7 @@ describe Mongoid::Clients::Options do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context 'when passing a block'
|
75
|
+
context 'when passing a block' do
|
76
76
|
|
77
77
|
let!(:connections_before) do
|
78
78
|
Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
@@ -284,7 +284,7 @@ describe Mongoid::Clients::Options do
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
describe '.with'
|
287
|
+
describe '.with' do
|
288
288
|
|
289
289
|
context 'when passing some options' do
|
290
290
|
|
@@ -362,7 +362,7 @@ describe Mongoid::Clients::Options do
|
|
362
362
|
end
|
363
363
|
end
|
364
364
|
|
365
|
-
context 'when passing a block'
|
365
|
+
context 'when passing a block' do
|
366
366
|
|
367
367
|
let!(:connections_before) do
|
368
368
|
test_model.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
@@ -40,7 +40,8 @@ describe Mongoid::Clients::Sessions do
|
|
40
40
|
|
41
41
|
context 'when a session is used on a model class' do
|
42
42
|
|
43
|
-
context 'when sessions are supported'
|
43
|
+
context 'when sessions are supported' do
|
44
|
+
min_server_version '3.6'
|
44
45
|
|
45
46
|
around do |example|
|
46
47
|
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
@@ -169,7 +170,8 @@ describe Mongoid::Clients::Sessions do
|
|
169
170
|
end
|
170
171
|
end
|
171
172
|
|
172
|
-
context 'when sessions are not supported'
|
173
|
+
context 'when sessions are not supported' do
|
174
|
+
max_server_version '3.4'
|
173
175
|
|
174
176
|
let!(:error) do
|
175
177
|
e = nil
|
@@ -196,7 +198,8 @@ describe Mongoid::Clients::Sessions do
|
|
196
198
|
end
|
197
199
|
end
|
198
200
|
|
199
|
-
context 'when sessions are supported'
|
201
|
+
context 'when sessions are supported' do
|
202
|
+
min_server_version '3.6'
|
200
203
|
|
201
204
|
around do |example|
|
202
205
|
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
@@ -313,7 +316,8 @@ describe Mongoid::Clients::Sessions do
|
|
313
316
|
end
|
314
317
|
end
|
315
318
|
|
316
|
-
context 'when sessions are not supported'
|
319
|
+
context 'when sessions are not supported' do
|
320
|
+
max_server_version '3.4'
|
317
321
|
|
318
322
|
let!(:error) do
|
319
323
|
e = nil
|
@@ -52,7 +52,8 @@ describe Mongoid::Clients::Sessions do
|
|
52
52
|
|
53
53
|
context 'when a transaction is used on a model class' do
|
54
54
|
|
55
|
-
context 'when transactions are supported'
|
55
|
+
context 'when transactions are supported' do
|
56
|
+
require_transaction_support
|
56
57
|
|
57
58
|
around do |example|
|
58
59
|
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
@@ -188,7 +189,10 @@ describe Mongoid::Clients::Sessions do
|
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
|
-
context 'when sessions are supported but transactions are not'
|
192
|
+
context 'when sessions are supported but transactions are not' do
|
193
|
+
min_server_version '3.6'
|
194
|
+
# Could also test 4.0 in sharded cluster
|
195
|
+
max_server_version '3.6'
|
192
196
|
|
193
197
|
let!(:error) do
|
194
198
|
e = nil
|
@@ -219,7 +223,8 @@ describe Mongoid::Clients::Sessions do
|
|
219
223
|
end
|
220
224
|
end
|
221
225
|
|
222
|
-
context 'when transactions are supported'
|
226
|
+
context 'when transactions are supported' do
|
227
|
+
require_transaction_support
|
223
228
|
|
224
229
|
around do |example|
|
225
230
|
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
@@ -342,16 +347,23 @@ describe Mongoid::Clients::Sessions do
|
|
342
347
|
end
|
343
348
|
end
|
344
349
|
|
345
|
-
context 'when sessions are supported but transactions are not'
|
350
|
+
context 'when sessions are supported but transactions are not' do
|
351
|
+
min_server_version '3.6'
|
352
|
+
# Could also test 4.0 in sharded cluster
|
353
|
+
max_server_version '3.6'
|
346
354
|
|
347
355
|
around do |example|
|
348
356
|
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
349
357
|
Mongoid::Clients.with_name(:other).command(create: :people)
|
350
|
-
|
351
|
-
|
352
|
-
|
358
|
+
|
359
|
+
begin
|
360
|
+
subscriber.clear_events!
|
361
|
+
person.with(client: :other) do
|
362
|
+
example.run
|
363
|
+
end
|
364
|
+
ensure
|
365
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
353
366
|
end
|
354
|
-
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
355
367
|
end
|
356
368
|
|
357
369
|
let!(:error) do
|
@@ -725,7 +725,7 @@ describe Mongoid::Clients do
|
|
725
725
|
end
|
726
726
|
end
|
727
727
|
|
728
|
-
describe ".store_in"
|
728
|
+
describe ".store_in" do
|
729
729
|
|
730
730
|
context "when provided a non hash" do
|
731
731
|
|
@@ -762,7 +762,7 @@ describe Mongoid::Clients do
|
|
762
762
|
end
|
763
763
|
end
|
764
764
|
|
765
|
-
describe ".with"
|
765
|
+
describe ".with" do
|
766
766
|
|
767
767
|
context "when changing write concern options" do
|
768
768
|
|
@@ -74,7 +74,8 @@ describe Mongoid::Contextual::Atomic do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
context 'when the criteria has a collation'
|
77
|
+
context 'when the criteria has a collation' do
|
78
|
+
min_server_version '3.4'
|
78
79
|
|
79
80
|
let(:criteria) do
|
80
81
|
Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
|
@@ -145,7 +146,8 @@ describe Mongoid::Contextual::Atomic do
|
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
148
|
-
context 'when the criteria has a collation'
|
149
|
+
context 'when the criteria has a collation' do
|
150
|
+
min_server_version '3.4'
|
149
151
|
|
150
152
|
let!(:depeche_mode) do
|
151
153
|
Band.create(members: [ "Dave" ], likes: 60)
|
@@ -224,7 +226,8 @@ describe Mongoid::Contextual::Atomic do
|
|
224
226
|
end
|
225
227
|
end
|
226
228
|
|
227
|
-
context 'when the criteria has a collation'
|
229
|
+
context 'when the criteria has a collation' do
|
230
|
+
min_server_version '3.4'
|
228
231
|
|
229
232
|
let!(:depeche_mode) do
|
230
233
|
Band.create(members: [ "Dave" ])
|
@@ -296,7 +299,8 @@ describe Mongoid::Contextual::Atomic do
|
|
296
299
|
end
|
297
300
|
end
|
298
301
|
|
299
|
-
context 'when the criteria has a collation'
|
302
|
+
context 'when the criteria has a collation' do
|
303
|
+
min_server_version '3.4'
|
300
304
|
|
301
305
|
let!(:depeche_mode) do
|
302
306
|
Band.create(members: [ "Dave" ])
|
@@ -350,7 +354,8 @@ describe Mongoid::Contextual::Atomic do
|
|
350
354
|
expect(smiths.reload.members).to be_nil
|
351
355
|
end
|
352
356
|
|
353
|
-
context 'when the criteria has a collation'
|
357
|
+
context 'when the criteria has a collation' do
|
358
|
+
min_server_version '3.4'
|
354
359
|
|
355
360
|
let!(:depeche_mode) do
|
356
361
|
Band.create(members: [ "Dave" ])
|
@@ -407,7 +412,8 @@ describe Mongoid::Contextual::Atomic do
|
|
407
412
|
end
|
408
413
|
end
|
409
414
|
|
410
|
-
context 'when the criteria has a collation'
|
415
|
+
context 'when the criteria has a collation' do
|
416
|
+
min_server_version '3.4'
|
411
417
|
|
412
418
|
let!(:depeche_mode) do
|
413
419
|
Band.create(members: [ "Dave", "Alan", "Fletch" ])
|
@@ -464,7 +470,8 @@ describe Mongoid::Contextual::Atomic do
|
|
464
470
|
end
|
465
471
|
end
|
466
472
|
|
467
|
-
context 'when the criteria has a collation'
|
473
|
+
context 'when the criteria has a collation' do
|
474
|
+
min_server_version '3.4'
|
468
475
|
|
469
476
|
let!(:depeche_mode) do
|
470
477
|
Band.create(members: [ "Dave" ])
|
@@ -529,7 +536,8 @@ describe Mongoid::Contextual::Atomic do
|
|
529
536
|
end
|
530
537
|
end
|
531
538
|
|
532
|
-
context 'when the criteria has a collation'
|
539
|
+
context 'when the criteria has a collation' do
|
540
|
+
min_server_version '3.4'
|
533
541
|
|
534
542
|
let!(:depeche_mode) do
|
535
543
|
Band.create(members: [ "Dave" ])
|
@@ -590,7 +598,8 @@ describe Mongoid::Contextual::Atomic do
|
|
590
598
|
end
|
591
599
|
end
|
592
600
|
|
593
|
-
context 'when the criteria has a collation'
|
601
|
+
context 'when the criteria has a collation' do
|
602
|
+
min_server_version '3.4'
|
594
603
|
|
595
604
|
let!(:depeche_mode) do
|
596
605
|
Band.create(members: [ "Dave" ])
|
@@ -749,7 +758,8 @@ describe Mongoid::Contextual::Atomic do
|
|
749
758
|
end
|
750
759
|
end
|
751
760
|
|
752
|
-
context 'when the criteria has a collation'
|
761
|
+
context 'when the criteria has a collation' do
|
762
|
+
min_server_version '3.4'
|
753
763
|
|
754
764
|
let!(:depeche_mode) do
|
755
765
|
Band.create(name: "Depeche Mode", years: 10)
|