mongoid 7.2.6 → 7.3.3
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 +16 -0
- data/lib/config/locales/en.yml +2 -2
- data/lib/mongoid/association/accessors.rb +13 -1
- data/lib/mongoid/association/constrainable.rb +1 -1
- data/lib/mongoid/association/depending.rb +4 -4
- data/lib/mongoid/association/embedded/batchable.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -3
- data/lib/mongoid/association/nested/many.rb +1 -1
- data/lib/mongoid/association/nested/one.rb +4 -2
- data/lib/mongoid/association/proxy.rb +6 -1
- data/lib/mongoid/association/referenced/auto_save.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +490 -496
- data/lib/mongoid/association/referenced/has_many/proxy.rb +2 -2
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
- data/lib/mongoid/atomic.rb +26 -2
- data/lib/mongoid/attributes/projector.rb +120 -0
- data/lib/mongoid/attributes.rb +24 -13
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/clients/factory.rb +22 -8
- data/lib/mongoid/clients.rb +1 -1
- data/lib/mongoid/config.rb +19 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +1 -1
- data/lib/mongoid/criteria/findable.rb +1 -1
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
- data/lib/mongoid/criteria/queryable/mergeable.rb +46 -20
- data/lib/mongoid/criteria/queryable/selectable.rb +8 -8
- data/lib/mongoid/criteria.rb +4 -5
- data/lib/mongoid/document.rb +1 -15
- data/lib/mongoid/errors/delete_restriction.rb +8 -9
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +1 -2
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +2 -2
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/fields.rb +43 -5
- data/lib/mongoid/inspectable.rb +1 -1
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/expression.rb +4 -0
- data/lib/mongoid/matcher/field_operator.rb +6 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +7 -0
- data/lib/mongoid/persistable/deletable.rb +1 -2
- data/lib/mongoid/persistable/destroyable.rb +8 -2
- data/lib/mongoid/persistable/updatable.rb +27 -2
- data/lib/mongoid/query_cache.rb +35 -29
- data/lib/mongoid/selectable.rb +5 -7
- data/lib/mongoid/shardable.rb +21 -5
- data/lib/mongoid/touchable.rb +33 -4
- data/lib/mongoid/version.rb +1 -1
- data/spec/integration/associations/embeds_many_spec.rb +44 -0
- data/spec/integration/associations/has_one_spec.rb +48 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -1
- data/spec/integration/document_spec.rb +9 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/in.yml +16 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/lite_spec_helper.rb +2 -0
- data/spec/mongoid/association/depending_spec.rb +391 -352
- data/spec/mongoid/association/nested/one_spec.rb +18 -14
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +245 -93
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +6 -6
- data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
- data/spec/mongoid/atomic/paths_spec.rb +64 -12
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +41 -0
- data/spec/mongoid/attributes_spec.rb +98 -6
- data/spec/mongoid/clients/factory_spec.rb +48 -0
- data/spec/mongoid/config_spec.rb +106 -1
- data/spec/mongoid/contextual/mongo_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
- data/spec/mongoid/criteria_projection_spec.rb +411 -0
- data/spec/mongoid/criteria_spec.rb +0 -275
- data/spec/mongoid/document_spec.rb +13 -13
- data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
- data/spec/mongoid/extensions/false_class_spec.rb +1 -1
- data/spec/mongoid/extensions/string_spec.rb +5 -5
- data/spec/mongoid/extensions/true_class_spec.rb +1 -1
- data/spec/mongoid/fields/localized_spec.rb +4 -4
- data/spec/mongoid/fields_spec.rb +4 -4
- data/spec/mongoid/inspectable_spec.rb +12 -4
- data/spec/mongoid/persistable/deletable_spec.rb +175 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
- data/spec/mongoid/persistable/savable_spec.rb +3 -5
- data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
- data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
- data/spec/mongoid/reloadable_spec.rb +18 -1
- data/spec/mongoid/shardable_spec.rb +44 -0
- data/spec/mongoid/touchable_spec.rb +122 -16
- data/spec/mongoid/touchable_spec_models.rb +54 -0
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/models/bolt.rb +8 -0
- data/spec/support/models/hole.rb +13 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/nut.rb +8 -0
- data/spec/support/models/person.rb +6 -0
- data/spec/support/models/sealer.rb +8 -0
- data/spec/support/models/shirt.rb +12 -0
- data/spec/support/models/spacer.rb +8 -0
- data/spec/support/models/threadlocker.rb +8 -0
- data/spec/support/models/washer.rb +8 -0
- data.tar.gz.sig +0 -0
- metadata +97 -3
- metadata.gz.sig +0 -0
- data/spec/support/cluster_config.rb +0 -158
@@ -124,13 +124,13 @@ describe Mongoid::Document do
|
|
124
124
|
describe "._mongoid_clear_types" do
|
125
125
|
|
126
126
|
context "when changing the discriminator_value" do
|
127
|
-
|
128
|
-
before do
|
127
|
+
|
128
|
+
before do
|
129
129
|
Kangaroo._types
|
130
130
|
Kangaroo.discriminator_value = "dvalue"
|
131
131
|
end
|
132
132
|
|
133
|
-
after do
|
133
|
+
after do
|
134
134
|
Kangaroo.discriminator_value = nil
|
135
135
|
end
|
136
136
|
|
@@ -140,13 +140,13 @@ describe Mongoid::Document do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
context "when changing the discriminator_value in child" do
|
143
|
-
|
144
|
-
before do
|
143
|
+
|
144
|
+
before do
|
145
145
|
Shape._types
|
146
146
|
Circle.discriminator_value = "dvalue"
|
147
147
|
end
|
148
148
|
|
149
|
-
after do
|
149
|
+
after do
|
150
150
|
Circle.discriminator_value = nil
|
151
151
|
end
|
152
152
|
|
@@ -944,7 +944,7 @@ describe Mongoid::Document do
|
|
944
944
|
end
|
945
945
|
|
946
946
|
context "when no embedded documents are present" do
|
947
|
-
context "when using the default discriminator key" do
|
947
|
+
context "when using the default discriminator key" do
|
948
948
|
let(:person) do
|
949
949
|
manager.becomes(Person)
|
950
950
|
end
|
@@ -968,12 +968,12 @@ describe Mongoid::Document do
|
|
968
968
|
end
|
969
969
|
end
|
970
970
|
|
971
|
-
context "when using a custom discriminator key" do
|
972
|
-
before do
|
971
|
+
context "when using a custom discriminator key" do
|
972
|
+
before do
|
973
973
|
Person.discriminator_key = "dkey"
|
974
974
|
end
|
975
975
|
|
976
|
-
after do
|
976
|
+
after do
|
977
977
|
Person.discriminator_key = nil
|
978
978
|
end
|
979
979
|
|
@@ -982,13 +982,13 @@ describe Mongoid::Document do
|
|
982
982
|
end
|
983
983
|
end
|
984
984
|
|
985
|
-
context "when using a custom discriminator key and discriminator value" do
|
986
|
-
before do
|
985
|
+
context "when using a custom discriminator key and discriminator value" do
|
986
|
+
before do
|
987
987
|
Person.discriminator_key = "dkey"
|
988
988
|
Person.discriminator_value = "dvalue"
|
989
989
|
end
|
990
990
|
|
991
|
-
after do
|
991
|
+
after do
|
992
992
|
Person.discriminator_key = nil
|
993
993
|
Person.discriminator_value = nil
|
994
994
|
end
|
@@ -13,7 +13,7 @@ describe Mongoid::Errors::DeleteRestriction do
|
|
13
13
|
|
14
14
|
it "contains the problem in the message" do
|
15
15
|
expect(error.message).to include(
|
16
|
-
"Cannot
|
16
|
+
"Cannot destroy Person because of dependent 'drugs'."
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
@@ -158,16 +158,16 @@ describe Mongoid::Extensions::String do
|
|
158
158
|
Time.now.utc_offset
|
159
159
|
end
|
160
160
|
|
161
|
-
|
162
|
-
expect(utc_offset).not_to eq(Time.zone.now.utc_offset)
|
163
|
-
end
|
164
|
-
|
165
|
-
let(:expected_time) { Time.parse("2010-11-19 00:24:49.123457 +0000").in_time_zone - utc_offset }
|
161
|
+
let(:expected_time) { Time.parse("2010-11-19 00:24:49.123457 +0000") - Time.parse(string).utc_offset }
|
166
162
|
|
167
163
|
let(:mongoized) do
|
168
164
|
string.__mongoize_time__
|
169
165
|
end
|
170
166
|
|
167
|
+
it 'test operates in multiple time zones' do
|
168
|
+
expect(utc_offset).not_to eq(Time.zone.now.utc_offset)
|
169
|
+
end
|
170
|
+
|
171
171
|
it_behaves_like 'mongoizes to Time'
|
172
172
|
it_behaves_like 'maintains precision when mongoized'
|
173
173
|
end
|
@@ -448,7 +448,7 @@ describe Mongoid::Fields::Localized do
|
|
448
448
|
context "when the value is false" do
|
449
449
|
|
450
450
|
let(:field) do
|
451
|
-
described_class.new(:boolean_value, localize: true, type: Boolean)
|
451
|
+
described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
|
452
452
|
end
|
453
453
|
|
454
454
|
let(:value) do
|
@@ -463,7 +463,7 @@ describe Mongoid::Fields::Localized do
|
|
463
463
|
context "when the value is true" do
|
464
464
|
|
465
465
|
let(:field) do
|
466
|
-
described_class.new(:boolean_value, localize: true, type: Boolean)
|
466
|
+
described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
|
467
467
|
end
|
468
468
|
|
469
469
|
let(:value) do
|
@@ -491,7 +491,7 @@ describe Mongoid::Fields::Localized do
|
|
491
491
|
end
|
492
492
|
|
493
493
|
let(:field) do
|
494
|
-
described_class.new(:boolean_value, localize: true, type: Boolean)
|
494
|
+
described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
|
495
495
|
end
|
496
496
|
|
497
497
|
let(:value) do
|
@@ -510,7 +510,7 @@ describe Mongoid::Fields::Localized do
|
|
510
510
|
end
|
511
511
|
|
512
512
|
let(:field) do
|
513
|
-
described_class.new(:boolean_value, localize: true, type: Boolean)
|
513
|
+
described_class.new(:boolean_value, localize: true, type: Mongoid::Boolean)
|
514
514
|
end
|
515
515
|
|
516
516
|
let(:value) do
|
data/spec/mongoid/fields_spec.rb
CHANGED
@@ -322,7 +322,7 @@ describe Mongoid::Fields do
|
|
322
322
|
end
|
323
323
|
|
324
324
|
it "converts to Mongoid::Boolean" do
|
325
|
-
expect(klass.field(:test, type: Boolean).type).to be(Mongoid::Boolean)
|
325
|
+
expect(klass.field(:test, type: Mongoid::Boolean).type).to be(Mongoid::Boolean)
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
@@ -404,7 +404,7 @@ describe Mongoid::Fields do
|
|
404
404
|
context "when the options are all standard" do
|
405
405
|
|
406
406
|
before do
|
407
|
-
Band.field :acceptable, type: Boolean
|
407
|
+
Band.field :acceptable, type: Mongoid::Boolean
|
408
408
|
end
|
409
409
|
|
410
410
|
after do
|
@@ -419,7 +419,7 @@ describe Mongoid::Fields do
|
|
419
419
|
context "when a custom option is provided" do
|
420
420
|
|
421
421
|
before do
|
422
|
-
Band.field :acceptable, type: Boolean, custom: true
|
422
|
+
Band.field :acceptable, type: Mongoid::Boolean, custom: true
|
423
423
|
end
|
424
424
|
|
425
425
|
it "adds the field to the model" do
|
@@ -990,7 +990,7 @@ describe Mongoid::Fields do
|
|
990
990
|
end
|
991
991
|
|
992
992
|
before do
|
993
|
-
Person.field :aliased, as: :alias, type: Boolean, overwrite: true
|
993
|
+
Person.field :aliased, as: :alias, type: Mongoid::Boolean, overwrite: true
|
994
994
|
end
|
995
995
|
|
996
996
|
it "uses the alias to write the attribute" do
|
@@ -33,18 +33,18 @@ describe Mongoid::Inspectable do
|
|
33
33
|
expect(inspected).to include("t(test):")
|
34
34
|
end
|
35
35
|
|
36
|
-
it "displays the default discriminator key" do
|
36
|
+
it "displays the default discriminator key" do
|
37
37
|
expect(inspected).to include(%q,_type: "Person",)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context "when using a custom discriminator key" do
|
42
42
|
|
43
|
-
before do
|
43
|
+
before do
|
44
44
|
Person.discriminator_key = "dkey"
|
45
45
|
end
|
46
46
|
|
47
|
-
after do
|
47
|
+
after do
|
48
48
|
Person.discriminator_key = nil
|
49
49
|
end
|
50
50
|
|
@@ -56,7 +56,7 @@ describe Mongoid::Inspectable do
|
|
56
56
|
person.inspect
|
57
57
|
end
|
58
58
|
|
59
|
-
it "displays the new discriminator key" do
|
59
|
+
it "displays the new discriminator key" do
|
60
60
|
expect(inspected).to include(%q,dkey: "Person",)
|
61
61
|
end
|
62
62
|
end
|
@@ -75,5 +75,13 @@ describe Mongoid::Inspectable do
|
|
75
75
|
expect(inspected).to include(%q,some_attribute: "foo",)
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
context 'when id is unaliased' do
|
80
|
+
let(:shirt) { Shirt.new(id: 1, _id: 2) }
|
81
|
+
|
82
|
+
it 'shows the correct _id and id values' do
|
83
|
+
shirt.inspect.should == "#<Shirt _id: 2, color: nil, id: \"1\">"
|
84
|
+
end
|
85
|
+
end
|
78
86
|
end
|
79
87
|
end
|
@@ -8,7 +8,7 @@ describe Mongoid::Persistable::Deletable do
|
|
8
8
|
describe "#delete" do
|
9
9
|
|
10
10
|
let!(:person) do
|
11
|
-
Person.create
|
11
|
+
Person.create!
|
12
12
|
end
|
13
13
|
|
14
14
|
context "when deleting a readonly document" do
|
@@ -24,6 +24,20 @@ describe Mongoid::Persistable::Deletable do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
context 'when deleting a document that was not saved' do
|
28
|
+
let(:unsaved_person) { Person.new(id: person.id) }
|
29
|
+
|
30
|
+
before do
|
31
|
+
unsaved_person.delete
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'deletes the matching document from the database' do
|
35
|
+
lambda do
|
36
|
+
person.reload
|
37
|
+
end.should raise_error(Mongoid::Errors::DocumentNotFound)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
context "when removing a root document" do
|
28
42
|
|
29
43
|
let!(:deleted) do
|
@@ -259,6 +273,86 @@ describe Mongoid::Persistable::Deletable do
|
|
259
273
|
expect(Browser.count).to eq(1)
|
260
274
|
end
|
261
275
|
end
|
276
|
+
|
277
|
+
context 'when there are dependent documents' do
|
278
|
+
context 'has_one' do
|
279
|
+
|
280
|
+
context 'dependent: :destroy' do
|
281
|
+
let!(:parent) do
|
282
|
+
Hole.create!(bolt: Bolt.create!)
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'does not destroy dependent documents' do
|
286
|
+
Bolt.count.should == 1
|
287
|
+
parent.delete
|
288
|
+
Bolt.count.should == 1
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'dependent: :delete_all' do
|
293
|
+
let!(:parent) do
|
294
|
+
Hole.create!(threadlocker: Threadlocker.create!)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'does not destroy dependent documents' do
|
298
|
+
Threadlocker.count.should == 1
|
299
|
+
parent.delete
|
300
|
+
Threadlocker.count.should == 1
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'dependent: :restrict_with_exception' do
|
305
|
+
let!(:parent) do
|
306
|
+
Hole.create!(sealer: Sealer.create!)
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'does not destroy dependent documents' do
|
310
|
+
Sealer.count.should == 1
|
311
|
+
parent.delete
|
312
|
+
Sealer.count.should == 1
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
context 'has_many' do
|
318
|
+
|
319
|
+
context 'dependent: :destroy' do
|
320
|
+
let!(:parent) do
|
321
|
+
Hole.create!(nuts: [Nut.create!])
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'does not destroy dependent documents' do
|
325
|
+
Nut.count.should == 1
|
326
|
+
parent.delete
|
327
|
+
Nut.count.should == 1
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'dependent: :delete_all' do
|
332
|
+
let!(:parent) do
|
333
|
+
Hole.create!(washers: [Washer.create!])
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'does not destroy dependent documents' do
|
337
|
+
Washer.count.should == 1
|
338
|
+
parent.delete
|
339
|
+
Washer.count.should == 1
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context 'dependent: :restrict_with_exception' do
|
344
|
+
let!(:parent) do
|
345
|
+
Hole.create!(spacers: [Spacer.create!])
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'does not destroy dependent documents' do
|
349
|
+
Spacer.count.should == 1
|
350
|
+
parent.delete
|
351
|
+
Spacer.count.should == 1
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
262
356
|
end
|
263
357
|
|
264
358
|
describe "#delete_all" do
|
@@ -337,5 +431,85 @@ describe Mongoid::Persistable::Deletable do
|
|
337
431
|
end
|
338
432
|
end
|
339
433
|
end
|
434
|
+
|
435
|
+
context 'when there are dependent documents' do
|
436
|
+
context 'has_one' do
|
437
|
+
|
438
|
+
context 'dependent: :destroy' do
|
439
|
+
let!(:parent) do
|
440
|
+
Hole.create!(bolt: Bolt.create!)
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'does not destroy dependent documents' do
|
444
|
+
Bolt.count.should == 1
|
445
|
+
Hole.delete_all
|
446
|
+
Bolt.count.should == 1
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
context 'dependent: :delete_all' do
|
451
|
+
let!(:parent) do
|
452
|
+
Hole.create!(threadlocker: Threadlocker.create!)
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'does not destroy dependent documents' do
|
456
|
+
Threadlocker.count.should == 1
|
457
|
+
Hole.delete_all
|
458
|
+
Threadlocker.count.should == 1
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
context 'dependent: :restrict_with_exception' do
|
463
|
+
let!(:parent) do
|
464
|
+
Hole.create!(sealer: Sealer.create!)
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'does not destroy dependent documents' do
|
468
|
+
Sealer.count.should == 1
|
469
|
+
Hole.delete_all
|
470
|
+
Sealer.count.should == 1
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
context 'has_many' do
|
476
|
+
|
477
|
+
context 'dependent: :destroy' do
|
478
|
+
let!(:parent) do
|
479
|
+
Hole.create!(nuts: [Nut.create!])
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'does not destroy dependent documents' do
|
483
|
+
Nut.count.should == 1
|
484
|
+
Hole.delete_all
|
485
|
+
Nut.count.should == 1
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
context 'dependent: :delete_all' do
|
490
|
+
let!(:parent) do
|
491
|
+
Hole.create!(washers: [Washer.create!])
|
492
|
+
end
|
493
|
+
|
494
|
+
it 'does not destroy dependent documents' do
|
495
|
+
Washer.count.should == 1
|
496
|
+
Hole.delete_all
|
497
|
+
Washer.count.should == 1
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
context 'dependent: :restrict_with_exception' do
|
502
|
+
let!(:parent) do
|
503
|
+
Hole.create!(spacers: [Spacer.create!])
|
504
|
+
end
|
505
|
+
|
506
|
+
it 'does not destroy dependent documents' do
|
507
|
+
Spacer.count.should == 1
|
508
|
+
Hole.delete_all
|
509
|
+
Spacer.count.should == 1
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
340
514
|
end
|
341
515
|
end
|
@@ -8,7 +8,7 @@ describe Mongoid::Persistable::Destroyable do
|
|
8
8
|
describe "#destroy" do
|
9
9
|
|
10
10
|
let!(:person) do
|
11
|
-
Person.create
|
11
|
+
Person.create!
|
12
12
|
end
|
13
13
|
|
14
14
|
context "when destroying a readonly document" do
|
@@ -24,9 +24,23 @@ describe Mongoid::Persistable::Destroyable do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
context 'when destroying a document that was not saved' do
|
28
|
+
let(:unsaved_person) { Person.new(id: person.id) }
|
29
|
+
|
30
|
+
before do
|
31
|
+
unsaved_person.destroy
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'deletes the matching document from the database' do
|
35
|
+
lambda do
|
36
|
+
person.reload
|
37
|
+
end.should raise_error(Mongoid::Errors::DocumentNotFound)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
27
41
|
context "when removing a root document" do
|
28
42
|
|
29
|
-
let!(:
|
43
|
+
let!(:destroyed) do
|
30
44
|
person.destroy
|
31
45
|
end
|
32
46
|
|
@@ -37,7 +51,7 @@ describe Mongoid::Persistable::Destroyable do
|
|
37
51
|
end
|
38
52
|
|
39
53
|
it "returns true" do
|
40
|
-
expect(
|
54
|
+
expect(destroyed).to be true
|
41
55
|
end
|
42
56
|
|
43
57
|
it "resets the flagged for destroy flag" do
|
@@ -145,6 +159,90 @@ describe Mongoid::Persistable::Destroyable do
|
|
145
159
|
end
|
146
160
|
end
|
147
161
|
end
|
162
|
+
|
163
|
+
context 'when there are dependent documents' do
|
164
|
+
context 'has_one' do
|
165
|
+
|
166
|
+
context 'dependent: :destroy' do
|
167
|
+
let!(:parent) do
|
168
|
+
Hole.create!(bolt: Bolt.create!)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'destroys dependent documents' do
|
172
|
+
Bolt.count.should == 1
|
173
|
+
parent.destroy
|
174
|
+
Bolt.count.should == 0
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'dependent: :destroy_all' do
|
179
|
+
let!(:parent) do
|
180
|
+
Hole.create!(threadlocker: Threadlocker.create!)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'deletes dependent documents' do
|
184
|
+
Threadlocker.count.should == 1
|
185
|
+
parent.destroy
|
186
|
+
Threadlocker.count.should == 0
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'dependent: :restrict_with_exception' do
|
191
|
+
let!(:parent) do
|
192
|
+
Hole.create!(sealer: Sealer.create!)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'raises an exception' do
|
196
|
+
Sealer.count.should == 1
|
197
|
+
lambda do
|
198
|
+
parent.destroy
|
199
|
+
end.should raise_error(Mongoid::Errors::DeleteRestriction)
|
200
|
+
Sealer.count.should == 1
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'has_many' do
|
206
|
+
|
207
|
+
context 'dependent: :destroy' do
|
208
|
+
let!(:parent) do
|
209
|
+
Hole.create!(nuts: [Nut.create!])
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'destroys dependent documents' do
|
213
|
+
Nut.count.should == 1
|
214
|
+
parent.destroy
|
215
|
+
Nut.count.should == 0
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context 'dependent: :destroy_all' do
|
220
|
+
let!(:parent) do
|
221
|
+
Hole.create!(washers: [Washer.create!])
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'deletes dependent documents' do
|
225
|
+
Washer.count.should == 1
|
226
|
+
parent.destroy
|
227
|
+
Washer.count.should == 0
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'dependent: :restrict_with_exception' do
|
232
|
+
let!(:parent) do
|
233
|
+
Hole.create!(spacers: [Spacer.create!])
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'raises an exception' do
|
237
|
+
Spacer.count.should == 1
|
238
|
+
lambda do
|
239
|
+
parent.destroy
|
240
|
+
end.should raise_error(Mongoid::Errors::DeleteRestriction)
|
241
|
+
Spacer.count.should == 1
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
148
246
|
end
|
149
247
|
|
150
248
|
describe "#destroy!" do
|
@@ -264,5 +362,95 @@ describe Mongoid::Persistable::Destroyable do
|
|
264
362
|
end
|
265
363
|
end
|
266
364
|
end
|
365
|
+
|
366
|
+
context 'when there are dependent documents' do
|
367
|
+
context 'has_one' do
|
368
|
+
|
369
|
+
context 'dependent: :destroy' do
|
370
|
+
let!(:parent) do
|
371
|
+
Hole.create!.tap do |hole|
|
372
|
+
Bolt.create!(hole: hole)
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'destroys dependent documents' do
|
377
|
+
Bolt.count.should == 1
|
378
|
+
Hole.destroy_all
|
379
|
+
Bolt.count.should == 0
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'dependent: :delete_all' do
|
384
|
+
let!(:parent) do
|
385
|
+
Hole.create!.tap do |hole|
|
386
|
+
Threadlocker.create!(hole: hole)
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'deletes dependent documents' do
|
391
|
+
Threadlocker.count.should == 1
|
392
|
+
Hole.destroy_all
|
393
|
+
Threadlocker.count.should == 0
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'dependent: :restrict_with_exception' do
|
398
|
+
let!(:parent) do
|
399
|
+
Hole.create!.tap do |hole|
|
400
|
+
Sealer.create!(hole: hole)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'raises an exception' do
|
405
|
+
Sealer.count.should == 1
|
406
|
+
lambda do
|
407
|
+
Hole.destroy_all
|
408
|
+
end.should raise_error(Mongoid::Errors::DeleteRestriction)
|
409
|
+
Sealer.count.should == 1
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
context 'has_many' do
|
415
|
+
|
416
|
+
context 'dependent: :destroy' do
|
417
|
+
let!(:parent) do
|
418
|
+
Hole.create!(nuts: [Nut.create!])
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'destroys dependent documents' do
|
422
|
+
Nut.count.should == 1
|
423
|
+
Hole.destroy_all
|
424
|
+
Nut.count.should == 0
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context 'dependent: :delete_all' do
|
429
|
+
let!(:parent) do
|
430
|
+
Hole.create!(washers: [Washer.create!])
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'deletes dependent documents' do
|
434
|
+
Washer.count.should == 1
|
435
|
+
Hole.destroy_all
|
436
|
+
Washer.count.should == 0
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
context 'dependent: :restrict_with_exception' do
|
441
|
+
let!(:parent) do
|
442
|
+
Hole.create!(spacers: [Spacer.create!])
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'raises an exception' do
|
446
|
+
Spacer.count.should == 1
|
447
|
+
lambda do
|
448
|
+
Hole.destroy_all
|
449
|
+
end.should raise_error(Mongoid::Errors::DeleteRestriction)
|
450
|
+
Spacer.count.should == 1
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
267
455
|
end
|
268
456
|
end
|