mongoid 6.4.0 → 6.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/clients/sessions.rb +2 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +3 -3
- data/lib/mongoid/contextual/memory.rb +4 -4
- data/lib/mongoid/contextual/mongo.rb +3 -3
- data/lib/mongoid/indexable.rb +4 -4
- data/lib/mongoid/persistable.rb +1 -1
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +2 -2
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/relations/embedded/batchable.rb +4 -4
- data/lib/mongoid/relations/embedded/many.rb +23 -0
- data/lib/mongoid/relations/many.rb +2 -2
- data/lib/mongoid/relations/referenced/many.rb +1 -1
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/tasks/database.rb +2 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -0
- data/spec/mongoid/persistable/settable_spec.rb +16 -1
- data/spec/mongoid/relations/embedded/many_spec.rb +246 -16
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f048aa8781f60c32235fe9d3daee1cfa17e7e58
|
4
|
+
data.tar.gz: 1fdca10737525f1272fbcde4273452c9d0ea116c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 191be89fce8a8d7437070a526b68ab6cd9622235d40ac8d01d22dfc477914bc4eec23a28056fde69c2a5651c36a9d2bfea84765d3dbf1f7b6367de941aa73778
|
7
|
+
data.tar.gz: 4e6371d1ae1d2fac3ff3c16d0283ac04132a9d09c83d390e8c3ae714a62ed833897f29d6ff0f2b1de9b6ae90b1019b0ae72d68752584792fbe62536db3a2e54a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -23,7 +23,7 @@ module Mongoid
|
|
23
23
|
#
|
24
24
|
# @since 3.0.0
|
25
25
|
def aggregates(field)
|
26
|
-
result = collection.find.aggregate(pipeline(field), session:
|
26
|
+
result = collection.find.aggregate(pipeline(field), session: _session).to_a
|
27
27
|
if result.empty?
|
28
28
|
{ "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
|
29
29
|
else
|
@@ -166,7 +166,7 @@ module Mongoid
|
|
166
166
|
validate_out!
|
167
167
|
cmd = command
|
168
168
|
opts = { read: cmd.delete(:read).options } if cmd[:read]
|
169
|
-
@map_reduce.database.command(cmd, (opts || {}).merge(session:
|
169
|
+
@map_reduce.database.command(cmd, (opts || {}).merge(session: _session)).first
|
170
170
|
end
|
171
171
|
alias :results :raw
|
172
172
|
|
@@ -250,8 +250,8 @@ module Mongoid
|
|
250
250
|
raise Errors::NoMapReduceOutput.new({}) unless @map_reduce.out
|
251
251
|
end
|
252
252
|
|
253
|
-
def
|
254
|
-
criteria.send(:
|
253
|
+
def _session
|
254
|
+
criteria.send(:_session)
|
255
255
|
end
|
256
256
|
end
|
257
257
|
end
|
@@ -49,7 +49,7 @@ module Mongoid
|
|
49
49
|
unless removed.empty?
|
50
50
|
collection.find(selector).update_one(
|
51
51
|
positionally(selector, "$pullAll" => { path => removed }),
|
52
|
-
session:
|
52
|
+
session: _session
|
53
53
|
)
|
54
54
|
end
|
55
55
|
deleted
|
@@ -304,7 +304,7 @@ module Mongoid
|
|
304
304
|
updates["$set"].merge!(doc.atomic_updates["$set"] || {})
|
305
305
|
doc.move_changes
|
306
306
|
end
|
307
|
-
collection.find(selector).update_one(updates, session:
|
307
|
+
collection.find(selector).update_one(updates, session: _session) unless updates["$set"].empty?
|
308
308
|
end
|
309
309
|
|
310
310
|
# Get the limiting value.
|
@@ -446,8 +446,8 @@ module Mongoid
|
|
446
446
|
doc.destroyed = true
|
447
447
|
end
|
448
448
|
|
449
|
-
def
|
450
|
-
@criteria.send(:
|
449
|
+
def _session
|
450
|
+
@criteria.send(:_session)
|
451
451
|
end
|
452
452
|
end
|
453
453
|
end
|
@@ -341,7 +341,7 @@ module Mongoid
|
|
341
341
|
@criteria, @klass, @cache = criteria, criteria.klass, criteria.options[:cache]
|
342
342
|
@collection = @klass.collection
|
343
343
|
criteria.send(:merge_type_selection)
|
344
|
-
@view = collection.find(criteria.selector, session:
|
344
|
+
@view = collection.find(criteria.selector, session: _session)
|
345
345
|
apply_options
|
346
346
|
end
|
347
347
|
|
@@ -706,8 +706,8 @@ module Mongoid
|
|
706
706
|
documents.push(doc) if cacheable?
|
707
707
|
end
|
708
708
|
|
709
|
-
def
|
710
|
-
@criteria.send(:
|
709
|
+
def _session
|
710
|
+
@criteria.send(:_session)
|
711
711
|
end
|
712
712
|
|
713
713
|
def acknowledged_write?
|
data/lib/mongoid/indexable.rb
CHANGED
@@ -32,10 +32,10 @@ module Mongoid
|
|
32
32
|
key, options = spec.key, spec.options
|
33
33
|
if database = options[:database]
|
34
34
|
with(database: database) do |klass|
|
35
|
-
klass.collection.indexes(session:
|
35
|
+
klass.collection.indexes(session: _session).create_one(key, options.except(:database))
|
36
36
|
end
|
37
37
|
else
|
38
|
-
collection.indexes(session:
|
38
|
+
collection.indexes(session: _session).create_one(key, options)
|
39
39
|
end
|
40
40
|
end and true
|
41
41
|
end
|
@@ -53,9 +53,9 @@ module Mongoid
|
|
53
53
|
indexed_database_names.each do |database|
|
54
54
|
with(database: database) do |klass|
|
55
55
|
begin
|
56
|
-
klass.collection.indexes(session:
|
56
|
+
klass.collection.indexes(session: _session).each do |spec|
|
57
57
|
unless spec["name"] == "_id_"
|
58
|
-
klass.collection.indexes(session:
|
58
|
+
klass.collection.indexes(session: _session).drop_one(spec["key"])
|
59
59
|
logger.info(
|
60
60
|
"MONGOID: Removed index '#{spec["name"]}' on collection " +
|
61
61
|
"'#{klass.collection.name}' in database '#{database}'."
|
data/lib/mongoid/persistable.rb
CHANGED
@@ -204,7 +204,7 @@ module Mongoid
|
|
204
204
|
def persist_atomic_operations(operations)
|
205
205
|
if persisted? && operations
|
206
206
|
selector = atomic_selector
|
207
|
-
_root.collection.find(selector).update_one(positionally(selector, operations), session:
|
207
|
+
_root.collection.find(selector).update_one(positionally(selector, operations), session: _session)
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
@@ -63,7 +63,7 @@ module Mongoid
|
|
63
63
|
selector = _parent.atomic_selector
|
64
64
|
_root.collection.find(selector).update_one(
|
65
65
|
positionally(selector, atomic_inserts),
|
66
|
-
session:
|
66
|
+
session: _session)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -78,7 +78,7 @@ module Mongoid
|
|
78
78
|
#
|
79
79
|
# @since 4.0.0
|
80
80
|
def insert_as_root
|
81
|
-
collection.insert_one(as_attributes, session:
|
81
|
+
collection.insert_one(as_attributes, session: _session)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Post process an insert, which sets the new record attribute to false
|
@@ -64,7 +64,7 @@ module Mongoid
|
|
64
64
|
selector = _parent.atomic_selector
|
65
65
|
_root.collection.find(selector).update_one(
|
66
66
|
positionally(selector, atomic_deletes),
|
67
|
-
session:
|
67
|
+
session: _session)
|
68
68
|
end
|
69
69
|
true
|
70
70
|
end
|
@@ -80,7 +80,7 @@ module Mongoid
|
|
80
80
|
#
|
81
81
|
# @since 4.0.0
|
82
82
|
def delete_as_root
|
83
|
-
collection.find(atomic_selector).delete_one(session:
|
83
|
+
collection.find(atomic_selector).delete_one(session: _session)
|
84
84
|
true
|
85
85
|
end
|
86
86
|
|
@@ -26,7 +26,7 @@ module Mongoid
|
|
26
26
|
field_and_value_hash = hasherizer(field.split('.'), value)
|
27
27
|
field = field_and_value_hash.keys.first.to_s
|
28
28
|
|
29
|
-
if fields[field] && fields[field].type == Hash && attributes.key?(field)
|
29
|
+
if fields[field] && fields[field].type == Hash && attributes.key?(field) && !value.empty?
|
30
30
|
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
31
31
|
value = (attributes[field] || {}).merge(field_and_value_hash[field], &merger)
|
32
32
|
process_attribute(field.to_s, value)
|
@@ -134,9 +134,9 @@ module Mongoid
|
|
134
134
|
unless updates.empty?
|
135
135
|
coll = collection(_root)
|
136
136
|
selector = atomic_selector
|
137
|
-
coll.find(selector).update_one(positionally(selector, updates), session:
|
137
|
+
coll.find(selector).update_one(positionally(selector, updates), session: _session)
|
138
138
|
conflicts.each_pair do |key, value|
|
139
|
-
coll.find(selector).update_one(positionally(selector, { key => value }), session:
|
139
|
+
coll.find(selector).update_one(positionally(selector, { key => value }), session: _session)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
@@ -39,7 +39,7 @@ module Mongoid
|
|
39
39
|
unless docs.empty?
|
40
40
|
collection.find(selector).update_one(
|
41
41
|
positionally(selector, "$unset" => { path => true }),
|
42
|
-
session:
|
42
|
+
session: _session
|
43
43
|
)
|
44
44
|
post_process_batch_remove(docs, :delete)
|
45
45
|
end
|
@@ -60,7 +60,7 @@ module Mongoid
|
|
60
60
|
if !docs.empty?
|
61
61
|
collection.find(selector).update_one(
|
62
62
|
positionally(selector, "$pullAll" => { path => removals }),
|
63
|
-
session:
|
63
|
+
session: _session
|
64
64
|
)
|
65
65
|
post_process_batch_remove(docs, method)
|
66
66
|
end
|
@@ -136,7 +136,7 @@ module Mongoid
|
|
136
136
|
if insertable?
|
137
137
|
collection.find(selector).update_one(
|
138
138
|
positionally(selector, '$set' => { path => inserts }),
|
139
|
-
session:
|
139
|
+
session: _session
|
140
140
|
)
|
141
141
|
post_process_batch_insert(docs)
|
142
142
|
end
|
@@ -161,7 +161,7 @@ module Mongoid
|
|
161
161
|
if insertable?
|
162
162
|
collection.find(selector).update_one(
|
163
163
|
positionally(selector, '$push' => { path => { '$each' => pushes } }),
|
164
|
-
session:
|
164
|
+
session: _session
|
165
165
|
)
|
166
166
|
post_process_batch_insert(docs)
|
167
167
|
end
|
@@ -294,6 +294,29 @@ module Mongoid
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
+
# Shift documents off the relation. This can be a single document or
|
298
|
+
# multiples, and will automatically persist the changes.
|
299
|
+
#
|
300
|
+
# @example Shift a single document.
|
301
|
+
# relation.shift
|
302
|
+
#
|
303
|
+
# @example Shift multiple documents.
|
304
|
+
# relation.shift(3)
|
305
|
+
#
|
306
|
+
# @param [ Integer ] count The number of documents to shift, or 1 if not
|
307
|
+
# provided.
|
308
|
+
#
|
309
|
+
# @return [ Document, Array<Document> ] The shifted document(s).
|
310
|
+
def shift(count = nil)
|
311
|
+
if count
|
312
|
+
if target.size > 0 && docs = target[0, count]
|
313
|
+
docs.each { |doc| delete(doc) }
|
314
|
+
end
|
315
|
+
else
|
316
|
+
delete(target[0])
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
297
320
|
# Substitutes the supplied target documents for the existing documents
|
298
321
|
# in the relation.
|
299
322
|
#
|
@@ -477,7 +477,7 @@ module Mongoid
|
|
477
477
|
# @since 3.0.0
|
478
478
|
def persist_delayed(docs, inserts)
|
479
479
|
unless docs.empty?
|
480
|
-
collection.insert_many(inserts, session:
|
480
|
+
collection.insert_many(inserts, session: _session)
|
481
481
|
docs.each do |doc|
|
482
482
|
doc.new_record = false
|
483
483
|
doc.run_after_callbacks(:create, :save)
|
@@ -31,7 +31,7 @@ module Mongoid
|
|
31
31
|
touches = touch_atomic_updates(field)
|
32
32
|
unless touches["$set"].blank?
|
33
33
|
selector = atomic_selector
|
34
|
-
_root.collection.find(selector).update_one(positionally(selector, touches), session:
|
34
|
+
_root.collection.find(selector).update_one(positionally(selector, touches), session: _session)
|
35
35
|
end
|
36
36
|
run_callbacks(:touch)
|
37
37
|
true
|
data/lib/mongoid/reloadable.rb
CHANGED
@@ -58,7 +58,7 @@ module Mongoid
|
|
58
58
|
#
|
59
59
|
# @since 2.3.2
|
60
60
|
def reload_root_document
|
61
|
-
{}.merge(collection.find({ _id: _id }, session:
|
61
|
+
{}.merge(collection.find({ _id: _id }, session: _session).read(mode: :primary).first || {})
|
62
62
|
end
|
63
63
|
|
64
64
|
# Reload the embedded document.
|
@@ -44,7 +44,7 @@ module Mongoid
|
|
44
44
|
models.each do |model|
|
45
45
|
unless model.embedded?
|
46
46
|
begin
|
47
|
-
model.collection.indexes(session: model.send(:
|
47
|
+
model.collection.indexes(session: model.send(:_session)).each do |index|
|
48
48
|
# ignore default index
|
49
49
|
unless index['name'] == '_id_'
|
50
50
|
key = index['key'].symbolize_keys
|
@@ -77,7 +77,7 @@ module Mongoid
|
|
77
77
|
indexes.each do |index|
|
78
78
|
key = index['key'].symbolize_keys
|
79
79
|
collection = model.collection
|
80
|
-
collection.indexes(session: model.send(:
|
80
|
+
collection.indexes(session: model.send(:_session)).drop_one(key)
|
81
81
|
logger.info(
|
82
82
|
"MONGOID: Removed index '#{index['name']}' on collection " +
|
83
83
|
"'#{collection.name}' in database '#{collection.database.name}'."
|
data/lib/mongoid/version.rb
CHANGED
@@ -11,6 +11,10 @@ development:
|
|
11
11
|
hosts:
|
12
12
|
- localhost:27017
|
13
13
|
options:
|
14
|
+
# Note that all options listed below are Ruby driver client options (the mongo gem).
|
15
|
+
# Please refer to the driver documentation of the version of the mongo gem you are using
|
16
|
+
# for the most up-to-date list of options.
|
17
|
+
#
|
14
18
|
# Change the default write concern. (default = { w: 1 })
|
15
19
|
# write:
|
16
20
|
# w: 1
|
@@ -278,7 +278,22 @@ describe Mongoid::Persistable::Settable do
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
context 'when the field is a
|
281
|
+
context 'when the field is a nested hash' do
|
282
|
+
|
283
|
+
context 'when the field is reset to an empty hash' do
|
284
|
+
|
285
|
+
before do
|
286
|
+
church.set('location' => {})
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'updates the field locally' do
|
290
|
+
expect(church.location).to eq({})
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'updates the field in the database' do
|
294
|
+
expect(church.reload.location).to eq({})
|
295
|
+
end
|
296
|
+
end
|
282
297
|
|
283
298
|
context 'when a leaf value in the nested hash is updated' do
|
284
299
|
|
@@ -2583,6 +2583,25 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2583
2583
|
person.addresses.create(street: "hermannstr")
|
2584
2584
|
end
|
2585
2585
|
|
2586
|
+
context "when the number is zero" do
|
2587
|
+
|
2588
|
+
let!(:popped) do
|
2589
|
+
person.addresses.pop(0)
|
2590
|
+
end
|
2591
|
+
|
2592
|
+
it "returns an empty array" do
|
2593
|
+
expect(popped).to eq([])
|
2594
|
+
end
|
2595
|
+
|
2596
|
+
it "does not remove the document from the relation" do
|
2597
|
+
expect(person.addresses).to eq([ address_one, address_two ])
|
2598
|
+
end
|
2599
|
+
|
2600
|
+
it "does not persist the pop" do
|
2601
|
+
expect(person.reload.addresses).to eq([ address_one, address_two ])
|
2602
|
+
end
|
2603
|
+
end
|
2604
|
+
|
2586
2605
|
context "when the number is not larger than the relation" do
|
2587
2606
|
|
2588
2607
|
let!(:popped) do
|
@@ -2640,6 +2659,125 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2640
2659
|
end
|
2641
2660
|
end
|
2642
2661
|
|
2662
|
+
describe "#shift" do
|
2663
|
+
|
2664
|
+
let(:person) do
|
2665
|
+
Person.create
|
2666
|
+
end
|
2667
|
+
|
2668
|
+
context "when no argument is provided" do
|
2669
|
+
|
2670
|
+
let!(:address_one) do
|
2671
|
+
person.addresses.create(street: "sonnenallee")
|
2672
|
+
end
|
2673
|
+
|
2674
|
+
let!(:address_two) do
|
2675
|
+
person.addresses.create(street: "hermannstr")
|
2676
|
+
end
|
2677
|
+
|
2678
|
+
let!(:shifted) do
|
2679
|
+
person.addresses.shift
|
2680
|
+
end
|
2681
|
+
|
2682
|
+
it "returns the shifted document" do
|
2683
|
+
expect(shifted).to eq(address_one)
|
2684
|
+
end
|
2685
|
+
|
2686
|
+
it "removes the document from the relation" do
|
2687
|
+
expect(person.addresses).to eq([ address_two ])
|
2688
|
+
end
|
2689
|
+
|
2690
|
+
it "persists the shift" do
|
2691
|
+
expect(person.reload.addresses).to eq([ address_two ])
|
2692
|
+
end
|
2693
|
+
end
|
2694
|
+
|
2695
|
+
context "when an integer is provided" do
|
2696
|
+
|
2697
|
+
let!(:address_one) do
|
2698
|
+
person.addresses.create(street: "sonnenallee")
|
2699
|
+
end
|
2700
|
+
|
2701
|
+
let!(:address_two) do
|
2702
|
+
person.addresses.create(street: "hermannstr")
|
2703
|
+
end
|
2704
|
+
|
2705
|
+
context "when the number is zero" do
|
2706
|
+
|
2707
|
+
let!(:shifted) do
|
2708
|
+
person.addresses.shift(0)
|
2709
|
+
end
|
2710
|
+
|
2711
|
+
it "returns an empty array" do
|
2712
|
+
expect(shifted).to eq([])
|
2713
|
+
end
|
2714
|
+
|
2715
|
+
it "does not remove the document from the relation" do
|
2716
|
+
expect(person.addresses).to eq([ address_one, address_two ])
|
2717
|
+
end
|
2718
|
+
|
2719
|
+
it "does not persist the shift" do
|
2720
|
+
expect(person.reload.addresses).to eq([ address_one, address_two ])
|
2721
|
+
end
|
2722
|
+
end
|
2723
|
+
|
2724
|
+
context "when the number is not larger than the relation" do
|
2725
|
+
|
2726
|
+
let!(:shifted) do
|
2727
|
+
person.addresses.shift(2)
|
2728
|
+
end
|
2729
|
+
|
2730
|
+
it "returns the shifted documents" do
|
2731
|
+
expect(shifted).to eq([ address_one, address_two ])
|
2732
|
+
end
|
2733
|
+
|
2734
|
+
it "removes the document from the relation" do
|
2735
|
+
expect(person.addresses).to be_empty
|
2736
|
+
end
|
2737
|
+
|
2738
|
+
it "persists the shift" do
|
2739
|
+
expect(person.reload.addresses).to be_empty
|
2740
|
+
end
|
2741
|
+
end
|
2742
|
+
|
2743
|
+
context "when the number is larger than the relation" do
|
2744
|
+
|
2745
|
+
let!(:shifted) do
|
2746
|
+
person.addresses.shift(4)
|
2747
|
+
end
|
2748
|
+
|
2749
|
+
it "returns the shifted documents" do
|
2750
|
+
expect(shifted).to eq([ address_one, address_two ])
|
2751
|
+
end
|
2752
|
+
|
2753
|
+
it "removes the document from the relation" do
|
2754
|
+
expect(person.addresses).to be_empty
|
2755
|
+
end
|
2756
|
+
|
2757
|
+
it "persists the shift" do
|
2758
|
+
expect(person.reload.addresses).to be_empty
|
2759
|
+
end
|
2760
|
+
end
|
2761
|
+
end
|
2762
|
+
|
2763
|
+
context "when the relation is empty" do
|
2764
|
+
|
2765
|
+
context "when providing no number" do
|
2766
|
+
|
2767
|
+
it "returns nil" do
|
2768
|
+
expect(person.addresses.shift).to be_nil
|
2769
|
+
end
|
2770
|
+
end
|
2771
|
+
|
2772
|
+
context "when providing a number" do
|
2773
|
+
|
2774
|
+
it "returns nil" do
|
2775
|
+
expect(person.addresses.shift(2)).to be_nil
|
2776
|
+
end
|
2777
|
+
end
|
2778
|
+
end
|
2779
|
+
end
|
2780
|
+
|
2643
2781
|
describe "#scoped" do
|
2644
2782
|
|
2645
2783
|
let(:person) do
|
@@ -3846,7 +3984,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3846
3984
|
end
|
3847
3985
|
end
|
3848
3986
|
|
3849
|
-
context "#delete or #clear with before_remove callback" do
|
3987
|
+
context "#delete, or #clear, or #pop, or #shift with before_remove callback" do
|
3850
3988
|
|
3851
3989
|
let(:artist) do
|
3852
3990
|
Artist.new
|
@@ -3892,35 +4030,81 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3892
4030
|
end
|
3893
4031
|
end
|
3894
4032
|
|
3895
|
-
|
4033
|
+
describe "#pop" do
|
3896
4034
|
|
3897
4035
|
before do
|
3898
|
-
|
4036
|
+
artist.songs.pop
|
3899
4037
|
end
|
3900
4038
|
|
3901
|
-
|
4039
|
+
it "executes the callback" do
|
4040
|
+
artist.songs.pop
|
4041
|
+
expect(artist.before_remove_embedded_called).to be true
|
4042
|
+
end
|
4043
|
+
end
|
3902
4044
|
|
3903
|
-
|
3904
|
-
|
3905
|
-
|
3906
|
-
|
4045
|
+
describe "#shift" do
|
4046
|
+
|
4047
|
+
before do
|
4048
|
+
artist.songs.shift
|
3907
4049
|
end
|
3908
4050
|
|
3909
|
-
|
4051
|
+
it "executes the callback" do
|
4052
|
+
artist.songs.shift
|
4053
|
+
expect(artist.before_remove_embedded_called).to be true
|
4054
|
+
end
|
4055
|
+
end
|
4056
|
+
end
|
3910
4057
|
|
3911
|
-
|
3912
|
-
begin; artist.songs.clear; rescue; end
|
3913
|
-
end
|
4058
|
+
context "when errors are raised" do
|
3914
4059
|
|
3915
|
-
|
3916
|
-
|
3917
|
-
|
4060
|
+
before do
|
4061
|
+
expect(artist).to receive(:before_remove_song).and_raise
|
4062
|
+
end
|
4063
|
+
|
4064
|
+
describe "#delete" do
|
4065
|
+
|
4066
|
+
it "does not remove the document from the relation" do
|
4067
|
+
begin; artist.songs.delete(song); rescue; end
|
4068
|
+
expect(artist.songs).to eq([ song ])
|
4069
|
+
end
|
4070
|
+
end
|
4071
|
+
|
4072
|
+
describe "#clear" do
|
4073
|
+
|
4074
|
+
before do
|
4075
|
+
begin; artist.songs.clear; rescue; end
|
4076
|
+
end
|
4077
|
+
|
4078
|
+
it "removes the documents from the relation" do
|
4079
|
+
expect(artist.songs).to eq([ song ])
|
4080
|
+
end
|
4081
|
+
end
|
4082
|
+
|
4083
|
+
describe "#pop" do
|
4084
|
+
|
4085
|
+
before do
|
4086
|
+
begin; artist.songs.pop; rescue; end
|
4087
|
+
end
|
4088
|
+
|
4089
|
+
it "should remove from collection" do
|
4090
|
+
expect(artist.songs).to eq([ song ])
|
4091
|
+
end
|
4092
|
+
end
|
4093
|
+
|
4094
|
+
describe "#shift" do
|
4095
|
+
|
4096
|
+
before do
|
4097
|
+
begin; artist.songs.shift; rescue; end
|
4098
|
+
end
|
4099
|
+
|
4100
|
+
it "should remove from collection" do
|
4101
|
+
expect(artist.songs).to eq([ song ])
|
3918
4102
|
end
|
3919
4103
|
end
|
3920
4104
|
end
|
3921
4105
|
end
|
3922
4106
|
|
3923
|
-
context "#delete or #clear with after_remove callback" do
|
4107
|
+
context "#delete, or #clear, or #pop, or #shift with after_remove callback" do
|
3924
4108
|
|
3925
4109
|
let(:artist) do
|
3926
4110
|
Artist.new
|
@@ -3957,6 +4141,30 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3957
4141
|
expect(artist.after_remove_embedded_called).to be true
|
3958
4142
|
end
|
3959
4143
|
end
|
4144
|
+
|
4145
|
+
describe "#pop" do
|
4146
|
+
|
4147
|
+
before do
|
4148
|
+
artist.labels.pop
|
4149
|
+
end
|
4150
|
+
|
4151
|
+
it "executes the callback" do
|
4152
|
+
artist.labels.pop
|
4153
|
+
expect(artist.after_remove_embedded_called).to be true
|
4154
|
+
end
|
4155
|
+
end
|
4156
|
+
|
4157
|
+
describe "#shift" do
|
4158
|
+
|
4159
|
+
before do
|
4160
|
+
artist.labels.shift
|
4161
|
+
end
|
4162
|
+
|
4163
|
+
it "executes the callback" do
|
4164
|
+
artist.labels.shift
|
4165
|
+
expect(artist.after_remove_embedded_called).to be true
|
4166
|
+
end
|
4167
|
+
end
|
3960
4168
|
end
|
3961
4169
|
|
3962
4170
|
context "when errors are raised" do
|
@@ -3986,6 +4194,28 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3986
4194
|
expect(artist.labels).to be_empty
|
3987
4195
|
end
|
3988
4196
|
end
|
4197
|
+
|
4198
|
+
describe "#pop" do
|
4199
|
+
|
4200
|
+
before do
|
4201
|
+
begin; artist.labels.pop; rescue; end
|
4202
|
+
end
|
4203
|
+
|
4204
|
+
it "should remove from collection" do
|
4205
|
+
expect(artist.labels).to be_empty
|
4206
|
+
end
|
4207
|
+
end
|
4208
|
+
|
4209
|
+
describe "#shift" do
|
4210
|
+
|
4211
|
+
before do
|
4212
|
+
begin; artist.labels.shift; rescue; end
|
4213
|
+
end
|
4214
|
+
|
4215
|
+
it "should remove from collection" do
|
4216
|
+
expect(artist.labels).to be_empty
|
4217
|
+
end
|
4218
|
+
end
|
3989
4219
|
end
|
3990
4220
|
end
|
3991
4221
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.4.
|
4
|
+
version: 6.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
fxN/GvhskJEgmdQToxEBRLOu5/udtPpVe/hb3gk5hzsxcWuKN/VTi4SbtFQdz9cq
|
31
31
|
fqd6ctFDOqcJmOYdlSRgb9g8zm4BiNgFWPBSk8NsP7c=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-03
|
33
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -872,7 +872,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
872
872
|
version: 1.3.6
|
873
873
|
requirements: []
|
874
874
|
rubyforge_project: mongoid
|
875
|
-
rubygems_version: 2.
|
875
|
+
rubygems_version: 2.6.14
|
876
876
|
signing_key:
|
877
877
|
specification_version: 4
|
878
878
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|