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
|
@@ -448,23 +448,110 @@ describe 'callbacks integration tests' do
|
|
|
448
448
|
end
|
|
449
449
|
end
|
|
450
450
|
|
|
451
|
-
context '
|
|
452
|
-
|
|
453
|
-
|
|
451
|
+
context 'saved_change_to_attribute, attribute_before_last_save, will_save_change_to_attribute' do
|
|
452
|
+
class TestSCTAAndABLSInCallbacks
|
|
453
|
+
include Mongoid::Document
|
|
454
454
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
end
|
|
455
|
+
field :name, type: String
|
|
456
|
+
field :age, type: Integer
|
|
458
457
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
set_callback :save, :before do |doc|
|
|
459
|
+
[:name, :age].each do |attr|
|
|
460
|
+
saved_change_to_attribute_values_before[attr] += [saved_change_to_attribute(attr)]
|
|
461
|
+
attribute_before_last_save_values_before[attr] += [attribute_before_last_save(attr)]
|
|
462
|
+
will_save_change_to_attribute_values_before[attr] += [will_save_change_to_attribute?(attr)]
|
|
463
|
+
end
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
set_callback :save, :after do |doc|
|
|
467
|
+
[:name, :age].each do |attr|
|
|
468
|
+
saved_change_to_attribute_values_after[attr] += [saved_change_to_attribute(attr)]
|
|
469
|
+
saved_change_to_attribute_q_values_after[attr] += [saved_change_to_attribute?(attr)]
|
|
470
|
+
attribute_before_last_save_values_after[attr] += [attribute_before_last_save(attr)]
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def saved_change_to_attribute_values_before
|
|
475
|
+
@saved_change_to_attribute_values_before ||= Hash.new do
|
|
476
|
+
[]
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
def attribute_before_last_save_values_before
|
|
481
|
+
@attribute_before_last_save_values_before ||= Hash.new do
|
|
482
|
+
[]
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
def saved_change_to_attribute_values_after
|
|
487
|
+
@saved_change_to_attribute_values_after ||= Hash.new do
|
|
488
|
+
[]
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
def saved_change_to_attribute_q_values_after
|
|
493
|
+
@saved_change_to_attribute_q_values_after ||= Hash.new do
|
|
494
|
+
[]
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
def attribute_before_last_save_values_after
|
|
499
|
+
@attribute_before_last_save_values_after ||= Hash.new do
|
|
500
|
+
[]
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
def will_save_change_to_attribute_values_before
|
|
505
|
+
@will_save_change_to_attribute_values_before ||= Hash.new do
|
|
506
|
+
[]
|
|
507
|
+
end
|
|
462
508
|
end
|
|
463
509
|
end
|
|
464
510
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
511
|
+
it 'reproduces ActiveRecord::AttributeMethods::Dirty behavior' do
|
|
512
|
+
subject = TestSCTAAndABLSInCallbacks.new(name: 'Name 1')
|
|
513
|
+
subject.save!
|
|
514
|
+
subject.age = 18
|
|
515
|
+
subject.save!
|
|
516
|
+
subject.name = 'Name 2'
|
|
517
|
+
subject.save!
|
|
518
|
+
|
|
519
|
+
expect(subject.saved_change_to_attribute_values_before).to eq(
|
|
520
|
+
{
|
|
521
|
+
:name => [nil, [nil, "Name 1"], nil],
|
|
522
|
+
:age => [nil, nil, [nil, 18]],
|
|
523
|
+
}
|
|
524
|
+
)
|
|
525
|
+
expect(subject.saved_change_to_attribute_values_after).to eq(
|
|
526
|
+
{
|
|
527
|
+
:name => [[nil, "Name 1"], nil, ["Name 1", "Name 2"]],
|
|
528
|
+
:age => [nil, [nil, 18], nil],
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
expect(subject.saved_change_to_attribute_q_values_after).to eq(
|
|
532
|
+
{
|
|
533
|
+
:name => [true, false, true],
|
|
534
|
+
:age => [false, true, false],
|
|
535
|
+
}
|
|
536
|
+
)
|
|
537
|
+
expect(subject.attribute_before_last_save_values_before).to eq(
|
|
538
|
+
{
|
|
539
|
+
:name => [nil, nil, "Name 1"],
|
|
540
|
+
:age => [nil, nil, nil]
|
|
541
|
+
}
|
|
542
|
+
)
|
|
543
|
+
expect(subject.attribute_before_last_save_values_after).to eq(
|
|
544
|
+
{
|
|
545
|
+
:name => [nil, "Name 1", "Name 1"],
|
|
546
|
+
:age => [nil, nil, 18]
|
|
547
|
+
}
|
|
548
|
+
)
|
|
549
|
+
expect(subject.will_save_change_to_attribute_values_before).to eq(
|
|
550
|
+
{
|
|
551
|
+
:name => [true, false, true],
|
|
552
|
+
:age => [false, true, false]
|
|
553
|
+
}
|
|
554
|
+
)
|
|
468
555
|
end
|
|
469
556
|
end
|
|
470
557
|
|
|
@@ -81,8 +81,9 @@ describe "#discriminator_key" do
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
context "before class creation" do
|
|
84
|
+
config_override :discriminator_key, "test"
|
|
85
|
+
|
|
84
86
|
before do
|
|
85
|
-
Mongoid.discriminator_key = "test"
|
|
86
87
|
|
|
87
88
|
class PreGlobalIntDiscriminatorParent
|
|
88
89
|
include Mongoid::Document
|
|
@@ -93,7 +94,6 @@ describe "#discriminator_key" do
|
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
after do
|
|
96
|
-
Mongoid.discriminator_key = "_type"
|
|
97
97
|
Object.send(:remove_const, :PreGlobalIntDiscriminatorParent)
|
|
98
98
|
Object.send(:remove_const, :PreGlobalIntDiscriminatorChild)
|
|
99
99
|
end
|
|
@@ -336,9 +336,9 @@ describe "#discriminator_key" do
|
|
|
336
336
|
end
|
|
337
337
|
|
|
338
338
|
context "Example 3" do
|
|
339
|
-
|
|
340
|
-
Mongoid.discriminator_key = "shape_type"
|
|
339
|
+
config_override :discriminator_key, "shape_type"
|
|
341
340
|
|
|
341
|
+
before do
|
|
342
342
|
class Example3Shape
|
|
343
343
|
include Mongoid::Document
|
|
344
344
|
field :x, type: Integer
|
|
@@ -358,7 +358,6 @@ describe "#discriminator_key" do
|
|
|
358
358
|
end
|
|
359
359
|
|
|
360
360
|
after do
|
|
361
|
-
Mongoid.discriminator_key = "_type"
|
|
362
361
|
Object.send(:remove_const, :Example3Shape)
|
|
363
362
|
Object.send(:remove_const, :Example3Circle)
|
|
364
363
|
Object.send(:remove_const, :Example3Rectangle)
|
|
@@ -267,20 +267,10 @@ describe "Dots and Dollars" do
|
|
|
267
267
|
DADMUser.where("$_amount": 0).first
|
|
268
268
|
end
|
|
269
269
|
|
|
270
|
-
it
|
|
270
|
+
it "raise an error" do
|
|
271
271
|
expect do
|
|
272
272
|
queried
|
|
273
|
-
end.to raise_error(
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
context 'when allow_unsafe_query_operators is true' do
|
|
277
|
-
config_override :allow_unsafe_query_operators, true
|
|
278
|
-
|
|
279
|
-
it 'raises an error from the server' do
|
|
280
|
-
expect do
|
|
281
|
-
queried
|
|
282
|
-
end.to raise_error(Mongo::Error::OperationFailure)
|
|
283
|
-
end
|
|
273
|
+
end.to raise_error(Mongo::Error::OperationFailure)
|
|
284
274
|
end
|
|
285
275
|
end
|
|
286
276
|
end
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe 'i18n fallbacks' do
|
|
6
|
-
|
|
6
|
+
require_fallbacks
|
|
7
7
|
|
|
8
8
|
context 'when fallbacks are enabled with a locale list' do
|
|
9
|
+
with_default_i18n_configs
|
|
10
|
+
|
|
9
11
|
before do
|
|
10
|
-
I18n.default_locale = :en
|
|
11
12
|
I18n.fallbacks[:de] = [ :en ]
|
|
12
13
|
end
|
|
13
14
|
|
|
@@ -135,27 +135,6 @@
|
|
|
135
135
|
$regex: bar
|
|
136
136
|
matches: false
|
|
137
137
|
|
|
138
|
-
# Object#=~ is gone as of Ruby 3.2, so an element that cannot be matched
|
|
139
|
-
# against has to be skipped rather than passed to =~.
|
|
140
|
-
- name: array field value - element that cannot be matched against
|
|
141
|
-
document:
|
|
142
|
-
title:
|
|
143
|
-
- 42
|
|
144
|
-
- foo
|
|
145
|
-
query:
|
|
146
|
-
title:
|
|
147
|
-
$regex: foo
|
|
148
|
-
matches: true
|
|
149
|
-
|
|
150
|
-
- name: array field value - no element can be matched against
|
|
151
|
-
document:
|
|
152
|
-
title:
|
|
153
|
-
- 42
|
|
154
|
-
query:
|
|
155
|
-
title:
|
|
156
|
-
$regex: foo
|
|
157
|
-
matches: false
|
|
158
|
-
|
|
159
138
|
- name: true field value
|
|
160
139
|
document:
|
|
161
140
|
title: true
|
|
@@ -14,36 +14,14 @@ describe Mongoid::Association::EagerLoadable do
|
|
|
14
14
|
Mongoid::Contextual::Mongo.new(criteria)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
let(:association_host) { Account }
|
|
18
|
-
|
|
19
17
|
let(:inclusions) do
|
|
20
18
|
includes.map do |key|
|
|
21
|
-
|
|
19
|
+
Account.reflect_on_association(key)
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
let(:doc) { criteria.first }
|
|
26
24
|
|
|
27
|
-
context 'when root is an STI subclass' do
|
|
28
|
-
# Driver has_one Vehicle
|
|
29
|
-
# Vehicle belongs_to Driver
|
|
30
|
-
# Truck is a Vehicle
|
|
31
|
-
|
|
32
|
-
before do
|
|
33
|
-
Driver.create!(vehicle: Truck.new)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
let(:criteria) { Truck.all }
|
|
37
|
-
let(:includes) { %i[ driver ] }
|
|
38
|
-
let(:association_host) { Truck }
|
|
39
|
-
|
|
40
|
-
it 'preloads the driver' do
|
|
41
|
-
expect(doc.ivar(:driver)).to be false
|
|
42
|
-
context.preload(inclusions, [ doc ])
|
|
43
|
-
expect(doc.ivar(:driver)).to be == Driver.first
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
25
|
context "when belongs_to" do
|
|
48
26
|
|
|
49
27
|
let!(:account) do
|
|
@@ -64,7 +42,7 @@ describe Mongoid::Association::EagerLoadable do
|
|
|
64
42
|
it "preloads the parent" do
|
|
65
43
|
expect(doc.ivar(:person)).to be false
|
|
66
44
|
context.preload(inclusions, [doc])
|
|
67
|
-
expect(doc.ivar(:person)).to
|
|
45
|
+
expect(doc.ivar(:person)).to eq(doc.person)
|
|
68
46
|
end
|
|
69
47
|
end
|
|
70
48
|
|
|
@@ -616,4 +616,31 @@ describe Mongoid::Association::Embedded::EmbeddedIn::Proxy do
|
|
|
616
616
|
end
|
|
617
617
|
end
|
|
618
618
|
end
|
|
619
|
+
|
|
620
|
+
context "when assigning a hash" do
|
|
621
|
+
let(:building_address) { BuildingAddress.new }
|
|
622
|
+
|
|
623
|
+
before do
|
|
624
|
+
building_address.building = { name: "Chrysler" }
|
|
625
|
+
end
|
|
626
|
+
|
|
627
|
+
it "creates the objects correctly" do
|
|
628
|
+
expect(building_address.building).to be_a(Building)
|
|
629
|
+
expect(building_address.building.name).to eq("Chrysler")
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
context "when replacing an association with a hash" do
|
|
634
|
+
let(:building_address) { BuildingAddress.new }
|
|
635
|
+
|
|
636
|
+
before do
|
|
637
|
+
building_address.building = { name: "Chrysler" }
|
|
638
|
+
building_address.building = { name: "Empire State" }
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
it "creates the objects correctly" do
|
|
642
|
+
expect(building_address.building).to be_a(Building)
|
|
643
|
+
expect(building_address.building.name).to eq("Empire State")
|
|
644
|
+
end
|
|
645
|
+
end
|
|
619
646
|
end
|
|
@@ -2357,10 +2357,7 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
2357
2357
|
context "when the id does not match" do
|
|
2358
2358
|
|
|
2359
2359
|
context "when config set to raise error" do
|
|
2360
|
-
|
|
2361
|
-
before do
|
|
2362
|
-
Mongoid.raise_not_found_error = true
|
|
2363
|
-
end
|
|
2360
|
+
config_override :raise_not_found_error, true
|
|
2364
2361
|
|
|
2365
2362
|
it "raises an error" do
|
|
2366
2363
|
expect {
|
|
@@ -2370,19 +2367,12 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
2370
2367
|
end
|
|
2371
2368
|
|
|
2372
2369
|
context "when config set not to raise error" do
|
|
2370
|
+
config_override :raise_not_found_error, false
|
|
2373
2371
|
|
|
2374
2372
|
let(:address) do
|
|
2375
2373
|
person.addresses.find(BSON::ObjectId.new)
|
|
2376
2374
|
end
|
|
2377
2375
|
|
|
2378
|
-
before do
|
|
2379
|
-
Mongoid.raise_not_found_error = false
|
|
2380
|
-
end
|
|
2381
|
-
|
|
2382
|
-
after do
|
|
2383
|
-
Mongoid.raise_not_found_error = true
|
|
2384
|
-
end
|
|
2385
|
-
|
|
2386
2376
|
it "returns nil" do
|
|
2387
2377
|
expect(address).to be_nil
|
|
2388
2378
|
end
|
|
@@ -2406,10 +2396,7 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
2406
2396
|
context "when the ids do not match" do
|
|
2407
2397
|
|
|
2408
2398
|
context "when config set to raise error" do
|
|
2409
|
-
|
|
2410
|
-
before do
|
|
2411
|
-
Mongoid.raise_not_found_error = true
|
|
2412
|
-
end
|
|
2399
|
+
config_override :raise_not_found_error, true
|
|
2413
2400
|
|
|
2414
2401
|
it "raises an error" do
|
|
2415
2402
|
expect {
|
|
@@ -2419,19 +2406,12 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
2419
2406
|
end
|
|
2420
2407
|
|
|
2421
2408
|
context "when config set not to raise error" do
|
|
2409
|
+
config_override :raise_not_found_error, false
|
|
2422
2410
|
|
|
2423
2411
|
let(:addresses) do
|
|
2424
2412
|
person.addresses.find([ BSON::ObjectId.new ])
|
|
2425
2413
|
end
|
|
2426
2414
|
|
|
2427
|
-
before do
|
|
2428
|
-
Mongoid.raise_not_found_error = false
|
|
2429
|
-
end
|
|
2430
|
-
|
|
2431
|
-
after do
|
|
2432
|
-
Mongoid.raise_not_found_error = true
|
|
2433
|
-
end
|
|
2434
|
-
|
|
2435
2415
|
it "returns an empty array" do
|
|
2436
2416
|
expect(addresses).to be_empty
|
|
2437
2417
|
end
|
|
@@ -4591,7 +4571,7 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
4591
4571
|
before do
|
|
4592
4572
|
band.collection.
|
|
4593
4573
|
find(_id: band.id).
|
|
4594
|
-
update_one("$set" => { records: [{ name: "Moderat" }]})
|
|
4574
|
+
update_one("$set" => { records: [{ _id: BSON::ObjectId.new, name: "Moderat" }]})
|
|
4595
4575
|
end
|
|
4596
4576
|
|
|
4597
4577
|
context "when loading the documents" do
|
|
@@ -4865,4 +4845,19 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
|
|
|
4865
4845
|
expect(from_db.company_tags.size).to eq(2)
|
|
4866
4846
|
end
|
|
4867
4847
|
end
|
|
4848
|
+
|
|
4849
|
+
context "when assigning hashes" do
|
|
4850
|
+
let(:user) { EmmUser.create! }
|
|
4851
|
+
|
|
4852
|
+
before do
|
|
4853
|
+
user.orders = [ { sku: 1 }, { sku: 2 } ]
|
|
4854
|
+
end
|
|
4855
|
+
|
|
4856
|
+
it "creates the objects correctly" do
|
|
4857
|
+
expect(user.orders.first).to be_a(EmmOrder)
|
|
4858
|
+
expect(user.orders.last).to be_a(EmmOrder)
|
|
4859
|
+
|
|
4860
|
+
expect(user.orders.map(&:sku).sort).to eq([ 1, 2 ])
|
|
4861
|
+
end
|
|
4862
|
+
end
|
|
4868
4863
|
end
|
|
@@ -27,10 +27,6 @@ describe Mongoid::Association::Embedded::EmbedsMany do
|
|
|
27
27
|
expect(legislator.attributes.keys).to eq(['_id', 'a'])
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it 'allows accessing the parent' do
|
|
31
|
-
expect { legislator.congress }.not_to raise_error
|
|
32
|
-
end
|
|
33
|
-
|
|
34
30
|
context 'when using only with $' do
|
|
35
31
|
before do
|
|
36
32
|
Patient.destroy_all
|
|
@@ -202,7 +202,7 @@ describe Mongoid::Association::Embedded::EmbedsOne::Proxy do
|
|
|
202
202
|
end
|
|
203
203
|
end
|
|
204
204
|
end
|
|
205
|
-
|
|
205
|
+
|
|
206
206
|
context 'when the original document does not need to be unset because it will be replaced by the $set' do
|
|
207
207
|
|
|
208
208
|
let!(:pet_owner) do
|
|
@@ -971,7 +971,7 @@ describe Mongoid::Association::Embedded::EmbedsOne::Proxy do
|
|
|
971
971
|
before do
|
|
972
972
|
band.collection.
|
|
973
973
|
find(_id: band.id).
|
|
974
|
-
update_one("$set" => { label: { name: "Mute" }})
|
|
974
|
+
update_one("$set" => { label: { _id: BSON::ObjectId.new, name: "Mute" }})
|
|
975
975
|
end
|
|
976
976
|
|
|
977
977
|
context "when loading the documents" do
|
|
@@ -1022,4 +1022,17 @@ describe Mongoid::Association::Embedded::EmbedsOne::Proxy do
|
|
|
1022
1022
|
expect(building.building_address).to be_a(BuildingAddress)
|
|
1023
1023
|
end
|
|
1024
1024
|
end
|
|
1025
|
+
|
|
1026
|
+
context "when assigning a hash" do
|
|
1027
|
+
let(:building) { Building.create! }
|
|
1028
|
+
|
|
1029
|
+
before do
|
|
1030
|
+
building.building_address = { city: "NYC" }
|
|
1031
|
+
end
|
|
1032
|
+
|
|
1033
|
+
it "creates the objects correctly" do
|
|
1034
|
+
expect(building.building_address).to be_a(BuildingAddress)
|
|
1035
|
+
expect(building.building_address.city).to eq("NYC")
|
|
1036
|
+
end
|
|
1037
|
+
end
|
|
1025
1038
|
end
|
|
@@ -546,17 +546,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
546
546
|
end
|
|
547
547
|
|
|
548
548
|
context 'when the global config option is true' do
|
|
549
|
-
|
|
550
|
-
around(:example) do |example|
|
|
551
|
-
original_config = Mongoid.belongs_to_required_by_default
|
|
552
|
-
Mongoid.belongs_to_required_by_default = true
|
|
553
|
-
example.run
|
|
554
|
-
Mongoid.belongs_to_required_by_default = original_config
|
|
555
|
-
end
|
|
556
|
-
|
|
557
|
-
let!(:original_required_config) do
|
|
558
|
-
Mongoid.belongs_to_required_by_default
|
|
559
|
-
end
|
|
549
|
+
config_override :belongs_to_required_by_default, true
|
|
560
550
|
|
|
561
551
|
context 'when the required option is true' do
|
|
562
552
|
|
|
@@ -684,13 +674,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
684
674
|
end
|
|
685
675
|
|
|
686
676
|
context 'when the global config option is false' do
|
|
687
|
-
|
|
688
|
-
around(:example) do |example|
|
|
689
|
-
original_config = Mongoid.belongs_to_required_by_default
|
|
690
|
-
Mongoid.belongs_to_required_by_default = false
|
|
691
|
-
example.run
|
|
692
|
-
Mongoid.belongs_to_required_by_default = original_config
|
|
693
|
-
end
|
|
677
|
+
config_override :belongs_to_required_by_default, false
|
|
694
678
|
|
|
695
679
|
context 'when the required option is true' do
|
|
696
680
|
|