mongoid 8.0.3 → 8.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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +2 -2
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +23 -21
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +5 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/proxy.rb +7 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +104 -4
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +101 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +373 -113
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/extensions/array.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +0 -8
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -11
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +0 -10
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +7 -5
- data/lib/mongoid/deprecable.rb +1 -1
- data/lib/mongoid/document.rb +50 -13
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/factory.rb +21 -8
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +69 -13
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +7 -6
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/matcher.rb +21 -6
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/shardable.rb +35 -11
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/threaded.rb +30 -0
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -2
- data/spec/integration/callbacks_models.rb +37 -0
- data/spec/integration/callbacks_spec.rb +134 -0
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +57 -57
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +148 -224
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +111 -164
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +5 -8
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -18
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +995 -36
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +3 -11
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -69
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -59
- data/spec/mongoid/criteria/queryable/optional_spec.rb +15 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +1 -1
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -34
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +15 -3
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -4
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +9 -30
- data/spec/mongoid/shardable_models.rb +14 -0
- data/spec/mongoid/shardable_spec.rb +153 -61
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +35 -9
- data/spec/shared/lib/mrss/docker_runner.rb +7 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +10 -2
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +36 -40
- data/spec/shared/shlib/server.sh +32 -8
- data/spec/shared/shlib/set_env.sh +4 -4
- data/spec/spec_helper.rb +5 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/book.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +700 -656
- metadata.gz.sig +0 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
@@ -411,19 +411,12 @@ describe Mongoid::PersistenceContext do
|
|
411
411
|
end
|
412
412
|
|
413
413
|
context 'when there is a database override' do
|
414
|
+
persistence_context_override :database, :other
|
414
415
|
|
415
416
|
before do
|
416
417
|
object.store_in database: :musique
|
417
418
|
end
|
418
419
|
|
419
|
-
before do
|
420
|
-
Mongoid::Threaded.database_override = :other
|
421
|
-
end
|
422
|
-
|
423
|
-
after do
|
424
|
-
Mongoid::Threaded.database_override = nil
|
425
|
-
end
|
426
|
-
|
427
420
|
it 'uses the override' do
|
428
421
|
expect(persistence_context.database_name).to eq(:other)
|
429
422
|
end
|
@@ -458,14 +451,7 @@ describe Mongoid::PersistenceContext do
|
|
458
451
|
end
|
459
452
|
|
460
453
|
context 'when there is a database override' do
|
461
|
-
|
462
|
-
before do
|
463
|
-
Mongoid::Threaded.database_override = :other
|
464
|
-
end
|
465
|
-
|
466
|
-
after do
|
467
|
-
Mongoid::Threaded.database_override = nil
|
468
|
-
end
|
454
|
+
persistence_context_override :database, :other
|
469
455
|
|
470
456
|
it 'uses the persistence context options' do
|
471
457
|
expect(persistence_context.database_name).to eq(:musique)
|
@@ -517,14 +503,7 @@ describe Mongoid::PersistenceContext do
|
|
517
503
|
end
|
518
504
|
|
519
505
|
context 'when there is a database override' do
|
520
|
-
|
521
|
-
before do
|
522
|
-
Mongoid::Threaded.database_override = :other
|
523
|
-
end
|
524
|
-
|
525
|
-
after do
|
526
|
-
Mongoid::Threaded.database_override = nil
|
527
|
-
end
|
506
|
+
persistence_context_override :database, :other
|
528
507
|
|
529
508
|
it 'uses the persistence context options' do
|
530
509
|
expect(persistence_context.database_name).to eq(:musique)
|
@@ -535,14 +514,7 @@ describe Mongoid::PersistenceContext do
|
|
535
514
|
context 'when there are no options passed to the Persistence Context' do
|
536
515
|
|
537
516
|
context 'when there is a database override' do
|
538
|
-
|
539
|
-
before do
|
540
|
-
Mongoid::Threaded.database_override = :other
|
541
|
-
end
|
542
|
-
|
543
|
-
after do
|
544
|
-
Mongoid::Threaded.database_override = nil
|
545
|
-
end
|
517
|
+
persistence_context_override :database, :other
|
546
518
|
|
547
519
|
it 'uses the database override options' do
|
548
520
|
expect(persistence_context.database_name).to eq(Mongoid::Threaded.database_override)
|
@@ -585,15 +557,7 @@ describe Mongoid::PersistenceContext do
|
|
585
557
|
end
|
586
558
|
|
587
559
|
context 'when there is a client override' do
|
588
|
-
|
589
|
-
before do
|
590
|
-
Mongoid::Threaded.client_override = :other
|
591
|
-
end
|
592
|
-
|
593
|
-
after do
|
594
|
-
persistence_context.client.close
|
595
|
-
Mongoid::Threaded.client_override = nil
|
596
|
-
end
|
560
|
+
persistence_context_override :client, :other
|
597
561
|
|
598
562
|
it 'uses the client option' do
|
599
563
|
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
|
@@ -637,14 +601,7 @@ describe Mongoid::PersistenceContext do
|
|
637
601
|
end
|
638
602
|
|
639
603
|
context 'when there is a client override' do
|
640
|
-
|
641
|
-
before do
|
642
|
-
Mongoid::Threaded.client_override = :alternative
|
643
|
-
end
|
644
|
-
|
645
|
-
after do
|
646
|
-
Mongoid::Threaded.client_override = nil
|
647
|
-
end
|
604
|
+
persistence_context_override :client, :alternative
|
648
605
|
|
649
606
|
it 'uses the client override' do
|
650
607
|
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
|
@@ -680,14 +637,7 @@ describe Mongoid::PersistenceContext do
|
|
680
637
|
end
|
681
638
|
|
682
639
|
context 'when there is a client override' do
|
683
|
-
|
684
|
-
before do
|
685
|
-
Mongoid::Threaded.client_override = :alternative
|
686
|
-
end
|
687
|
-
|
688
|
-
after do
|
689
|
-
Mongoid::Threaded.client_override = nil
|
690
|
-
end
|
640
|
+
persistence_context_override :client, :alternative
|
691
641
|
|
692
642
|
it 'uses the client override' do
|
693
643
|
expect(persistence_context.client).to eq(Mongoid::Clients.with_name(:alternative))
|
@@ -24,21 +24,12 @@ describe Mongoid::QueryCache do
|
|
24
24
|
Mrss::SessionRegistry.instance.verify_sessions_ended!
|
25
25
|
end
|
26
26
|
|
27
|
-
let(:reset_legacy_qc_warning) do
|
28
|
-
begin
|
29
|
-
Mongoid::QueryCache.remove_instance_variable('@legacy_query_cache_warned')
|
30
|
-
rescue NameError
|
31
|
-
# raised if the instance variable wasn't set
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
27
|
describe '#cache' do
|
28
|
+
|
36
29
|
context 'with driver query cache' do
|
37
30
|
|
38
31
|
context 'when query cache is not enabled' do
|
39
|
-
|
40
|
-
Mongoid::QueryCache.enabled = false
|
41
|
-
end
|
32
|
+
override_query_cache false
|
42
33
|
|
43
34
|
it 'turns on the query cache within the block' do
|
44
35
|
expect(Mongoid::QueryCache.enabled?).to be false
|
@@ -52,9 +43,7 @@ describe Mongoid::QueryCache do
|
|
52
43
|
end
|
53
44
|
|
54
45
|
context 'when query cache is enabled' do
|
55
|
-
|
56
|
-
Mongoid::QueryCache.enabled = true
|
57
|
-
end
|
46
|
+
override_query_cache true
|
58
47
|
|
59
48
|
it 'keeps the query cache enabled within the block' do
|
60
49
|
expect(Mongoid::QueryCache.enabled?).to be true
|
@@ -84,12 +73,11 @@ describe Mongoid::QueryCache do
|
|
84
73
|
end
|
85
74
|
|
86
75
|
describe '#uncached' do
|
76
|
+
|
87
77
|
context 'with driver query cache' do
|
88
78
|
|
89
79
|
context 'when query cache is not enabled' do
|
90
|
-
|
91
|
-
Mongoid::QueryCache.enabled = false
|
92
|
-
end
|
80
|
+
override_query_cache false
|
93
81
|
|
94
82
|
it 'keeps the query cache turned off within the block' do
|
95
83
|
expect(Mongoid::QueryCache.enabled?).to be false
|
@@ -103,9 +91,7 @@ describe Mongoid::QueryCache do
|
|
103
91
|
end
|
104
92
|
|
105
93
|
context 'when query cache is enabled' do
|
106
|
-
|
107
|
-
Mongoid::QueryCache.enabled = true
|
108
|
-
end
|
94
|
+
override_query_cache true
|
109
95
|
|
110
96
|
it 'turns off the query cache within the block' do
|
111
97
|
expect(Mongoid::QueryCache.enabled?).to be true
|
@@ -159,10 +145,7 @@ describe Mongoid::QueryCache do
|
|
159
145
|
end
|
160
146
|
|
161
147
|
context 'does not query for the relation and instead sets the base' do
|
162
|
-
|
163
|
-
before do
|
164
|
-
Mongoid::QueryCache.enabled = false
|
165
|
-
end
|
148
|
+
override_query_cache false
|
166
149
|
|
167
150
|
it 'queries for each access to the base' do
|
168
151
|
expect(server).to receive(:with_connection).exactly(0).times.and_call_original
|
@@ -180,10 +163,7 @@ describe Mongoid::QueryCache do
|
|
180
163
|
end
|
181
164
|
|
182
165
|
context 'when query cache is disabled' do
|
183
|
-
|
184
|
-
before do
|
185
|
-
Mongoid::QueryCache.enabled = false
|
186
|
-
end
|
166
|
+
override_query_cache false
|
187
167
|
|
188
168
|
it 'does not query for access to the base' do
|
189
169
|
expect(server).to receive(:context).exactly(0).times.and_call_original
|
@@ -194,10 +174,7 @@ describe Mongoid::QueryCache do
|
|
194
174
|
end
|
195
175
|
|
196
176
|
context 'when query cache is enabled' do
|
197
|
-
|
198
|
-
before do
|
199
|
-
Mongoid::QueryCache.enabled = true
|
200
|
-
end
|
177
|
+
override_query_cache true
|
201
178
|
|
202
179
|
it 'does not query for access to the base' do
|
203
180
|
expect(server).to receive(:context).exactly(0).times.and_call_original
|
@@ -243,10 +220,7 @@ describe Mongoid::QueryCache do
|
|
243
220
|
end
|
244
221
|
|
245
222
|
context 'when block is cached' do
|
246
|
-
|
247
|
-
before do
|
248
|
-
Mongoid::QueryCache.enabled = false
|
249
|
-
end
|
223
|
+
override_query_cache false
|
250
224
|
|
251
225
|
it 'uses the driver query cache' do
|
252
226
|
expect(Mongo::QueryCache).to receive(:cache).and_call_original
|
@@ -259,10 +233,7 @@ describe Mongoid::QueryCache do
|
|
259
233
|
end
|
260
234
|
|
261
235
|
context 'when block is uncached' do
|
262
|
-
|
263
|
-
before do
|
264
|
-
Mongoid::QueryCache.enabled = true
|
265
|
-
end
|
236
|
+
override_query_cache true
|
266
237
|
|
267
238
|
it 'uses the driver query cache' do
|
268
239
|
expect(Mongo::QueryCache).to receive(:uncached).and_call_original
|
@@ -314,10 +285,7 @@ describe Mongoid::QueryCache do
|
|
314
285
|
end
|
315
286
|
|
316
287
|
context "when query cache is disabled" do
|
317
|
-
|
318
|
-
before do
|
319
|
-
Mongoid::QueryCache.enabled = false
|
320
|
-
end
|
288
|
+
override_query_cache false
|
321
289
|
|
322
290
|
it "queries again" do
|
323
291
|
expect_query(1) do
|
@@ -440,10 +408,7 @@ describe Mongoid::QueryCache do
|
|
440
408
|
end
|
441
409
|
|
442
410
|
context "when query cache is disabled" do
|
443
|
-
|
444
|
-
before do
|
445
|
-
Mongoid::QueryCache.enabled = false
|
446
|
-
end
|
411
|
+
override_query_cache false
|
447
412
|
|
448
413
|
it "queries again" do
|
449
414
|
expect_query(1) do
|
@@ -669,13 +634,7 @@ describe Mongoid::QueryCache do
|
|
669
634
|
end
|
670
635
|
|
671
636
|
context "when query caching is enabled and the batch_size is set" do
|
672
|
-
|
673
|
-
around(:each) do |example|
|
674
|
-
query_cache_enabled = Mongoid::QueryCache.enabled?
|
675
|
-
Mongoid::QueryCache.enabled = true
|
676
|
-
example.run
|
677
|
-
Mongoid::QueryCache.enabled = query_cache_enabled
|
678
|
-
end
|
637
|
+
override_query_cache true
|
679
638
|
|
680
639
|
it "does not raise an error when requesting the second batch" do
|
681
640
|
expect {
|
@@ -684,7 +643,6 @@ describe Mongoid::QueryCache do
|
|
684
643
|
end
|
685
644
|
}.not_to raise_error
|
686
645
|
end
|
687
|
-
|
688
646
|
end
|
689
647
|
end
|
690
648
|
|
@@ -752,10 +710,7 @@ describe Mongoid::QueryCache do
|
|
752
710
|
end
|
753
711
|
|
754
712
|
context 'when query cache is disabled' do
|
755
|
-
|
756
|
-
before do
|
757
|
-
Mongoid::QueryCache.enabled = false
|
758
|
-
end
|
713
|
+
override_query_cache false
|
759
714
|
|
760
715
|
it "queries again" do
|
761
716
|
band = Band.find(band_id)
|
@@ -819,8 +774,9 @@ describe Mongoid::QueryCache do
|
|
819
774
|
end
|
820
775
|
|
821
776
|
context 'when the initial query does not exhaust the results' do
|
777
|
+
override_query_cache true
|
778
|
+
|
822
779
|
before do
|
823
|
-
Mongoid::QueryCache.enabled = true
|
824
780
|
10.times { Band.create! }
|
825
781
|
|
826
782
|
Band.batch_size(4).to_a
|
@@ -867,4 +823,43 @@ describe Mongoid::QueryCache do
|
|
867
823
|
school.students.to_a.length.should == 5
|
868
824
|
end
|
869
825
|
end
|
826
|
+
|
827
|
+
describe 'deprecation warnings' do
|
828
|
+
|
829
|
+
context '#cache' do
|
830
|
+
it 'should raise a warning' do
|
831
|
+
expect(Mongoid::Warnings).to receive(:warn_mongoid_query_cache)
|
832
|
+
Mongoid::QueryCache.cache {}
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
context '#uncached' do
|
837
|
+
it 'should raise a warning' do
|
838
|
+
expect(Mongoid::Warnings).to receive(:warn_mongoid_query_cache)
|
839
|
+
Mongoid::QueryCache.uncached {}
|
840
|
+
end
|
841
|
+
end
|
842
|
+
|
843
|
+
context '#clear_cache' do
|
844
|
+
it 'should raise a warning' do
|
845
|
+
expect(Mongoid::Warnings).to receive(:warn_mongoid_query_cache_clear)
|
846
|
+
Mongoid::QueryCache.clear_cache
|
847
|
+
end
|
848
|
+
end
|
849
|
+
|
850
|
+
context '#enabled?' do
|
851
|
+
it 'should raise a warning' do
|
852
|
+
expect(Mongoid::Warnings).to receive(:warn_mongoid_query_cache)
|
853
|
+
Mongoid::QueryCache.enabled?
|
854
|
+
end
|
855
|
+
end
|
856
|
+
|
857
|
+
context '#enabled=' do
|
858
|
+
it 'should raise a warning' do
|
859
|
+
old_enabled = Mongoid::QueryCache.enabled?
|
860
|
+
expect(Mongoid::Warnings).to receive(:warn_mongoid_query_cache)
|
861
|
+
Mongoid::QueryCache.enabled = old_enabled
|
862
|
+
end
|
863
|
+
end
|
864
|
+
end
|
870
865
|
end
|
@@ -488,12 +488,32 @@ describe Mongoid::Reloadable do
|
|
488
488
|
Person.create!
|
489
489
|
end
|
490
490
|
|
491
|
-
|
492
|
-
|
491
|
+
context "when legacy_readonly is on" do
|
492
|
+
config_override :legacy_readonly, true
|
493
|
+
|
494
|
+
let(:reloaded) do
|
495
|
+
Person.only(:name).first.reload
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'resets the readonly state after reloading' do
|
499
|
+
expect(reloaded.readonly?).to be(false)
|
500
|
+
end
|
493
501
|
end
|
494
502
|
|
495
|
-
|
496
|
-
|
503
|
+
context "when legacy_readonly is off" do
|
504
|
+
config_override :legacy_readonly, false
|
505
|
+
|
506
|
+
let(:reloaded) do
|
507
|
+
Person.only(:name).first.tap do |doc|
|
508
|
+
doc.readonly!
|
509
|
+
expect(doc.readonly?).to be true
|
510
|
+
doc.reload
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
it 'does not reset the readonly state after reloading' do
|
515
|
+
expect(reloaded.readonly?).to be(true)
|
516
|
+
end
|
497
517
|
end
|
498
518
|
end
|
499
519
|
|
@@ -121,6 +121,76 @@ describe Mongoid::Scopable do
|
|
121
121
|
expect(selector).to eq({'active' => true})
|
122
122
|
end
|
123
123
|
end
|
124
|
+
|
125
|
+
context "when the default scope is dotted" do
|
126
|
+
|
127
|
+
let(:criteria) do
|
128
|
+
Band.where('tags.foo' => 'bar')
|
129
|
+
end
|
130
|
+
|
131
|
+
before do
|
132
|
+
Band.default_scope ->{ criteria }
|
133
|
+
end
|
134
|
+
|
135
|
+
after do
|
136
|
+
Band.default_scoping = nil
|
137
|
+
end
|
138
|
+
|
139
|
+
let!(:band) do
|
140
|
+
Band.create!
|
141
|
+
end
|
142
|
+
|
143
|
+
it "adds the scope as a dotted key attribute" do
|
144
|
+
expect(band.attributes['tags.foo']).to eq('bar')
|
145
|
+
end
|
146
|
+
|
147
|
+
it "adds the default scope to the class" do
|
148
|
+
expect(Band.default_scoping.call).to eq(criteria)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "flags as being default scoped" do
|
152
|
+
expect(Band).to be_default_scoping
|
153
|
+
end
|
154
|
+
|
155
|
+
it "does not find the correct document" do
|
156
|
+
expect(Band.count).to eq(0)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "when the default scope is dotted with a query" do
|
161
|
+
|
162
|
+
let(:criteria) do
|
163
|
+
Band.where('tags.foo' => {'$eq' => 'bar'})
|
164
|
+
end
|
165
|
+
|
166
|
+
before do
|
167
|
+
Band.default_scope ->{ criteria }
|
168
|
+
end
|
169
|
+
|
170
|
+
after do
|
171
|
+
Band.default_scoping = nil
|
172
|
+
end
|
173
|
+
|
174
|
+
let!(:band) do
|
175
|
+
Band.create!('tags' => { 'foo' => 'bar' })
|
176
|
+
end
|
177
|
+
|
178
|
+
it "does not add the scope as a dotted key attribute" do
|
179
|
+
expect(band.attributes).to_not have_key('tags.foo')
|
180
|
+
end
|
181
|
+
|
182
|
+
it "adds the default scope to the class" do
|
183
|
+
expect(Band.default_scoping.call).to eq(criteria)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "flags as being default scoped" do
|
187
|
+
expect(Band).to be_default_scoping
|
188
|
+
end
|
189
|
+
|
190
|
+
it "finds the correct document" do
|
191
|
+
expect(Band.where.first).to eq(band)
|
192
|
+
end
|
193
|
+
end
|
124
194
|
end
|
125
195
|
|
126
196
|
describe ".default_scopable?" do
|
@@ -14,19 +14,19 @@ describe Mongoid::Serializable do
|
|
14
14
|
expect(guitar.send(:field_names, {})).to eq(guitar.fields.except("_type").keys.sort)
|
15
15
|
end
|
16
16
|
|
17
|
-
context "when using a custom discriminator_key" do
|
18
|
-
before do
|
17
|
+
context "when using a custom discriminator_key" do
|
18
|
+
before do
|
19
19
|
Instrument.discriminator_key = "dkey"
|
20
20
|
end
|
21
21
|
|
22
|
-
after do
|
22
|
+
after do
|
23
23
|
Instrument.discriminator_key = nil
|
24
24
|
end
|
25
25
|
|
26
26
|
let(:guitar) do
|
27
27
|
Guitar.new
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "includes _type but does not include the new discriminator key" do
|
31
31
|
expect(guitar.send(:field_names, {})).to eq(guitar.fields.except("dkey").keys.sort)
|
32
32
|
end
|
@@ -41,15 +41,11 @@ describe Mongoid::Serializable do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
after do
|
44
|
-
Mongoid.include_root_in_json = false
|
45
44
|
reload_model(:Minim)
|
46
45
|
end
|
47
46
|
|
48
47
|
context "when global config is set to true" do
|
49
|
-
|
50
|
-
before do
|
51
|
-
Mongoid.include_root_in_json = true
|
52
|
-
end
|
48
|
+
config_override :include_root_in_json, true
|
53
49
|
|
54
50
|
it "returns true" do
|
55
51
|
expect(Minim.public_send(meth)).to be true
|
@@ -67,10 +63,7 @@ describe Mongoid::Serializable do
|
|
67
63
|
end
|
68
64
|
|
69
65
|
context "when global config set to false" do
|
70
|
-
|
71
|
-
before do
|
72
|
-
Mongoid.include_root_in_json = false
|
73
|
-
end
|
66
|
+
config_override :include_root_in_json, false
|
74
67
|
|
75
68
|
it "returns false" do
|
76
69
|
expect(Minim.public_send(meth)).to be false
|
@@ -89,13 +82,13 @@ describe Mongoid::Serializable do
|
|
89
82
|
end
|
90
83
|
|
91
84
|
describe "#include_root_in_json" do
|
85
|
+
config_override :include_root_in_json, false
|
92
86
|
|
93
87
|
before do
|
94
88
|
reload_model(:Minim)
|
95
89
|
end
|
96
90
|
|
97
91
|
after do
|
98
|
-
Mongoid.include_root_in_json = false
|
99
92
|
reload_model(:Minim)
|
100
93
|
end
|
101
94
|
|
@@ -127,10 +120,6 @@ describe Mongoid::Serializable do
|
|
127
120
|
|
128
121
|
context "when global config set to false" do
|
129
122
|
|
130
|
-
before do
|
131
|
-
Mongoid.include_root_in_json = false
|
132
|
-
end
|
133
|
-
|
134
123
|
it "returns false" do
|
135
124
|
expect(minim.public_send(meth)).to be false
|
136
125
|
end
|
@@ -297,14 +286,7 @@ describe Mongoid::Serializable do
|
|
297
286
|
end
|
298
287
|
|
299
288
|
context "when include_type_for_serialization is true" do
|
300
|
-
|
301
|
-
before do
|
302
|
-
Mongoid.include_type_for_serialization = true
|
303
|
-
end
|
304
|
-
|
305
|
-
after do
|
306
|
-
Mongoid.include_type_for_serialization = false
|
307
|
-
end
|
289
|
+
config_override :include_type_for_serialization, true
|
308
290
|
|
309
291
|
it "includes _type field" do
|
310
292
|
expect(person.serializable_hash.keys).to include '_type'
|
@@ -881,16 +863,13 @@ describe Mongoid::Serializable do
|
|
881
863
|
end
|
882
864
|
|
883
865
|
context "when including root in json via Mongoid" do
|
866
|
+
config_override :include_root_in_json, false
|
884
867
|
|
885
868
|
before do
|
886
869
|
account.include_root_in_json.should be false
|
887
870
|
Mongoid.include_root_in_json = true
|
888
871
|
end
|
889
872
|
|
890
|
-
after do
|
891
|
-
Mongoid.include_root_in_json = false
|
892
|
-
end
|
893
|
-
|
894
873
|
it "uses the mongoid configuration" do
|
895
874
|
expect(JSON.parse(account.to_json)).to have_key("account")
|
896
875
|
end
|
@@ -59,3 +59,17 @@ end
|
|
59
59
|
class SmNotSharded
|
60
60
|
include Mongoid::Document
|
61
61
|
end
|
62
|
+
|
63
|
+
class SmReviewAuthor
|
64
|
+
include Mongoid::Document
|
65
|
+
embedded_in :review, class_name: "SmReview", touch: false
|
66
|
+
field :name, type: String
|
67
|
+
end
|
68
|
+
|
69
|
+
class SmReview
|
70
|
+
include Mongoid::Document
|
71
|
+
|
72
|
+
embeds_one :author, class_name: "SmReviewAuthor"
|
73
|
+
|
74
|
+
shard_key "author.name" => 1
|
75
|
+
end
|