mongoid 8.0.4 → 8.0.6
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/Rakefile +25 -0
- data/lib/mongoid/association/macros.rb +6 -0
- data/lib/mongoid/atomic.rb +7 -0
- data/lib/mongoid/attributes/processing.rb +29 -5
- data/lib/mongoid/changeable.rb +1 -3
- data/lib/mongoid/config/options.rb +3 -0
- data/lib/mongoid/config.rb +17 -0
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +6 -2
- data/lib/mongoid/fields.rb +45 -18
- data/lib/mongoid/reloadable.rb +3 -5
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +27 -0
- data/spec/mongoid/config_spec.rb +9 -0
- data/spec/mongoid/contextual/mongo_spec.rb +41 -11
- data/spec/mongoid/criteria/queryable/selector_spec.rb +75 -2
- data/spec/mongoid/criteria/queryable/storable_spec.rb +72 -0
- data/spec/mongoid/extensions/hash_spec.rb +3 -3
- data/spec/mongoid/fields_spec.rb +43 -0
- data/spec/mongoid/reloadable_spec.rb +24 -0
- data/spec/mongoid_spec.rb +1 -1
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +8 -0
- data/spec/shared/shlib/server.sh +5 -5
- data/spec/support/models/person.rb +1 -0
- data/spec/support/models/purse.rb +9 -0
- data.tar.gz.sig +0 -0
- metadata +654 -652
- metadata.gz.sig +0 -0
data/spec/mongoid/fields_spec.rb
CHANGED
@@ -567,6 +567,49 @@ describe Mongoid::Fields do
|
|
567
567
|
end
|
568
568
|
end
|
569
569
|
end
|
570
|
+
|
571
|
+
context 'when the field is declared as BSON::Decimal128' do
|
572
|
+
let(:document) { Mop.create!(decimal128_field: BSON::Decimal128.new(Math::PI.to_s)).reload }
|
573
|
+
|
574
|
+
shared_context 'BSON::Decimal128 is BigDecimal' do
|
575
|
+
it 'should return a BigDecimal' do
|
576
|
+
expect(document.decimal128_field).to be_a BigDecimal
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
shared_context 'BSON::Decimal128 is BSON::Decimal128' do
|
581
|
+
it 'should return a BSON::Decimal128' do
|
582
|
+
expect(document.decimal128_field).to be_a BSON::Decimal128
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
it 'is declared as BSON::Decimal128' do
|
587
|
+
expect(Mop.fields['decimal128_field'].type).to be == BSON::Decimal128
|
588
|
+
end
|
589
|
+
|
590
|
+
context 'when BSON version <= 4' do
|
591
|
+
max_bson_version '4.99.99'
|
592
|
+
it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
|
593
|
+
end
|
594
|
+
|
595
|
+
context 'when BSON version >= 5' do
|
596
|
+
min_bson_version '5.0.0'
|
597
|
+
|
598
|
+
context 'when allow_bson5_decimal128 is false' do
|
599
|
+
config_override :allow_bson5_decimal128, false
|
600
|
+
it_behaves_like 'BSON::Decimal128 is BigDecimal'
|
601
|
+
end
|
602
|
+
|
603
|
+
context 'when allow_bson5_decimal128 is true' do
|
604
|
+
config_override :allow_bson5_decimal128, true
|
605
|
+
it_behaves_like 'BSON::Decimal128 is BSON::Decimal128'
|
606
|
+
end
|
607
|
+
|
608
|
+
context 'when allow_bson5_decimal128 is default' do
|
609
|
+
it_behaves_like 'BSON::Decimal128 is BigDecimal'
|
610
|
+
end
|
611
|
+
end
|
612
|
+
end
|
570
613
|
end
|
571
614
|
|
572
615
|
describe "#getter_before_type_cast" do
|
@@ -390,6 +390,30 @@ describe Mongoid::Reloadable do
|
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
+
context 'when embeds_many is modified' do
|
394
|
+
let(:contractor1) { Contractor.new(name: 'b') }
|
395
|
+
let(:contractor2) { Contractor.new(name: 'c') }
|
396
|
+
|
397
|
+
let(:building) do
|
398
|
+
Building.create!(contractors: [ contractor1 ])
|
399
|
+
end
|
400
|
+
|
401
|
+
let(:more_contractors) { building.contractors + [ contractor2 ] }
|
402
|
+
|
403
|
+
let(:modified_building) do
|
404
|
+
building.tap do
|
405
|
+
building.assign_attributes contractors: more_contractors
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
let(:reloaded_building) { modified_building.reload }
|
410
|
+
|
411
|
+
it 'resets delayed_atomic_sets' do
|
412
|
+
expect(modified_building.delayed_atomic_sets).not_to be_empty
|
413
|
+
expect(reloaded_building.delayed_atomic_sets).to be_empty
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
393
417
|
context "when embedded document is nil" do
|
394
418
|
|
395
419
|
let(:palette) do
|
data/spec/mongoid_spec.rb
CHANGED
@@ -52,7 +52,7 @@ describe Mongoid do
|
|
52
52
|
|
53
53
|
it "disconnects from all active clients" do
|
54
54
|
clients.each do |client|
|
55
|
-
expect(client
|
55
|
+
expect(client).to receive(:close).and_call_original
|
56
56
|
end
|
57
57
|
Mongoid.disconnect_clients
|
58
58
|
end
|
@@ -84,22 +84,32 @@ module Mrss
|
|
84
84
|
|
85
85
|
# Locates command stated events for the specified command name,
|
86
86
|
# asserts that there is exactly one such event, and returns it.
|
87
|
-
def single_command_started_event(command_name, include_auth: false)
|
87
|
+
def single_command_started_event(command_name, include_auth: false, database_name: nil)
|
88
88
|
events = if include_auth
|
89
89
|
started_events
|
90
90
|
else
|
91
91
|
non_auth_command_started_events
|
92
92
|
end
|
93
|
-
events
|
94
|
-
|
93
|
+
get_one_event(events, command_name, 'started', database_name: database_name)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Locates command succeeded events for the specified command name,
|
97
|
+
# asserts that there is exactly one such event, and returns it.
|
98
|
+
def single_command_succeeded_event(command_name, database_name: nil)
|
99
|
+
get_one_event(succeeded_events, command_name, 'succeeded', database_name: database_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_one_event(events, command_name, kind, database_name: nil)
|
103
|
+
events = events.select do |event|
|
104
|
+
event.command_name == command_name and
|
105
|
+
database_name.nil? || database_name == event.database_name
|
95
106
|
end
|
96
107
|
if events.length != 1
|
97
|
-
raise "Expected a single #{command_name} event but we have #{events.length}"
|
108
|
+
raise "Expected a single '#{command_name}' #{kind} event#{database_name ? " for '#{database_name}'" : ''} but we have #{events.length}"
|
98
109
|
end
|
99
110
|
events.first
|
100
111
|
end
|
101
112
|
|
102
|
-
|
103
113
|
# Get the first succeeded event published for the name, and then delete it.
|
104
114
|
#
|
105
115
|
# @param [ String ] name The event name.
|
@@ -209,6 +209,14 @@ module Mrss
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
+
def require_no_fallbacks
|
213
|
+
before(:all) do
|
214
|
+
if %w(yes true 1).include?((ENV['TEST_I18N_FALLBACKS'] || '').downcase)
|
215
|
+
skip 'Set TEST_I18N_FALLBACKS=0 environment variable to run these tests'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
212
220
|
# This is a macro for retrying flaky tests on CI that occasionally fail.
|
213
221
|
# Note that the tests will only be retried on CI.
|
214
222
|
#
|
data/spec/shared/shlib/server.sh
CHANGED
@@ -71,12 +71,12 @@ prepare_server_from_url() {
|
|
71
71
|
export PATH="$BINDIR":$PATH
|
72
72
|
}
|
73
73
|
|
74
|
-
|
74
|
+
install_mlaunch_venv() {
|
75
75
|
python3 -V || true
|
76
|
-
if ! python3 -m
|
76
|
+
if ! python3 -m venv -h >/dev/null; then
|
77
77
|
# Current virtualenv fails with
|
78
78
|
# https://github.com/pypa/virtualenv/issues/1630
|
79
|
-
python3 -m pip install
|
79
|
+
python3 -m pip install venv --user
|
80
80
|
fi
|
81
81
|
if test "$USE_SYSTEM_PYTHON_PACKAGES" = 1 &&
|
82
82
|
python3 -m pip list |grep mtools
|
@@ -85,13 +85,13 @@ install_mlaunch_virtualenv() {
|
|
85
85
|
:
|
86
86
|
else
|
87
87
|
venvpath="$MONGO_ORCHESTRATION_HOME"/venv
|
88
|
-
python3 -m
|
88
|
+
python3 -m venv $venvpath
|
89
89
|
. $venvpath/bin/activate
|
90
90
|
# [mlaunch] does not work:
|
91
91
|
# https://github.com/rueckstiess/mtools/issues/856
|
92
92
|
# dateutil dependency is missing in mtools: https://github.com/rueckstiess/mtools/issues/864
|
93
93
|
#pip install 'mtools==1.7' 'pymongo==4.1' python-dateutil psutil
|
94
|
-
|
94
|
+
|
95
95
|
# dateutil dependency is missing in mtools: https://github.com/rueckstiess/mtools/issues/864
|
96
96
|
pip install 'mtools-legacy[mlaunch]' 'pymongo<4' python-dateutil
|
97
97
|
fi
|
@@ -70,6 +70,7 @@ class Person
|
|
70
70
|
embeds_many :messages, validate: false
|
71
71
|
|
72
72
|
embeds_one :passport, autobuild: true, store_as: :pass, validate: false
|
73
|
+
embeds_one :purse, store_as: "Purse"
|
73
74
|
embeds_one :pet, class_name: "Animal", validate: false
|
74
75
|
embeds_one :name, as: :namable, validate: false do
|
75
76
|
def extension
|
data.tar.gz.sig
CHANGED
Binary file
|