mongoid 6.4.8 → 7.0.0
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 +0 -26
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +116 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +21 -21
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +20 -50
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +31 -58
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +159 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +415 -0
- data/lib/mongoid/association/touchable.rb +97 -0
- data/lib/mongoid/association.rb +150 -0
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +10 -10
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/sessions.rb +2 -2
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -4
- data/lib/mongoid/contextual/memory.rb +25 -7
- data/lib/mongoid/contextual/mongo.rb +13 -11
- data/lib/mongoid/copyable.rb +6 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +6 -6
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +5 -2
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +0 -1
- data/lib/mongoid/extensions/string.rb +1 -3
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/fields.rb +3 -3
- data/lib/mongoid/indexable.rb +8 -5
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable.rb +0 -3
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +9 -8
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +5 -6
- data/lib/mongoid/persistence_context.rb +1 -5
- data/lib/mongoid/query_cache.rb +19 -64
- data/lib/mongoid/railtie.rb +0 -17
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/tasks/database.rb +2 -2
- data/lib/mongoid/threaded.rb +0 -36
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +1 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +613 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -73
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +14 -12
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +28 -52
- data/spec/mongoid/clients/options_spec.rb +65 -69
- data/spec/mongoid/clients/sessions_spec.rb +4 -13
- data/spec/mongoid/config_spec.rb +24 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +30 -5
- data/spec/mongoid/copyable_spec.rb +34 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +43 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +3 -42
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +0 -81
- data/spec/mongoid/criteria_spec.rb +16 -19
- data/spec/mongoid/document_spec.rb +2 -56
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/extensions/regexp_spec.rb +0 -23
- data/spec/mongoid/extensions/string_spec.rb +7 -35
- data/spec/mongoid/factory_spec.rb +19 -1
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +2 -2
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +18 -8
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable_spec.rb +1 -26
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +1 -35
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/query_cache_spec.rb +16 -99
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +0 -13
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +0 -68
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -14
- data.tar.gz.sig +1 -1
- metadata +192 -207
- metadata.gz.sig +0 -0
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/railties/controller_runtime.rb +0 -86
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/lib/mongoid/relations.rb +0 -148
- data/spec/app/models/array_field.rb +0 -7
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/integration/document_spec.rb +0 -22
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/constraints.rb +0 -101
- data/spec/support/macros.rb +0 -20
- data/spec/support/session_registry.rb +0 -50
- data/spec/support/spec_config.rb +0 -42
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
@@ -0,0 +1,613 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Association::Depending do
|
4
|
+
|
5
|
+
around(:each) do |example|
|
6
|
+
relations_before = Person.relations
|
7
|
+
example.run
|
8
|
+
Person.relations = relations_before
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#apply_delete_dependencies!" do
|
12
|
+
|
13
|
+
let(:band) do
|
14
|
+
Band.new
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when the association exists in the list of dependencies" do
|
18
|
+
|
19
|
+
context "when the association has no dependent strategy" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
band.dependents.push(Band.relations["records"])
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
band.dependents.delete(Band.relations["records"])
|
27
|
+
end
|
28
|
+
|
29
|
+
it "ignores the dependency" do
|
30
|
+
expect(band.apply_delete_dependencies!).to eq([Band.relations["records"]])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".define_dependency!" do
|
37
|
+
|
38
|
+
let(:klass) do
|
39
|
+
Class.new.tap { |c| c.send(:include, Mongoid::Document) }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when the association metadata doesnt exist" do
|
43
|
+
|
44
|
+
before do
|
45
|
+
klass.dependents.push("nothing")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "does not raise an error" do
|
49
|
+
expect {
|
50
|
+
klass.new.apply_delete_dependencies!
|
51
|
+
}.not_to raise_error
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when a dependent option is provided" do
|
56
|
+
|
57
|
+
let!(:association) do
|
58
|
+
klass.has_many :posts, dependent: :destroy
|
59
|
+
end
|
60
|
+
|
61
|
+
after do
|
62
|
+
klass.relations.delete(association.name.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "adds the relation to the dependents" do
|
66
|
+
expect(klass.dependents).to include(klass.relations["posts"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when no dependent option is provided" do
|
71
|
+
|
72
|
+
let!(:association) do
|
73
|
+
klass.has_many :posts
|
74
|
+
end
|
75
|
+
|
76
|
+
after do
|
77
|
+
klass.relations.delete(association.name.to_s)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does not add a relation to the dependents" do
|
81
|
+
expect(klass.dependents).to_not include(association)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when the class is defined more than once' do
|
86
|
+
|
87
|
+
let!(:association) do
|
88
|
+
klass.has_many :posts, dependent: :destroy
|
89
|
+
klass.has_many :posts, dependent: :destroy
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'only creates the dependency once' do
|
93
|
+
expect(klass.dependents.size).to eq(1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
[:delete, :destroy].each do |method|
|
99
|
+
|
100
|
+
describe "##{method}" do
|
101
|
+
|
102
|
+
context "when cascading removals" do
|
103
|
+
|
104
|
+
context "when strategy is delete" do
|
105
|
+
|
106
|
+
let(:person) do
|
107
|
+
Person.create
|
108
|
+
end
|
109
|
+
|
110
|
+
let!(:post) do
|
111
|
+
person.posts.create(title: "Testing")
|
112
|
+
end
|
113
|
+
|
114
|
+
before do
|
115
|
+
person.send(method)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "deletes the associated documents" do
|
119
|
+
expect {
|
120
|
+
Post.find(post.id)
|
121
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when strategy is destroy" do
|
126
|
+
|
127
|
+
let(:person) do
|
128
|
+
Person.create
|
129
|
+
end
|
130
|
+
|
131
|
+
let!(:game) do
|
132
|
+
person.create_game(name: "Pong")
|
133
|
+
end
|
134
|
+
|
135
|
+
before do
|
136
|
+
person.send(method)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "destroys the associated documents" do
|
140
|
+
expect {
|
141
|
+
Game.find(game.id)
|
142
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when strategy is nullify" do
|
147
|
+
|
148
|
+
context "when nullifying a references many" do
|
149
|
+
|
150
|
+
let(:movie) do
|
151
|
+
Movie.create(title: "Bladerunner")
|
152
|
+
end
|
153
|
+
|
154
|
+
let!(:rating) do
|
155
|
+
movie.ratings.create(value: 10)
|
156
|
+
end
|
157
|
+
|
158
|
+
let(:from_db) do
|
159
|
+
Rating.find(rating.id)
|
160
|
+
end
|
161
|
+
|
162
|
+
before do
|
163
|
+
movie.send(method)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "removes the references to the removed document" do
|
167
|
+
expect(from_db.ratable_id).to be_nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when nullifying a references one" do
|
172
|
+
|
173
|
+
context "when the relation exists" do
|
174
|
+
|
175
|
+
let(:book) do
|
176
|
+
Book.create(title: "Neuromancer")
|
177
|
+
end
|
178
|
+
|
179
|
+
let!(:rating) do
|
180
|
+
book.create_rating(value: 10)
|
181
|
+
end
|
182
|
+
|
183
|
+
let(:from_db) do
|
184
|
+
Rating.find(rating.id)
|
185
|
+
end
|
186
|
+
|
187
|
+
before do
|
188
|
+
book.send(method)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "removes the references to the removed document" do
|
192
|
+
expect(from_db.ratable_id).to be_nil
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when the relation is nil" do
|
197
|
+
|
198
|
+
let(:book) do
|
199
|
+
Book.create(title: "Neuromancer")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "returns nil" do
|
203
|
+
expect(book.send(method)).to be true
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "when nullifying a many to many" do
|
209
|
+
|
210
|
+
let(:person) do
|
211
|
+
Person.create
|
212
|
+
end
|
213
|
+
|
214
|
+
let!(:preference) do
|
215
|
+
person.preferences.create(name: "Setting")
|
216
|
+
end
|
217
|
+
|
218
|
+
let(:from_db) do
|
219
|
+
Preference.find(preference.id)
|
220
|
+
end
|
221
|
+
|
222
|
+
before do
|
223
|
+
person.send(method)
|
224
|
+
end
|
225
|
+
|
226
|
+
it "removes the references from the removed document" do
|
227
|
+
expect(person.preference_ids).to_not include(preference.id)
|
228
|
+
end
|
229
|
+
|
230
|
+
it "removes the references to the removed document" do
|
231
|
+
expect(from_db.person_ids).to_not include(person.id)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "when dependent is restrict_with_error" do
|
237
|
+
|
238
|
+
context "when restricting a references many" do
|
239
|
+
|
240
|
+
let!(:association) do
|
241
|
+
Person.has_many :drugs, dependent: :restrict_with_exception
|
242
|
+
end
|
243
|
+
|
244
|
+
after do
|
245
|
+
Person.dependents.delete(association)
|
246
|
+
Person.has_many :drugs, validate: false
|
247
|
+
end
|
248
|
+
|
249
|
+
context "when the relation is empty" do
|
250
|
+
|
251
|
+
let(:person) do
|
252
|
+
Person.new drugs: []
|
253
|
+
end
|
254
|
+
|
255
|
+
it "raises no error" do
|
256
|
+
expect { person.send(method) }.to_not raise_error
|
257
|
+
end
|
258
|
+
|
259
|
+
it "deletes the parent" do
|
260
|
+
person.send(method)
|
261
|
+
expect(person).to be_destroyed
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "when the relation is not empty" do
|
266
|
+
|
267
|
+
let(:person) do
|
268
|
+
Person.new drugs: [Drug.new]
|
269
|
+
end
|
270
|
+
|
271
|
+
it "raises DeleteRestriction error" do
|
272
|
+
expect { person.send(method) }.to raise_error(Mongoid::Errors::DeleteRestriction)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when restricting a references one" do
|
278
|
+
|
279
|
+
let!(:association) do
|
280
|
+
Person.has_one :account, dependent: :restrict_with_exception
|
281
|
+
end
|
282
|
+
|
283
|
+
after do
|
284
|
+
Person.dependents.delete(association)
|
285
|
+
Person.has_one :account, validate: false
|
286
|
+
end
|
287
|
+
|
288
|
+
context "when the relation is empty" do
|
289
|
+
|
290
|
+
let(:person) do
|
291
|
+
Person.new account: nil
|
292
|
+
end
|
293
|
+
|
294
|
+
it "raises no error" do
|
295
|
+
expect { person.send(method) }.to_not raise_error
|
296
|
+
end
|
297
|
+
|
298
|
+
it "deletes the parent" do
|
299
|
+
person.send(method)
|
300
|
+
expect(person).to be_destroyed
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "when the relation is not empty" do
|
305
|
+
|
306
|
+
let(:person) do
|
307
|
+
Person.new account: Account.new(name: 'test')
|
308
|
+
end
|
309
|
+
|
310
|
+
it "raises DeleteRestriction error" do
|
311
|
+
expect { person.send(method) }.to raise_error(Mongoid::Errors::DeleteRestriction)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context "when restricting a many to many" do
|
317
|
+
|
318
|
+
let!(:association) do
|
319
|
+
Person.has_and_belongs_to_many :houses, dependent: :restrict_with_exception
|
320
|
+
end
|
321
|
+
|
322
|
+
after do
|
323
|
+
Person.dependents.delete(association)
|
324
|
+
Person.has_and_belongs_to_many :houses, validate: false
|
325
|
+
end
|
326
|
+
|
327
|
+
context "when the relation is empty" do
|
328
|
+
|
329
|
+
let(:person) do
|
330
|
+
Person.new houses: []
|
331
|
+
end
|
332
|
+
|
333
|
+
it "raises no error" do
|
334
|
+
expect { person.send(method) }.to_not raise_error
|
335
|
+
end
|
336
|
+
|
337
|
+
it "deletes the parent" do
|
338
|
+
person.send(method)
|
339
|
+
expect(person).to be_destroyed
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context "when the relation is not empty" do
|
344
|
+
|
345
|
+
let(:person) do
|
346
|
+
Person.new houses: [House.new]
|
347
|
+
end
|
348
|
+
|
349
|
+
it "raises DeleteRestriction error" do
|
350
|
+
expect { person.send(method) }.to raise_error(Mongoid::Errors::DeleteRestriction)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context 'when the strategy is :delete_all' do
|
360
|
+
|
361
|
+
let(:person) do
|
362
|
+
Person.create
|
363
|
+
end
|
364
|
+
|
365
|
+
context "when cascading a has one" do
|
366
|
+
|
367
|
+
context "when the relation exists" do
|
368
|
+
|
369
|
+
let!(:home) do
|
370
|
+
person.create_home
|
371
|
+
end
|
372
|
+
|
373
|
+
before do
|
374
|
+
person.delete
|
375
|
+
end
|
376
|
+
|
377
|
+
it "deletes the relation" do
|
378
|
+
expect(home).to be_destroyed
|
379
|
+
end
|
380
|
+
|
381
|
+
it "persists the deletion" do
|
382
|
+
expect {
|
383
|
+
home.reload
|
384
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
context "when the relation does not exist" do
|
389
|
+
|
390
|
+
before do
|
391
|
+
person.delete
|
392
|
+
end
|
393
|
+
|
394
|
+
it "deletes the base document" do
|
395
|
+
expect(person).to be_destroyed
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context "when cascading a has many" do
|
401
|
+
|
402
|
+
context "when the relation has documents" do
|
403
|
+
|
404
|
+
let!(:post_one) do
|
405
|
+
person.posts.create(title: "one")
|
406
|
+
end
|
407
|
+
|
408
|
+
let!(:post_two) do
|
409
|
+
person.posts.create(title: "two")
|
410
|
+
end
|
411
|
+
|
412
|
+
context "when the documents are in memory" do
|
413
|
+
|
414
|
+
before do
|
415
|
+
expect(post_one).to receive(:delete).never
|
416
|
+
expect(post_two).to receive(:delete).never
|
417
|
+
person.delete
|
418
|
+
end
|
419
|
+
|
420
|
+
it "deletes the first document" do
|
421
|
+
expect(post_one).to be_destroyed
|
422
|
+
end
|
423
|
+
|
424
|
+
it "deletes the second document" do
|
425
|
+
expect(post_two).to be_destroyed
|
426
|
+
end
|
427
|
+
|
428
|
+
it "unbinds the first document" do
|
429
|
+
expect(post_one.person).to be_nil
|
430
|
+
end
|
431
|
+
|
432
|
+
it "unbinds the second document" do
|
433
|
+
expect(post_two.person).to be_nil
|
434
|
+
end
|
435
|
+
|
436
|
+
it "removes the documents from the relation" do
|
437
|
+
expect(person.posts).to be_empty
|
438
|
+
end
|
439
|
+
|
440
|
+
it "persists the first deletion" do
|
441
|
+
expect {
|
442
|
+
post_one.reload
|
443
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "persists the second deletion" do
|
447
|
+
expect {
|
448
|
+
post_two.reload
|
449
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
context 'when the strategy is :destroy' do
|
457
|
+
|
458
|
+
let!(:association) do
|
459
|
+
Person.has_many :destroyable_posts, class_name: "Post", dependent: :destroy
|
460
|
+
end
|
461
|
+
|
462
|
+
after do
|
463
|
+
Person.dependents.delete(association)
|
464
|
+
end
|
465
|
+
|
466
|
+
let(:person) do
|
467
|
+
Person.new
|
468
|
+
end
|
469
|
+
|
470
|
+
let(:post) do
|
471
|
+
Post.new
|
472
|
+
end
|
473
|
+
|
474
|
+
context "when the documents exist" do
|
475
|
+
|
476
|
+
before do
|
477
|
+
expect(post).to receive(:destroy)
|
478
|
+
person.destroyable_posts << post
|
479
|
+
end
|
480
|
+
|
481
|
+
it "destroys all documents in the relation" do
|
482
|
+
person.delete
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
context "when no documents exist" do
|
487
|
+
|
488
|
+
before do
|
489
|
+
expect(post).to receive(:destroy).never
|
490
|
+
end
|
491
|
+
|
492
|
+
it "it does not destroy the relation" do
|
493
|
+
person.delete
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
context 'when the strategy is :nullify' do
|
499
|
+
|
500
|
+
let!(:association) do
|
501
|
+
Person.has_many :nullifyable_posts, class_name: "Post", dependent: :nullify
|
502
|
+
end
|
503
|
+
|
504
|
+
after do
|
505
|
+
Person.dependents.delete(association)
|
506
|
+
end
|
507
|
+
|
508
|
+
let(:person) do
|
509
|
+
Person.new
|
510
|
+
end
|
511
|
+
|
512
|
+
let(:posts_relation) do
|
513
|
+
person.posts
|
514
|
+
end
|
515
|
+
|
516
|
+
before do
|
517
|
+
allow(person).to receive(:nullifyable_posts).and_return(posts_relation)
|
518
|
+
expect(posts_relation).to receive(:nullify)
|
519
|
+
end
|
520
|
+
|
521
|
+
it "nullifies the relation" do
|
522
|
+
person.delete
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
context 'when the strategy is :restrict_with_exception' do
|
527
|
+
|
528
|
+
let(:person) do
|
529
|
+
Person.new
|
530
|
+
end
|
531
|
+
|
532
|
+
let(:post) do
|
533
|
+
Post.new
|
534
|
+
end
|
535
|
+
|
536
|
+
let!(:association) do
|
537
|
+
Person.has_many :restrictable_posts, class_name: "Post", dependent: :restrict_with_exception
|
538
|
+
end
|
539
|
+
|
540
|
+
after do
|
541
|
+
Person.dependents.delete(association)
|
542
|
+
end
|
543
|
+
|
544
|
+
context 'when there are related objects' do
|
545
|
+
|
546
|
+
before do
|
547
|
+
person.restrictable_posts << post
|
548
|
+
expect(post).to receive(:delete).never
|
549
|
+
expect(post).to receive(:destroy).never
|
550
|
+
end
|
551
|
+
|
552
|
+
it 'raises an exception and leaves the related one intact' do
|
553
|
+
expect { person.delete }.to raise_exception(Mongoid::Errors::DeleteRestriction)
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
context 'when there are no related objects' do
|
558
|
+
|
559
|
+
before do
|
560
|
+
expect(post).to receive(:delete).never
|
561
|
+
expect(post).to receive(:destroy).never
|
562
|
+
end
|
563
|
+
|
564
|
+
it 'deletes the object and leaves the other one intact' do
|
565
|
+
expect(person.delete).to be(true)
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
context 'when the strategy is :restrict_with_error' do
|
571
|
+
|
572
|
+
let(:person) do
|
573
|
+
Person.new
|
574
|
+
end
|
575
|
+
|
576
|
+
let(:post) do
|
577
|
+
Post.new
|
578
|
+
end
|
579
|
+
|
580
|
+
let!(:association) do
|
581
|
+
Person.has_many :restrictable_posts, class_name: "Post", dependent: :restrict_with_error
|
582
|
+
end
|
583
|
+
|
584
|
+
after do
|
585
|
+
Person.dependents.delete(association)
|
586
|
+
end
|
587
|
+
|
588
|
+
context 'when there are related objects' do
|
589
|
+
|
590
|
+
before do
|
591
|
+
person.restrictable_posts << post
|
592
|
+
end
|
593
|
+
|
594
|
+
it 'adds an error to the parent object' do
|
595
|
+
expect(person.delete).to be(false)
|
596
|
+
expect(person.errors[:restrictable_posts].first).to be(
|
597
|
+
Mongoid::Association::Depending::RESTRICT_ERROR_MSG)
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
context 'when there are no related objects' do
|
602
|
+
|
603
|
+
before do
|
604
|
+
expect(post).to receive(:delete).never
|
605
|
+
expect(post).to receive(:destroy).never
|
606
|
+
end
|
607
|
+
|
608
|
+
it 'deletes the object and leaves the other one intact' do
|
609
|
+
expect(person.delete).to be(true)
|
610
|
+
end
|
611
|
+
end
|
612
|
+
end
|
613
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Mongoid::
|
3
|
+
describe Mongoid::Association::EagerLoadable do
|
4
4
|
|
5
5
|
describe ".preload" do
|
6
6
|
|
@@ -122,12 +122,12 @@ describe Mongoid::Relations::Eager do
|
|
122
122
|
Person.all.to_a
|
123
123
|
end
|
124
124
|
|
125
|
-
let(:
|
125
|
+
let(:posts_association) do
|
126
126
|
Person.reflect_on_association(:posts)
|
127
127
|
end
|
128
128
|
|
129
129
|
it "runs the has_many preload" do
|
130
|
-
expect(Mongoid::
|
130
|
+
expect(Mongoid::Association::Referenced::HasMany::Eager).to receive(:new).with([posts_association], docs).once.and_call_original
|
131
131
|
|
132
132
|
context.eager_load(docs)
|
133
133
|
end
|
@@ -154,31 +154,31 @@ describe Mongoid::Relations::Eager do
|
|
154
154
|
Person.all.to_a
|
155
155
|
end
|
156
156
|
|
157
|
-
let(:
|
157
|
+
let(:posts_association) do
|
158
158
|
Person.reflect_on_association(:posts)
|
159
159
|
end
|
160
160
|
|
161
|
-
let(:
|
161
|
+
let(:houses_association) do
|
162
162
|
Person.reflect_on_association(:houses)
|
163
163
|
end
|
164
164
|
|
165
|
-
let(:
|
165
|
+
let(:cat_association) do
|
166
166
|
Person.reflect_on_association(:cat)
|
167
167
|
end
|
168
168
|
|
169
169
|
it "runs the has_many preload" do
|
170
|
-
expect(Mongoid::
|
170
|
+
expect(Mongoid::Association::Referenced::HasMany::Eager).to receive(:new).with([posts_association], docs).once.and_call_original
|
171
171
|
|
172
172
|
context.eager_load(docs)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "runs the has_one preload" do
|
176
|
-
expect(Mongoid::
|
176
|
+
expect(Mongoid::Association::Referenced::HasOne::Eager).to receive(:new).with([cat_association], docs).once.and_call_original
|
177
177
|
context.eager_load(docs)
|
178
178
|
end
|
179
179
|
|
180
180
|
it "runs the has_and_belongs_to_many preload" do
|
181
|
-
expect(Mongoid::
|
181
|
+
expect(Mongoid::Association::Referenced::HasAndBelongsToMany::Eager).to receive(:new).with([houses_association], docs).once.and_call_original
|
182
182
|
context.eager_load(docs)
|
183
183
|
end
|
184
184
|
|
@@ -233,16 +233,16 @@ describe Mongoid::Relations::Eager do
|
|
233
233
|
Person.all.to_a
|
234
234
|
end
|
235
235
|
|
236
|
-
let(:
|
236
|
+
let(:book_association) do
|
237
237
|
Person.reflect_on_association(:book)
|
238
238
|
end
|
239
239
|
|
240
|
-
let(:
|
240
|
+
let(:cat_association) do
|
241
241
|
Person.reflect_on_association(:cat)
|
242
242
|
end
|
243
243
|
|
244
244
|
it "runs the has_one preload" do
|
245
|
-
expect(Mongoid::
|
245
|
+
expect(Mongoid::Association::Referenced::HasOne::Eager).to receive(:new).with([book_association, cat_association], docs).once.and_call_original
|
246
246
|
context.eager_load(docs)
|
247
247
|
end
|
248
248
|
end
|