mongoid 8.0.13 → 8.0.14
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
- data/lib/mongoid/association/referenced/has_many/proxy.rb +4 -2
- data/lib/mongoid/attributes/readonly.rb +19 -1
- data/lib/mongoid/changeable.rb +22 -4
- data/lib/mongoid/contextual/memory.rb +1 -1
- data/lib/mongoid/contextual/none.rb +51 -0
- data/lib/mongoid/criteria/scopable.rb +7 -1
- data/lib/mongoid/criteria.rb +45 -1
- data/lib/mongoid/document.rb +10 -0
- data/lib/mongoid/reloadable.rb +1 -0
- data/lib/mongoid/threaded.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +48 -0
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +83 -0
- data/spec/mongoid/attributes/readonly_dotted_spec.rb +332 -0
- data/spec/mongoid/attributes/readonly_spec.rb +387 -0
- data/spec/mongoid/changeable_spec.rb +18 -0
- data/spec/mongoid/config_spec.rb +7 -0
- data/spec/mongoid/contextual/memory_spec.rb +25 -0
- data/spec/mongoid/contextual/none_spec.rb +18 -0
- data/spec/mongoid/criteria_spec.rb +17 -0
- data/spec/mongoid/findable_spec.rb +14 -0
- data/spec/mongoid/matcher/regexp_budget_spec.rb +6 -0
- data/spec/mongoid/scopable_spec.rb +116 -2
- data/spec/spec_helper.rb +8 -0
- data/spec/support/models/delete_all_account.rb +10 -0
- data/spec/support/models/delete_all_item.rb +9 -0
- data/spec/support/models/delete_all_scoped_item.rb +11 -0
- data/spec/support/models/delete_all_tag.rb +7 -0
- metadata +1862 -1835
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25cd7a90ef28bbf811d80c2f11edb549f48a9b038775b7487dec2a3c10a320a0
|
|
4
|
+
data.tar.gz: 4f3a7ab5cb3f2315d78631e8c8e7bc4007e17ebd26c9cda0fcc4d8bb8572458a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 938ed265403968f8f571b3be0452dcebd51fd855c724023d438217fd2130e449e410e83b0babbe44aa6757aaaa2f01d906fd40fabdea7f6f558375ef2640ef12
|
|
7
|
+
data.tar.gz: b3975411c3e49d8549a9bc5ef145d819f76c563510037245065719c5767871fe1c3419fcba125568917b59d08c01e455655650f6bdf9846d0f2a3cff77ac2a04
|
|
@@ -476,8 +476,10 @@ module Mongoid
|
|
|
476
476
|
#
|
|
477
477
|
# @return [ Integer ] The number of documents deleted.
|
|
478
478
|
def remove_all(conditions = nil, method = :delete_all)
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
# Conjoin the conditions with the association selector so that a
|
|
480
|
+
# key present in both is intersected rather than overwritten. This
|
|
481
|
+
# also leaves the caller's Hash alone.
|
|
482
|
+
selector = criteria.where(conditions || {}).selector
|
|
481
483
|
|
|
482
484
|
# Scanning before the delete means scanning only what is already in
|
|
483
485
|
# memory, so it is only done where there is a pattern whose cost has
|
|
@@ -22,7 +22,25 @@ module Mongoid
|
|
|
22
22
|
# @return [ true | false ] If the document is new, or if the field is not
|
|
23
23
|
# readonly.
|
|
24
24
|
def attribute_writable?(name)
|
|
25
|
-
|
|
25
|
+
return true if new_record?
|
|
26
|
+
|
|
27
|
+
readonly = self.class.readonly_attributes
|
|
28
|
+
return _loaded?(name) if readonly.empty?
|
|
29
|
+
|
|
30
|
+
path = name.to_s
|
|
31
|
+
return false if readonly.include?(path)
|
|
32
|
+
|
|
33
|
+
readonly.each do |field|
|
|
34
|
+
# A readonly attribute that is a declared field with a dotted name
|
|
35
|
+
# is that literal field, not a path prefix.
|
|
36
|
+
next if field.include?('.') && self.class.fields.key?(field)
|
|
37
|
+
|
|
38
|
+
# A path that is a declared field with a dotted name addresses that
|
|
39
|
+
# literal field, not a descendant of the readonly attribute.
|
|
40
|
+
return false if path.start_with?("#{field}.") && !self.class.fields.key?(path)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
_loaded?(name)
|
|
26
44
|
end
|
|
27
45
|
|
|
28
46
|
private
|
data/lib/mongoid/changeable.rb
CHANGED
|
@@ -72,6 +72,7 @@ module Mongoid
|
|
|
72
72
|
@previous_attributes = attributes.dup
|
|
73
73
|
reset_atomic_updates!
|
|
74
74
|
changed_attributes.clear
|
|
75
|
+
@pre_create_changed_attributes = nil
|
|
75
76
|
end
|
|
76
77
|
|
|
77
78
|
# Things that need to execute after a document has been persisted.
|
|
@@ -164,6 +165,13 @@ module Mongoid
|
|
|
164
165
|
def attribute_changed?(attr)
|
|
165
166
|
attr = database_field_name(attr)
|
|
166
167
|
return false unless changed_attributes.key?(attr)
|
|
168
|
+
# An in-place change to a readonly attribute of a persisted document
|
|
169
|
+
# is not part of the dirty tracking API and will not be persisted. A
|
|
170
|
+
# change tracked while the document was new initializes the document,
|
|
171
|
+
# and new documents may set readonly attributes, so it is still
|
|
172
|
+
# reported as a saved change.
|
|
173
|
+
return false if !new_record? && self.class.readonly_attributes.include?(attr) &&
|
|
174
|
+
!@pre_create_changed_attributes&.include?(attr)
|
|
167
175
|
changed_attributes[attr] != attributes[attr]
|
|
168
176
|
end
|
|
169
177
|
|
|
@@ -220,9 +228,16 @@ module Mongoid
|
|
|
220
228
|
#
|
|
221
229
|
# @return [ Object ] The old value.
|
|
222
230
|
def attribute_will_change!(attr)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
return if changed_attributes.key?(attr)
|
|
232
|
+
|
|
233
|
+
# The snapshot is taken for readonly attributes as well. Their changes
|
|
234
|
+
# are hidden from the dirty tracking API (see #attribute_changed?), but
|
|
235
|
+
# the snapshot is needed to reset an in-place change. Changes tracked
|
|
236
|
+
# while the document is new initialize it, and new documents may set
|
|
237
|
+
# readonly attributes, so they are remembered here and still reported
|
|
238
|
+
# when the document is created.
|
|
239
|
+
(@pre_create_changed_attributes ||= ::Set.new).add(attr) if new_record?
|
|
240
|
+
changed_attributes[attr] = read_raw_attribute(attr).__deep_copy__
|
|
226
241
|
end
|
|
227
242
|
|
|
228
243
|
# Set the attribute back to its old value.
|
|
@@ -235,7 +250,10 @@ module Mongoid
|
|
|
235
250
|
# @return [ Object ] The old value.
|
|
236
251
|
def reset_attribute!(attr)
|
|
237
252
|
attr = database_field_name(attr)
|
|
238
|
-
|
|
253
|
+
return unless changed_attributes.key?(attr)
|
|
254
|
+
return if changed_attributes[attr] == attributes[attr]
|
|
255
|
+
|
|
256
|
+
attributes[attr] = changed_attributes.delete(attr)
|
|
239
257
|
end
|
|
240
258
|
|
|
241
259
|
def reset_attribute_to_default!(attr)
|
|
@@ -81,7 +81,7 @@ module Mongoid
|
|
|
81
81
|
# @return [ Array<Object> ] The distinct values for the field.
|
|
82
82
|
def distinct(field)
|
|
83
83
|
if Mongoid.legacy_pluck_distinct
|
|
84
|
-
documents.map{ |doc| doc
|
|
84
|
+
documents.map { |doc| read_field_value(doc, field) }.uniq
|
|
85
85
|
else
|
|
86
86
|
pluck(field).uniq
|
|
87
87
|
end
|
|
@@ -45,6 +45,31 @@ module Mongoid
|
|
|
45
45
|
other.is_a?(None)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Delete all documents in the database that match the selector. There
|
|
49
|
+
# are no documents in the null context, so nothing is deleted.
|
|
50
|
+
#
|
|
51
|
+
# @example Delete all the documents.
|
|
52
|
+
# context.delete
|
|
53
|
+
#
|
|
54
|
+
# @return [ Integer ] Always zero.
|
|
55
|
+
def delete
|
|
56
|
+
0
|
|
57
|
+
end
|
|
58
|
+
alias delete_all delete
|
|
59
|
+
|
|
60
|
+
# Destroy all documents in the database that match the selector. There
|
|
61
|
+
# are no documents in the null context, so nothing is destroyed and no
|
|
62
|
+
# callbacks are run.
|
|
63
|
+
#
|
|
64
|
+
# @example Destroy all the documents.
|
|
65
|
+
# context.destroy
|
|
66
|
+
#
|
|
67
|
+
# @return [ Integer ] Always zero.
|
|
68
|
+
def destroy
|
|
69
|
+
0
|
|
70
|
+
end
|
|
71
|
+
alias destroy_all destroy
|
|
72
|
+
|
|
48
73
|
# Get the distinct field values in null context.
|
|
49
74
|
#
|
|
50
75
|
# @example Get the distinct values in null context.
|
|
@@ -119,6 +144,32 @@ module Mongoid
|
|
|
119
144
|
{}
|
|
120
145
|
end
|
|
121
146
|
|
|
147
|
+
# Update the first matching document atomically. There are no documents
|
|
148
|
+
# in the null context, so nothing is updated.
|
|
149
|
+
#
|
|
150
|
+
# @example Update the matching document.
|
|
151
|
+
# context.update(name: "Smiths")
|
|
152
|
+
#
|
|
153
|
+
# @param [ Hash ] attributes The new attributes for the document.
|
|
154
|
+
#
|
|
155
|
+
# @return [ nil | false ] False if no attributes were provided.
|
|
156
|
+
def update(attributes = nil, _opts = {})
|
|
157
|
+
attributes ? nil : false
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Update all the matching documents atomically. There are no documents
|
|
161
|
+
# in the null context, so nothing is updated.
|
|
162
|
+
#
|
|
163
|
+
# @example Update all the matching documents.
|
|
164
|
+
# context.update_all(name: "Smiths")
|
|
165
|
+
#
|
|
166
|
+
# @param [ Hash ] attributes The new attributes for each document.
|
|
167
|
+
#
|
|
168
|
+
# @return [ nil | false ] False if no attributes were provided.
|
|
169
|
+
def update_all(attributes = nil, _opts = {})
|
|
170
|
+
attributes ? nil : false
|
|
171
|
+
end
|
|
172
|
+
|
|
122
173
|
# Create the new null context.
|
|
123
174
|
#
|
|
124
175
|
# @example Create the new context.
|
|
@@ -11,9 +11,13 @@ module Mongoid
|
|
|
11
11
|
#
|
|
12
12
|
# @return [ Criteria ] The criteria.
|
|
13
13
|
def apply_default_scope
|
|
14
|
+
explicit_none = none_state == true
|
|
14
15
|
klass.without_default_scope do
|
|
15
16
|
merge!(klass.default_scoping.call)
|
|
16
17
|
end
|
|
18
|
+
# A none coming from the default scope is not an explicit none, so it
|
|
19
|
+
# may be removed by unscoping.
|
|
20
|
+
@none = :default if !explicit_none && @none
|
|
17
21
|
self.scoping_options = true, false
|
|
18
22
|
end
|
|
19
23
|
|
|
@@ -98,7 +102,9 @@ module Mongoid
|
|
|
98
102
|
crit = clone
|
|
99
103
|
unless unscoped?
|
|
100
104
|
crit.scoping_options = false, true
|
|
101
|
-
crit.selector.clear
|
|
105
|
+
crit.selector.clear
|
|
106
|
+
crit.options.clear
|
|
107
|
+
crit.send(:clear_default_scope_none)
|
|
102
108
|
end
|
|
103
109
|
crit
|
|
104
110
|
end
|
data/lib/mongoid/criteria.rb
CHANGED
|
@@ -256,6 +256,20 @@ module Mongoid
|
|
|
256
256
|
self.documents = criteria.documents.dup unless criteria.documents.empty?
|
|
257
257
|
self.scoping_options = criteria.scoping_options
|
|
258
258
|
self.inclusions = (inclusions + criteria.inclusions).uniq
|
|
259
|
+
if criteria.empty_and_chainable?
|
|
260
|
+
# An explicit none wins over a none that only came from a default
|
|
261
|
+
# scope. Association proxies forward is_a? to their target, so the
|
|
262
|
+
# runtime class is checked instead; anything that is not a criteria is
|
|
263
|
+
# treated as an explicit none.
|
|
264
|
+
explicit = if Criteria === criteria # rubocop:disable Style/CaseEquality
|
|
265
|
+
criteria.send(:none_state) == true
|
|
266
|
+
else
|
|
267
|
+
true
|
|
268
|
+
end
|
|
269
|
+
@none = true if @none == true || explicit
|
|
270
|
+
@none ||= :default
|
|
271
|
+
@context = nil
|
|
272
|
+
end
|
|
259
273
|
self
|
|
260
274
|
end
|
|
261
275
|
|
|
@@ -267,7 +281,9 @@ module Mongoid
|
|
|
267
281
|
#
|
|
268
282
|
# @return [ Criteria ] The none criteria.
|
|
269
283
|
def none
|
|
270
|
-
@none = true
|
|
284
|
+
@none = true
|
|
285
|
+
@context = nil
|
|
286
|
+
self
|
|
271
287
|
end
|
|
272
288
|
|
|
273
289
|
# Is the criteria an empty but chainable criteria?
|
|
@@ -448,6 +464,34 @@ module Mongoid
|
|
|
448
464
|
|
|
449
465
|
private
|
|
450
466
|
|
|
467
|
+
# The kind of none on this criteria, if any. An explicit none is +true+,
|
|
468
|
+
# a none coming only from the default scope is +:default+, and a criteria
|
|
469
|
+
# that is not none returns +nil+.
|
|
470
|
+
#
|
|
471
|
+
# @api private
|
|
472
|
+
#
|
|
473
|
+
# @example Get the none state.
|
|
474
|
+
# criteria.send(:none_state)
|
|
475
|
+
#
|
|
476
|
+
# @return [ true | :default | nil ] The none state.
|
|
477
|
+
def none_state
|
|
478
|
+
@none
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
# Removes the none flag if it was set only by the default scope. An
|
|
482
|
+
# explicitly requested none is never removed.
|
|
483
|
+
#
|
|
484
|
+
# @api private
|
|
485
|
+
#
|
|
486
|
+
# @example Clear a default scope none.
|
|
487
|
+
# criteria.send(:clear_default_scope_none)
|
|
488
|
+
#
|
|
489
|
+
# @return [ Criteria ] The criteria.
|
|
490
|
+
def clear_default_scope_none
|
|
491
|
+
@none = nil if @none == :default
|
|
492
|
+
self
|
|
493
|
+
end
|
|
494
|
+
|
|
451
495
|
# Are documents in the query missing, and are we configured to raise an
|
|
452
496
|
# error?
|
|
453
497
|
#
|
data/lib/mongoid/document.rb
CHANGED
|
@@ -193,6 +193,12 @@ module Mongoid
|
|
|
193
193
|
new_errors.copy!(errors)
|
|
194
194
|
became.instance_variable_set(:@errors, new_errors)
|
|
195
195
|
became.instance_variable_set(:@new_record, new_record?)
|
|
196
|
+
# The document was constructed as new, collecting pre-create change
|
|
197
|
+
# markers. Drop them when the copied state is that of a persisted
|
|
198
|
+
# document: its pending changes were all tracked after the document
|
|
199
|
+
# was persisted, and stale markers would let in-place changes to
|
|
200
|
+
# readonly attributes bypass the dirty filter.
|
|
201
|
+
became.instance_variable_set(:@pre_create_changed_attributes, nil) unless new_record?
|
|
196
202
|
became.instance_variable_set(:@destroyed, destroyed?)
|
|
197
203
|
became.changed_attributes[klass.discriminator_key] = self.class.discriminator_value
|
|
198
204
|
became[klass.discriminator_key] = klass.discriminator_value
|
|
@@ -203,6 +209,10 @@ module Mongoid
|
|
|
203
209
|
relation = became.__send__(name)
|
|
204
210
|
Array.wrap(relation).each do |r|
|
|
205
211
|
r.instance_variable_set(:@new_record, new_record?)
|
|
212
|
+
# The embedded documents were also constructed as new; drop
|
|
213
|
+
# their pre-create change markers when they are marked as
|
|
214
|
+
# persisted, as is done for the parent document.
|
|
215
|
+
r.instance_variable_set(:@pre_create_changed_attributes, nil) unless new_record?
|
|
206
216
|
end
|
|
207
217
|
end
|
|
208
218
|
end
|
data/lib/mongoid/reloadable.rb
CHANGED
data/lib/mongoid/threaded.rb
CHANGED
data/lib/mongoid/version.rb
CHANGED
|
@@ -3818,4 +3818,52 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
|
3818
3818
|
expect(contract.signature_ids).to eq([signature.id])
|
|
3819
3819
|
end
|
|
3820
3820
|
end
|
|
3821
|
+
|
|
3822
|
+
# Conditions that share a key with the association selector must be
|
|
3823
|
+
# intersected with it, whatever kind of key the caller used.
|
|
3824
|
+
key_variants = {
|
|
3825
|
+
'String' => :stringify_keys,
|
|
3826
|
+
'Symbol' => :symbolize_keys,
|
|
3827
|
+
'indifferent access' => :with_indifferent_access
|
|
3828
|
+
}.freeze
|
|
3829
|
+
|
|
3830
|
+
%i[ delete_all destroy_all ].each do |method|
|
|
3831
|
+
describe "##{method} with conditions on a key the association selector uses" do
|
|
3832
|
+
key_variants.each do |label, converter|
|
|
3833
|
+
context "when the keys are #{label}" do
|
|
3834
|
+
let(:draft) { DeleteAllTag.create!(state: 'draft') }
|
|
3835
|
+
let(:outside) { DeleteAllTag.create!(state: 'draft') }
|
|
3836
|
+
let(:account) { DeleteAllAccount.create!(tags: [ draft, DeleteAllTag.create!(state: 'open') ]) }
|
|
3837
|
+
let(:proxy) { DeleteAllAccount.find(account.id).tags }
|
|
3838
|
+
|
|
3839
|
+
before { outside }
|
|
3840
|
+
|
|
3841
|
+
context 'with a condition on the primary key' do
|
|
3842
|
+
let(:conditions) { { _id: outside.id }.send(converter) }
|
|
3843
|
+
|
|
3844
|
+
it 'deletes nothing outside the association' do
|
|
3845
|
+
expect(proxy.send(method, conditions)).to eq(0)
|
|
3846
|
+
expect(DeleteAllTag.count).to eq(3)
|
|
3847
|
+
end
|
|
3848
|
+
|
|
3849
|
+
it 'does not modify the conditions' do
|
|
3850
|
+
original = conditions.deep_dup
|
|
3851
|
+
proxy.send(method, conditions)
|
|
3852
|
+
expect(conditions).to eq(original)
|
|
3853
|
+
end
|
|
3854
|
+
end
|
|
3855
|
+
|
|
3856
|
+
context 'with a condition on the primary key inside the association' do
|
|
3857
|
+
let(:conditions) { { _id: draft.id }.send(converter) }
|
|
3858
|
+
|
|
3859
|
+
it 'deletes only the matching document' do
|
|
3860
|
+
expect(proxy.send(method, conditions)).to eq(1)
|
|
3861
|
+
expect(DeleteAllTag.pluck(:_id)).not_to include(draft.id)
|
|
3862
|
+
expect(DeleteAllTag.count).to eq(2)
|
|
3863
|
+
end
|
|
3864
|
+
end
|
|
3865
|
+
end
|
|
3866
|
+
end
|
|
3867
|
+
end
|
|
3868
|
+
end
|
|
3821
3869
|
end
|
|
@@ -4291,4 +4291,87 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
4291
4291
|
expect(agent.basic_ids).to eq([basic.id])
|
|
4292
4292
|
end
|
|
4293
4293
|
end
|
|
4294
|
+
|
|
4295
|
+
# Conditions that share a key with the association selector must be
|
|
4296
|
+
# intersected with it, whatever kind of key the caller used.
|
|
4297
|
+
key_variants = {
|
|
4298
|
+
'String' => :stringify_keys,
|
|
4299
|
+
'Symbol' => :symbolize_keys,
|
|
4300
|
+
'indifferent access' => :with_indifferent_access
|
|
4301
|
+
}.freeze
|
|
4302
|
+
|
|
4303
|
+
%i[ delete_all destroy_all ].each do |method|
|
|
4304
|
+
describe "##{method} with conditions on a key the association selector uses" do
|
|
4305
|
+
let(:account) { DeleteAllAccount.create! }
|
|
4306
|
+
let(:other) { DeleteAllAccount.create! }
|
|
4307
|
+
|
|
4308
|
+
key_variants.each do |label, converter|
|
|
4309
|
+
context "when the keys are #{label}" do
|
|
4310
|
+
# rubocop:disable RSpec/MultipleMemoizedHelpers
|
|
4311
|
+
shared_examples 'an intersected bulk delete' do
|
|
4312
|
+
let(:reloaded) { DeleteAllAccount.find(account.id) }
|
|
4313
|
+
let(:proxy) { reloaded.send(association) }
|
|
4314
|
+
let(:conditions) { raw_conditions.send(converter) }
|
|
4315
|
+
let!(:expected) { DeleteAllAccount.find(account.id).send(association).where(raw_conditions).pluck(:_id) }
|
|
4316
|
+
let!(:everything) { klass.pluck(:_id) }
|
|
4317
|
+
|
|
4318
|
+
it 'deletes the same documents as the where chain' do
|
|
4319
|
+
expect(proxy.send(method, conditions)).to eq(expected.size)
|
|
4320
|
+
expect(klass.pluck(:_id)).to match_array(everything - expected)
|
|
4321
|
+
end
|
|
4322
|
+
|
|
4323
|
+
it 'does not modify the conditions' do
|
|
4324
|
+
original = conditions.deep_dup
|
|
4325
|
+
proxy.send(method, conditions)
|
|
4326
|
+
expect(conditions).to eq(original)
|
|
4327
|
+
end
|
|
4328
|
+
end
|
|
4329
|
+
# rubocop:enable RSpec/MultipleMemoizedHelpers
|
|
4330
|
+
|
|
4331
|
+
context 'with an association scope' do
|
|
4332
|
+
let(:klass) { DeleteAllItem }
|
|
4333
|
+
let(:association) { :items }
|
|
4334
|
+
let(:raw_conditions) { { state: 'draft' } }
|
|
4335
|
+
|
|
4336
|
+
before do
|
|
4337
|
+
2.times { DeleteAllItem.create!(account: account, state: 'open') }
|
|
4338
|
+
DeleteAllItem.create!(account: account, state: 'draft')
|
|
4339
|
+
DeleteAllItem.create!(account: other, state: 'draft')
|
|
4340
|
+
DeleteAllItem.create!(account: account, state: 'closed')
|
|
4341
|
+
end
|
|
4342
|
+
|
|
4343
|
+
it_behaves_like 'an intersected bulk delete'
|
|
4344
|
+
end
|
|
4345
|
+
|
|
4346
|
+
context 'with a child default scope' do
|
|
4347
|
+
let(:klass) { DeleteAllScopedItem }
|
|
4348
|
+
let(:association) { :scoped_items }
|
|
4349
|
+
let(:raw_conditions) { { state: 'draft' } }
|
|
4350
|
+
|
|
4351
|
+
before do
|
|
4352
|
+
2.times { DeleteAllScopedItem.create!(account: account, state: 'open') }
|
|
4353
|
+
DeleteAllScopedItem.create!(account: account, state: 'draft')
|
|
4354
|
+
DeleteAllScopedItem.create!(account: other, state: 'draft')
|
|
4355
|
+
DeleteAllScopedItem.collection.insert_one(account_id: account.id, state: 'closed')
|
|
4356
|
+
end
|
|
4357
|
+
|
|
4358
|
+
it_behaves_like 'an intersected bulk delete'
|
|
4359
|
+
end
|
|
4360
|
+
|
|
4361
|
+
context 'with a condition on the foreign key' do
|
|
4362
|
+
let(:klass) { DeleteAllItem }
|
|
4363
|
+
let(:association) { :items }
|
|
4364
|
+
let(:raw_conditions) { { account_id: other.id } }
|
|
4365
|
+
|
|
4366
|
+
before do
|
|
4367
|
+
2.times { DeleteAllItem.create!(account: account, state: 'open') }
|
|
4368
|
+
DeleteAllItem.create!(account: other, state: 'open')
|
|
4369
|
+
end
|
|
4370
|
+
|
|
4371
|
+
it_behaves_like 'an intersected bulk delete'
|
|
4372
|
+
end
|
|
4373
|
+
end
|
|
4374
|
+
end
|
|
4375
|
+
end
|
|
4376
|
+
end
|
|
4294
4377
|
end
|