mongoid 8.0.13 → 8.1.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +17 -66
- data/lib/config/locales/en.yml +46 -40
- data/lib/mongoid/association/accessors.rb +3 -7
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/depending.rb +4 -8
- data/lib/mongoid/association/eager_loadable.rb +0 -3
- 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 +6 -6
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
- data/lib/mongoid/association/macros.rb +0 -6
- data/lib/mongoid/association/nested/many.rb +3 -38
- data/lib/mongoid/association/nested/nested_buildable.rb +0 -14
- 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 +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
- data/lib/mongoid/association/referenced/has_many/proxy.rb +4 -103
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +7 -16
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/processing.rb +5 -29
- 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 +107 -5
- data/lib/mongoid/clients/factory.rb +0 -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/options.rb +0 -3
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +88 -89
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -5
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +240 -51
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +370 -133
- 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/numeric.rb +1 -15
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -13
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -121
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -2
- data/lib/mongoid/deprecation.rb +3 -3
- data/lib/mongoid/document.rb +1 -8
- 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 -2
- data/lib/mongoid/extensions/hash.rb +3 -51
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +59 -35
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +6 -116
- data/lib/mongoid/matchable.rb +1 -6
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +5 -3
- data/lib/mongoid/matcher/regex.rb +9 -8
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/matcher.rb +0 -1
- 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/reloadable.rb +5 -3
- 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 +0 -3
- data/lib/mongoid/timestamps/created.rb +1 -8
- data/lib/mongoid/traversable.rb +0 -12
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +17 -98
- data/lib/mongoid/validatable/macros.rb +5 -20
- data/lib/mongoid/validatable.rb +4 -10
- data/lib/mongoid/version.rb +1 -5
- data/lib/mongoid/warnings.rb +17 -2
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -20
- data/spec/integration/associations/embeds_one_spec.rb +5 -25
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -55
- data/spec/integration/callbacks_spec.rb +99 -12
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/dots_and_dollars_spec.rb +2 -12
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/integration/matcher_operator_data/regex.yml +0 -21
- data/spec/mongoid/association/eager_spec.rb +2 -24
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
- 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 +42 -103
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -195
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes/nested_spec.rb +10 -204
- data/spec/mongoid/attributes_spec.rb +3 -33
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients/factory_spec.rb +0 -30
- 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 -27
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +0 -91
- data/spec/mongoid/contextual/memory_spec.rb +332 -253
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +2 -10
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -2
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +0 -235
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -11
- data/spec/mongoid/document_spec.rb +0 -27
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/hash_spec.rb +3 -239
- 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 -77
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +153 -442
- data/spec/mongoid/interceptable_spec_models.rb +111 -51
- 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 -28
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +23 -44
- 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/created_spec.rb +0 -23
- 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/associated_spec.rb +34 -27
- data/spec/mongoid/validatable/numericality_spec.rb +0 -16
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/shared/lib/mrss/docker_runner.rb +1 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -1
- data/spec/shared/lib/mrss/spec_organizer.rb +3 -32
- data/spec/shared/share/Dockerfile.erb +85 -15
- data/spec/shared/shlib/distro.sh +0 -10
- data/spec/shared/shlib/server.sh +27 -34
- data/spec/shared/shlib/set_env.sh +68 -9
- data/spec/spec_helper.rb +5 -0
- data/spec/support/expectations.rb +17 -20
- 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/building.rb +2 -0
- data/spec/support/models/name.rb +0 -10
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +715 -671
- metadata.gz.sig +2 -0
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
- data/lib/mongoid/field_readable.rb +0 -70
- data/lib/mongoid/matcher/regexp_budget.rb +0 -389
- data/lib/mongoid/validatable/numericality.rb +0 -19
- data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
- data/spec/integration/query_operator_guard_spec.rb +0 -89
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -61
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -61
- data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
- data/spec/shared/CANDIDATE.md +0 -28
- data/spec/shared/lib/mrss/release/candidate.rb +0 -281
- data/spec/shared/lib/mrss/release/product_data.rb +0 -144
- data/spec/shared/lib/tasks/candidate.rake +0 -64
- data/spec/support/models/purse.rb +0 -9
data/spec/mongoid/config_spec.rb
CHANGED
|
@@ -224,6 +224,79 @@ describe Mongoid::Config do
|
|
|
224
224
|
end
|
|
225
225
|
end
|
|
226
226
|
|
|
227
|
+
context 'async_query_executor option' do
|
|
228
|
+
let(:option) { :async_query_executor }
|
|
229
|
+
|
|
230
|
+
before do
|
|
231
|
+
Mongoid::Config.reset
|
|
232
|
+
Mongoid.configure do |config|
|
|
233
|
+
config.load_configuration(conf)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
context "when it is not set in the config" do
|
|
238
|
+
|
|
239
|
+
let(:conf) { CONFIG }
|
|
240
|
+
|
|
241
|
+
it "it is set to its default" do
|
|
242
|
+
expect(Mongoid.send(option)).to eq(:immediate)
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
context 'when the value is :immediate' do
|
|
247
|
+
|
|
248
|
+
let(:conf) do
|
|
249
|
+
CONFIG.merge(options: { option => :immediate })
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "is set to false" do
|
|
253
|
+
expect(Mongoid.send(option)).to be(:immediate)
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
context 'when the value is :global_thread_pool' do
|
|
258
|
+
|
|
259
|
+
let(:conf) do
|
|
260
|
+
CONFIG.merge(options: { option => :global_thread_pool })
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it "is set to false" do
|
|
264
|
+
expect(Mongoid.send(option)).to be(:global_thread_pool)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
context 'global_executor_concurrency option' do
|
|
270
|
+
let(:option) { :global_executor_concurrency }
|
|
271
|
+
|
|
272
|
+
before do
|
|
273
|
+
Mongoid::Config.reset
|
|
274
|
+
Mongoid.configure do |config|
|
|
275
|
+
config.load_configuration(conf)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
context "when it is not set in the config" do
|
|
280
|
+
|
|
281
|
+
let(:conf) { CONFIG }
|
|
282
|
+
|
|
283
|
+
it "it is set to its default" do
|
|
284
|
+
expect(Mongoid.send(option)).to eq(nil)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
context 'when the value is set to a number' do
|
|
289
|
+
|
|
290
|
+
let(:conf) do
|
|
291
|
+
CONFIG.merge(options: { option => 5 })
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it "is set to the number" do
|
|
295
|
+
expect(Mongoid.send(option)).to be(5)
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
227
300
|
shared_examples "a config option" do
|
|
228
301
|
|
|
229
302
|
before do
|
|
@@ -272,15 +345,6 @@ describe Mongoid::Config do
|
|
|
272
345
|
it_behaves_like "a config option"
|
|
273
346
|
end
|
|
274
347
|
|
|
275
|
-
context 'when setting the allow_bson5_decimal128 option in the config' do
|
|
276
|
-
min_bson_version '5.0'
|
|
277
|
-
|
|
278
|
-
let(:option) { :allow_bson5_decimal128 }
|
|
279
|
-
let(:default) { false }
|
|
280
|
-
|
|
281
|
-
it_behaves_like "a config option"
|
|
282
|
-
end
|
|
283
|
-
|
|
284
348
|
context 'when setting the broken_updates option in the config' do
|
|
285
349
|
let(:option) { :broken_updates }
|
|
286
350
|
let(:default) { false }
|
|
@@ -358,6 +422,13 @@ describe Mongoid::Config do
|
|
|
358
422
|
it_behaves_like "a config option"
|
|
359
423
|
end
|
|
360
424
|
|
|
425
|
+
context 'when setting the legacy_readonly option in the config' do
|
|
426
|
+
let(:option) { :legacy_readonly }
|
|
427
|
+
let(:default) { true }
|
|
428
|
+
|
|
429
|
+
it_behaves_like "a config option"
|
|
430
|
+
end
|
|
431
|
+
|
|
361
432
|
describe "#load!" do
|
|
362
433
|
|
|
363
434
|
before(:all) do
|
|
@@ -608,24 +679,26 @@ describe Mongoid::Config do
|
|
|
608
679
|
|
|
609
680
|
it 'passes uuid to driver' do
|
|
610
681
|
Mongo::Client.should receive(:new).with(SpecConfig.instance.addresses,
|
|
611
|
-
{
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
'
|
|
616
|
-
|
|
617
|
-
'
|
|
618
|
-
'
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
682
|
+
{
|
|
683
|
+
auto_encryption_options: {
|
|
684
|
+
'key_vault_namespace' => 'admin.datakeys',
|
|
685
|
+
'kms_providers' => { 'local' => { 'key' => 'z7iYiYKLuYymEWtk4kfny1ESBwwFdA58qMqff96A8ghiOcIK75lJGPUIocku8LOFjQuEgeIP4xlln3s7r93FV9J5sAE7zg8U' } },
|
|
686
|
+
'schema_map' => { 'blog_development.comments' => {
|
|
687
|
+
'bsonType' => 'object',
|
|
688
|
+
'properties' => {
|
|
689
|
+
'message' => { 'encrypt' => {
|
|
690
|
+
'algorithm' => 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic',
|
|
691
|
+
'bsonType' => 'string',
|
|
692
|
+
'keyId' => [BSON::Binary.new("G\xF0 5\xCC@HX\xA2%b\x97\xA9a\xA8\xE7", :uuid)],
|
|
693
|
+
} },
|
|
694
|
+
},
|
|
695
|
+
} } },
|
|
696
|
+
database: 'mongoid_test',
|
|
697
|
+
platform: "mongoid-#{Mongoid::VERSION}",
|
|
698
|
+
wrapping_libraries: [
|
|
699
|
+
{ 'name' => 'Mongoid', 'version' => Mongoid::VERSION },
|
|
700
|
+
],
|
|
701
|
+
}
|
|
629
702
|
)
|
|
630
703
|
|
|
631
704
|
client
|
|
@@ -654,6 +727,17 @@ describe Mongoid::Config do
|
|
|
654
727
|
}.to raise_error(Mongoid::Errors::InvalidConfigOption)
|
|
655
728
|
end
|
|
656
729
|
end
|
|
730
|
+
|
|
731
|
+
context 'when invalid global_executor_concurrency option provided' do
|
|
732
|
+
it "raises an error" do
|
|
733
|
+
expect do
|
|
734
|
+
described_class.options = {
|
|
735
|
+
async_query_executor: :immediate,
|
|
736
|
+
global_executor_concurrency: 5
|
|
737
|
+
}
|
|
738
|
+
end.to raise_error(Mongoid::Errors::InvalidGlobalExecutorConcurrency)
|
|
739
|
+
end
|
|
740
|
+
end
|
|
657
741
|
end
|
|
658
742
|
|
|
659
743
|
describe "#clients=" do
|
|
@@ -854,4 +938,47 @@ describe Mongoid::Config do
|
|
|
854
938
|
end
|
|
855
939
|
end
|
|
856
940
|
end
|
|
941
|
+
|
|
942
|
+
describe 'deprecations' do
|
|
943
|
+
{ use_activesupport_time_zone: true,
|
|
944
|
+
broken_aggregables: false,
|
|
945
|
+
broken_alias_handling: false,
|
|
946
|
+
broken_and: false,
|
|
947
|
+
broken_scoping: false,
|
|
948
|
+
broken_updates: false,
|
|
949
|
+
compare_time_by_ms: true,
|
|
950
|
+
legacy_attributes: false,
|
|
951
|
+
legacy_pluck_distinct: false,
|
|
952
|
+
legacy_triple_equals: false,
|
|
953
|
+
object_id_as_json_oid: false,
|
|
954
|
+
overwrite_chained_operators: false }.each do |option, default|
|
|
955
|
+
|
|
956
|
+
context ":#{option} option" do
|
|
957
|
+
|
|
958
|
+
before do
|
|
959
|
+
Mongoid::Warnings.class_eval do
|
|
960
|
+
instance_variable_set(:"@#{option}_deprecated", false)
|
|
961
|
+
end
|
|
962
|
+
end
|
|
963
|
+
|
|
964
|
+
let(:matcher) do
|
|
965
|
+
/Config option :#{option}.+\. It will always be #{default} beginning in Mongoid 9\.0\./
|
|
966
|
+
end
|
|
967
|
+
|
|
968
|
+
context 'when set to true' do
|
|
969
|
+
it 'gives a deprecation warning' do
|
|
970
|
+
expect(Mongoid.logger).to receive(:warn).with(matcher)
|
|
971
|
+
described_class.send(:"#{option}=", true)
|
|
972
|
+
end
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
context 'when set to false' do
|
|
976
|
+
it 'gives a deprecation warning' do
|
|
977
|
+
expect(Mongoid.logger).to receive(:warn).with(matcher)
|
|
978
|
+
described_class.send(:"#{option}=", false)
|
|
979
|
+
end
|
|
980
|
+
end
|
|
981
|
+
end
|
|
982
|
+
end
|
|
983
|
+
end
|
|
857
984
|
end
|
|
@@ -570,95 +570,4 @@ describe Mongoid::Contextual::Aggregable::Memory do
|
|
|
570
570
|
end
|
|
571
571
|
end
|
|
572
572
|
end
|
|
573
|
-
|
|
574
|
-
context 'when the field name is a method name' do
|
|
575
|
-
let!(:depeche) do
|
|
576
|
-
Band.create!(name: 'Depeche Mode', likes: 1000)
|
|
577
|
-
end
|
|
578
|
-
|
|
579
|
-
let(:criteria) do
|
|
580
|
-
Band.all.tap do |crit|
|
|
581
|
-
crit.documents = [ depeche ]
|
|
582
|
-
end
|
|
583
|
-
end
|
|
584
|
-
|
|
585
|
-
it 'does not call the method for sum' do
|
|
586
|
-
expect(depeche).not_to receive(:delete)
|
|
587
|
-
expect(context.sum(:delete)).to eq(0)
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
it 'does not call the method for min' do
|
|
591
|
-
expect(depeche).not_to receive(:delete)
|
|
592
|
-
expect(context.min(:delete)).to be_nil
|
|
593
|
-
end
|
|
594
|
-
|
|
595
|
-
it 'does not call the method for max' do
|
|
596
|
-
expect(depeche).not_to receive(:delete)
|
|
597
|
-
expect(context.max(:delete)).to be_nil
|
|
598
|
-
end
|
|
599
|
-
|
|
600
|
-
it 'does not call the method for avg' do
|
|
601
|
-
expect(depeche).not_to receive(:delete)
|
|
602
|
-
expect(context.avg(:delete)).to be_nil
|
|
603
|
-
end
|
|
604
|
-
|
|
605
|
-
it 'does not call the method for aggregates' do
|
|
606
|
-
expect(depeche).not_to receive(:delete)
|
|
607
|
-
expect(context.aggregates(:delete))
|
|
608
|
-
.to eq('count' => 0, 'avg' => nil, 'max' => nil, 'min' => nil, 'sum' => 0)
|
|
609
|
-
end
|
|
610
|
-
|
|
611
|
-
it 'does not call a private method for avg' do
|
|
612
|
-
expect(depeche).not_to receive(:exit)
|
|
613
|
-
expect(context.avg(:exit)).to be_nil
|
|
614
|
-
end
|
|
615
|
-
end
|
|
616
|
-
|
|
617
|
-
context 'when the field is not defined' do
|
|
618
|
-
let!(:depeche) do
|
|
619
|
-
Band.create!(name: 'Depeche Mode', likes: 1000)
|
|
620
|
-
end
|
|
621
|
-
|
|
622
|
-
let(:criteria) do
|
|
623
|
-
Band.all.tap do |crit|
|
|
624
|
-
crit.documents = [ depeche ]
|
|
625
|
-
end
|
|
626
|
-
end
|
|
627
|
-
|
|
628
|
-
it 'returns zero for sum' do
|
|
629
|
-
expect(context.sum(:not_a_field)).to eq(0)
|
|
630
|
-
end
|
|
631
|
-
|
|
632
|
-
it 'returns nil for min' do
|
|
633
|
-
expect(context.min(:not_a_field)).to be_nil
|
|
634
|
-
end
|
|
635
|
-
|
|
636
|
-
it 'returns nil for max' do
|
|
637
|
-
expect(context.max(:not_a_field)).to be_nil
|
|
638
|
-
end
|
|
639
|
-
|
|
640
|
-
it 'returns nil for avg' do
|
|
641
|
-
expect(context.avg(:not_a_field)).to be_nil
|
|
642
|
-
end
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
context 'when the field is the foreign key of a many to many association' do
|
|
646
|
-
let!(:preference) do
|
|
647
|
-
Preference.create!(name: 'nature')
|
|
648
|
-
end
|
|
649
|
-
|
|
650
|
-
let!(:person) do
|
|
651
|
-
Person.new(preferences: [ preference ])
|
|
652
|
-
end
|
|
653
|
-
|
|
654
|
-
let(:criteria) do
|
|
655
|
-
Person.all.tap do |crit|
|
|
656
|
-
crit.documents = [ person ]
|
|
657
|
-
end
|
|
658
|
-
end
|
|
659
|
-
|
|
660
|
-
it 'aggregates the stored ids' do
|
|
661
|
-
expect(context.max(:preference_ids)).to eq([ preference.id ])
|
|
662
|
-
end
|
|
663
|
-
end
|
|
664
573
|
end
|