mongoid 6.4.2 → 7.0.3
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/README.md +1 -1
- 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 +137 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +19 -19
- 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 +552 -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 +19 -49
- 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 +162 -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 +312 -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 +509 -0
- data/lib/mongoid/{relations.rb → association.rb} +57 -56
- 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 +22 -11
- 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 +7 -5
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +21 -3
- data/lib/mongoid/contextual/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +7 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/options.rb +2 -2
- 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 +37 -7
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +15 -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 +1 -0
- 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 +4 -1
- 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/eq.rb +22 -0
- data/lib/mongoid/matchable/ne.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -1
- data/lib/mongoid/persistable/deletable.rb +7 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +20 -5
- data/lib/mongoid/query_cache.rb +8 -4
- data/lib/mongoid/railtie.rb +17 -0
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/threaded.rb +36 -0
- data/lib/mongoid/touchable.rb +102 -0
- 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/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/minim.rb +7 -0
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/store_as_dup_test3.rb +7 -0
- data/spec/app/models/store_as_dup_test4.rb +7 -0
- data/spec/app/models/updatable.rb +7 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +13 -3
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/lite_spec_helper.rb +56 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +40 -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 +866 -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} +124 -182
- 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 +66 -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} +33 -14
- 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 +2006 -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} +26 -7
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +56 -0
- 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_models.rb +26 -0
- 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/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_models.rb +37 -0
- 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_models.rb +48 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1350 -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_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 +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +24 -18
- data/spec/mongoid/clients/options_spec.rb +58 -44
- data/spec/mongoid/clients/sessions_spec.rb +1 -1
- data/spec/mongoid/clients/transactions_spec.rb +369 -0
- data/spec/mongoid/clients_spec.rb +68 -8
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +33 -5
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -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 +42 -3
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +33 -18
- data/spec/mongoid/document_spec.rb +83 -4
- 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 +23 -0
- 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/eq_spec.rb +48 -0
- 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 +95 -10
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/persistence_context_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +61 -22
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/{relations/touchable_spec.rb → touchable_spec.rb} +40 -1
- 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/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +51 -25
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/spec_config.rb +39 -0
- metadata +602 -582
- checksums.yaml.gz.sig +0 -2
- 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/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/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.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
|
@@ -0,0 +1,908 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Association::Embedded::EmbedsOne do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
class Container; include Mongoid::Document; end
|
|
7
|
+
class EmbeddedObject; include Mongoid::Document; end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
after do
|
|
11
|
+
Container.relations.clear
|
|
12
|
+
EmbeddedObject.relations.clear
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:embeds_one_class) do
|
|
16
|
+
Container
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
let(:name) do
|
|
20
|
+
:embedded_object
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
let(:association) do
|
|
24
|
+
embeds_one_class.embeds_one name, options
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:options) do
|
|
28
|
+
{ }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#relation_complements' do
|
|
32
|
+
|
|
33
|
+
let(:expected_complements) do
|
|
34
|
+
[
|
|
35
|
+
Mongoid::Association::Embedded::EmbeddedIn,
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns the relation complements' do
|
|
40
|
+
expect(association.send(:relation_complements)).to eq(expected_complements)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#setup!' do
|
|
45
|
+
|
|
46
|
+
it 'sets up a getter for the relation' do
|
|
47
|
+
expect(Mongoid::Association::Accessors).to receive(:define_getter!).with(association)
|
|
48
|
+
association.setup!
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'sets up a setter for the relation' do
|
|
52
|
+
expect(Mongoid::Association::Accessors).to receive(:define_setter!).with(association)
|
|
53
|
+
association.setup!
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'sets up an existence check for the relation' do
|
|
57
|
+
expect(Mongoid::Association::Accessors).to receive(:define_existence_check!).with(association)
|
|
58
|
+
association.setup!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'sets up the builder for the relation' do
|
|
62
|
+
expect(Mongoid::Association::Builders).to receive(:define_builder!).with(association)
|
|
63
|
+
association.setup!
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'sets up the creator for the relation' do
|
|
67
|
+
expect(Mongoid::Association::Builders).to receive(:define_creator!).with(association)
|
|
68
|
+
association.setup!
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'when the :validate option is true' do
|
|
72
|
+
|
|
73
|
+
let(:options) do
|
|
74
|
+
{
|
|
75
|
+
validate: true
|
|
76
|
+
}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
let(:association) do
|
|
80
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
81
|
+
# setup! method will be called by the :embeds_one macro
|
|
82
|
+
described_class.new(embeds_one_class, name, options)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'sets up validation' do
|
|
86
|
+
expect(embeds_one_class).to receive(:validates_associated).with(name).and_call_original
|
|
87
|
+
association.setup!
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context 'when the :validate option is false' do
|
|
92
|
+
|
|
93
|
+
let(:options) do
|
|
94
|
+
{
|
|
95
|
+
validate: false
|
|
96
|
+
}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'does not set up validation' do
|
|
100
|
+
expect(embeds_one_class).not_to receive(:validates_associated)
|
|
101
|
+
association.setup!
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'when the :validate option is not provided' do
|
|
106
|
+
|
|
107
|
+
let(:association) do
|
|
108
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
109
|
+
# setup! method will be called by the :embeds_one macro
|
|
110
|
+
described_class.new(embeds_one_class, name, options)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'sets up the validation because it uses the validation default (true)' do
|
|
114
|
+
expect(embeds_one_class).to receive(:validates_associated).with(name).and_call_original
|
|
115
|
+
association.setup!
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe '#type' do
|
|
121
|
+
|
|
122
|
+
context 'when polymorphic' do
|
|
123
|
+
|
|
124
|
+
let(:options) do
|
|
125
|
+
{ as: :containable }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'returns the as attribute followed by "_type"' do
|
|
129
|
+
expect(association.type).to eq("#{options[:as]}_type")
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'when not polymorphic' do
|
|
134
|
+
|
|
135
|
+
it 'returns nil' do
|
|
136
|
+
expect(association.type).to be_nil
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe '#inverse_type' do
|
|
142
|
+
|
|
143
|
+
context 'when polymorphic' do
|
|
144
|
+
|
|
145
|
+
let(:options) do
|
|
146
|
+
{ as: :containable }
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'returns nil' do
|
|
150
|
+
expect(association.inverse_type).to be_nil
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context 'when not polymorphic' do
|
|
155
|
+
|
|
156
|
+
it 'returns nil' do
|
|
157
|
+
expect(association.inverse_type).to be_nil
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe '#inverse_type_setter' do
|
|
163
|
+
|
|
164
|
+
context 'when polymorphic' do
|
|
165
|
+
|
|
166
|
+
let(:options) do
|
|
167
|
+
{ as: :containable }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'returns nil' do
|
|
171
|
+
expect(association.inverse_type).to be_nil
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
context 'when not polymorphic' do
|
|
176
|
+
|
|
177
|
+
it 'returns nil' do
|
|
178
|
+
expect(association.inverse_type).to be_nil
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
describe '#embedded?' do
|
|
184
|
+
|
|
185
|
+
it 'returns true' do
|
|
186
|
+
expect(association.embedded?).to be(true)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
describe '#primary_key' do
|
|
191
|
+
|
|
192
|
+
it 'returns nil' do
|
|
193
|
+
expect(association.primary_key).to be_nil
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
describe '#indexed?' do
|
|
198
|
+
|
|
199
|
+
it 'returns false' do
|
|
200
|
+
expect(association.indexed?).to be(false)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
describe '#relation' do
|
|
205
|
+
|
|
206
|
+
it 'returns Mongoid::Association::Embedded::EmbedsOne::Proxy' do
|
|
207
|
+
expect(association.relation).to be(Mongoid::Association::Embedded::EmbedsOne::Proxy)
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
describe '#validation_default' do
|
|
212
|
+
|
|
213
|
+
it 'returns true' do
|
|
214
|
+
expect(association.validation_default).to be(true)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe '#name' do
|
|
219
|
+
|
|
220
|
+
it 'returns the name of the relation' do
|
|
221
|
+
expect(association.name).to be(name)
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
describe '#options' do
|
|
226
|
+
|
|
227
|
+
it 'returns the options' do
|
|
228
|
+
expect(association.options).to be(options)
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
describe '#cyclic?' do
|
|
233
|
+
|
|
234
|
+
context 'when :cyclic is specified in the options' do
|
|
235
|
+
|
|
236
|
+
let(:options) do
|
|
237
|
+
{ cyclic: true }
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it 'returns true' do
|
|
241
|
+
expect(association.cyclic?).to be(true)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
context 'when :cyclic is not specified in the options' do
|
|
246
|
+
|
|
247
|
+
it 'returns false' do
|
|
248
|
+
expect(association.cyclic?).to be(false)
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
describe '#merge!' do
|
|
254
|
+
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
describe '#store_as' do
|
|
258
|
+
|
|
259
|
+
context 'when :store_as is specified in the options' do
|
|
260
|
+
|
|
261
|
+
let(:options) do
|
|
262
|
+
{
|
|
263
|
+
store_as: :baby_kangaroo
|
|
264
|
+
}
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
it 'returns the :store_as option as a String' do
|
|
268
|
+
expect(association.store_as).to eq(options[:store_as].to_s)
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
context 'when :store_as is not specified in the options' do
|
|
273
|
+
|
|
274
|
+
it 'returns name as a String' do
|
|
275
|
+
expect(association.store_as).to eq(name.to_s)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
describe '#touchable?' do
|
|
281
|
+
|
|
282
|
+
it 'return false' do
|
|
283
|
+
expect(association.send(:touchable?)).to be(false)
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
describe '#order' do
|
|
288
|
+
|
|
289
|
+
it 'returns nil' do
|
|
290
|
+
expect(association.order).to be_nil
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
describe '#as' do
|
|
295
|
+
|
|
296
|
+
context 'when :as is specified in the options' do
|
|
297
|
+
|
|
298
|
+
let(:options) do
|
|
299
|
+
{
|
|
300
|
+
as: :containable
|
|
301
|
+
}
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
it 'returns the :as option' do
|
|
305
|
+
expect(association.as).to eq(options[:as])
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
context 'when :as is not specified in the options' do
|
|
310
|
+
|
|
311
|
+
it 'returns nil' do
|
|
312
|
+
expect(association.as).to be_nil
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
describe '#polymorphic?' do
|
|
318
|
+
|
|
319
|
+
context 'when :as is specified in the options' do
|
|
320
|
+
|
|
321
|
+
let(:options) do
|
|
322
|
+
{
|
|
323
|
+
as: :containable
|
|
324
|
+
}
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it 'returns true' do
|
|
328
|
+
expect(association.polymorphic?).to be(true)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
context 'when :as is not specified in the options' do
|
|
334
|
+
|
|
335
|
+
it 'returns false' do
|
|
336
|
+
expect(association.polymorphic?).to be(false)
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
describe '#type_setter' do
|
|
342
|
+
|
|
343
|
+
context 'when polymorphic' do
|
|
344
|
+
|
|
345
|
+
let(:options) do
|
|
346
|
+
{ as: :containable }
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it 'returns the type followed by = as a String' do
|
|
350
|
+
expect(association.type_setter).to eq("containable_type=")
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
context 'when not polymorphic' do
|
|
355
|
+
|
|
356
|
+
it 'returns nil' do
|
|
357
|
+
expect(association.type).to be_nil
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
describe '#dependent' do
|
|
363
|
+
|
|
364
|
+
it 'returns nil' do
|
|
365
|
+
expect(association.dependent).to be_nil
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
describe '#inverse_type' do
|
|
370
|
+
|
|
371
|
+
it 'returns nil' do
|
|
372
|
+
expect(association.inverse_type).to be_nil
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
describe '#bindable?' do
|
|
377
|
+
|
|
378
|
+
it 'returns false' do
|
|
379
|
+
expect(association.bindable?(Person.new)).to be(false)
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
describe '#inverses' do
|
|
384
|
+
|
|
385
|
+
context 'when polymorphic' do
|
|
386
|
+
|
|
387
|
+
before do
|
|
388
|
+
EmbeddedObject.embedded_in :containable, polymorphic: true
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
let(:options) do
|
|
392
|
+
{
|
|
393
|
+
as: :containable
|
|
394
|
+
}
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
context 'when another object is passed to the method' do
|
|
398
|
+
|
|
399
|
+
let(:instance_of_other_class) do
|
|
400
|
+
EmbeddedObject.new
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
404
|
+
|
|
405
|
+
it 'returns the :as attribute of this association' do
|
|
406
|
+
expect(association.inverses(instance_of_other_class)).to match_array([ :containable ])
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context 'when :inverse_of is specified' do
|
|
411
|
+
|
|
412
|
+
before do
|
|
413
|
+
options.merge!(inverse_of: :inverse_name)
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
it 'returns the :inverse_of value' do
|
|
417
|
+
expect(association.inverses(instance_of_other_class)).to eq([ :inverse_name ])
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
context 'when inverse_of is not specified' do
|
|
422
|
+
|
|
423
|
+
it 'returns the :as attribute of this association' do
|
|
424
|
+
expect(association.inverses(instance_of_other_class)).to match_array([ :containable ])
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
context 'when another object is not passed to the method' do
|
|
430
|
+
|
|
431
|
+
context 'when inverse_of is specified' do
|
|
432
|
+
|
|
433
|
+
before do
|
|
434
|
+
options.merge!(inverse_of: :inverse_name)
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
it 'returns the :inverse_of value' do
|
|
438
|
+
expect(association.inverses).to eq([ :inverse_name ])
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
context 'when inverse_of is not specified' do
|
|
443
|
+
|
|
444
|
+
it 'returns the :as attribute' do
|
|
445
|
+
expect(association.inverses).to eq([ :containable ])
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
context 'when not polymorphic' do
|
|
452
|
+
|
|
453
|
+
before do
|
|
454
|
+
EmbeddedObject.embedded_in :container
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
context 'when inverse_of is specified' do
|
|
458
|
+
|
|
459
|
+
before do
|
|
460
|
+
options.merge!(inverse_of: :inverse_name)
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
it 'returns the :inverse_of value' do
|
|
464
|
+
expect(association.inverses).to eq([ :inverse_name ])
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
context 'when inverse_of is not specified' do
|
|
469
|
+
|
|
470
|
+
it 'uses the inverse class to find the inverse name' do
|
|
471
|
+
expect(association.inverses).to eq([ :container ])
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
context 'when :cyclic is specified' do
|
|
476
|
+
|
|
477
|
+
it 'returns the cyclic inverse name' do
|
|
478
|
+
|
|
479
|
+
end
|
|
480
|
+
end
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
describe '##inverse' do
|
|
485
|
+
|
|
486
|
+
context 'when polymorphic' do
|
|
487
|
+
|
|
488
|
+
before do
|
|
489
|
+
EmbeddedObject.embedded_in :containable, polymorphic: true
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
let(:options) do
|
|
493
|
+
{
|
|
494
|
+
as: :containable
|
|
495
|
+
}
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
context 'when another object is passed to the method' do
|
|
499
|
+
|
|
500
|
+
let(:instance_of_other_class) do
|
|
501
|
+
EmbeddedObject.new
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
505
|
+
|
|
506
|
+
it 'returns the :as attribute of this association' do
|
|
507
|
+
expect(association.inverse(instance_of_other_class)).to eq(:containable)
|
|
508
|
+
end
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
context 'when :inverse_of is specified' do
|
|
512
|
+
|
|
513
|
+
before do
|
|
514
|
+
options.merge!(inverse_of: :inverse_name)
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
it 'returns the :inverse_of value' do
|
|
518
|
+
expect(association.inverse(instance_of_other_class)).to eq(:inverse_name)
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
context 'when inverse_of is not specified' do
|
|
523
|
+
|
|
524
|
+
it 'returns the :as attribute of this association' do
|
|
525
|
+
expect(association.inverse(instance_of_other_class)).to eq(:containable)
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
context 'when another object is not passed to the method' do
|
|
531
|
+
|
|
532
|
+
context 'when inverse_of is specified' do
|
|
533
|
+
|
|
534
|
+
before do
|
|
535
|
+
options.merge!(inverse_of: :inverse_name)
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
it 'returns the :inverse_of value' do
|
|
539
|
+
expect(association.inverse).to eq(:inverse_name)
|
|
540
|
+
end
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
context 'when inverse_of is not specified' do
|
|
544
|
+
|
|
545
|
+
it 'returns the :as attribute' do
|
|
546
|
+
expect(association.inverse).to eq(:containable)
|
|
547
|
+
end
|
|
548
|
+
end
|
|
549
|
+
end
|
|
550
|
+
end
|
|
551
|
+
|
|
552
|
+
context 'when not polymorphic' do
|
|
553
|
+
|
|
554
|
+
before do
|
|
555
|
+
EmbeddedObject.embedded_in :container
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
context 'when inverse_of is specified' do
|
|
559
|
+
|
|
560
|
+
before do
|
|
561
|
+
options.merge!(inverse_of: :inverse_name)
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
it 'returns the :inverse_of value' do
|
|
565
|
+
expect(association.inverse).to eq(:inverse_name)
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
context 'when inverse_of is not specified' do
|
|
570
|
+
|
|
571
|
+
it 'uses the inverse class to find the inverse name' do
|
|
572
|
+
expect(association.inverse).to eq(:container)
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
context 'when :cyclic is specified' do
|
|
577
|
+
|
|
578
|
+
it 'returns the cyclic inverse name' do
|
|
579
|
+
|
|
580
|
+
end
|
|
581
|
+
end
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
describe '#inverse_association' do
|
|
586
|
+
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
describe '#autosave' do
|
|
590
|
+
|
|
591
|
+
it 'returns false' do
|
|
592
|
+
expect(association.autosave).to be(false)
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
describe '#relation_class_name' do
|
|
597
|
+
|
|
598
|
+
context 'when the :class_name option is specified' do
|
|
599
|
+
|
|
600
|
+
let(:options) do
|
|
601
|
+
{ class_name: 'OtherEmbeddedObject' }
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
it 'returns the class name option' do
|
|
605
|
+
expect(association.relation_class_name).to eq('OtherEmbeddedObject')
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
context 'when the class_name option is not specified' do
|
|
610
|
+
|
|
611
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
612
|
+
expect(association.relation_class_name).to eq('EmbeddedObject')
|
|
613
|
+
end
|
|
614
|
+
end
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
describe '#klass' do
|
|
618
|
+
|
|
619
|
+
context 'when the :class_name option is specified' do
|
|
620
|
+
|
|
621
|
+
let!(:_class) do
|
|
622
|
+
class OtherEmbeddedObject; end
|
|
623
|
+
OtherEmbeddedObject
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
let(:options) do
|
|
627
|
+
{ class_name: 'OtherEmbeddedObject' }
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
it 'returns the class name option' do
|
|
631
|
+
expect(association.klass).to eq(_class)
|
|
632
|
+
end
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
context 'when the class_name option is not specified' do
|
|
636
|
+
|
|
637
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
638
|
+
expect(association.klass).to eq(EmbeddedObject)
|
|
639
|
+
end
|
|
640
|
+
end
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
describe '#inverse_class_name' do
|
|
644
|
+
|
|
645
|
+
it 'returns the name of the owner class' do
|
|
646
|
+
expect(association.inverse_class_name).to eq(Container.name)
|
|
647
|
+
end
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
describe '#inverse_class' do
|
|
651
|
+
|
|
652
|
+
it 'returns the owner class' do
|
|
653
|
+
expect(association.inverse_class).to be(Container)
|
|
654
|
+
end
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
describe '#inverse_of' do
|
|
658
|
+
|
|
659
|
+
context 'when :inverse_of is specified in the options' do
|
|
660
|
+
|
|
661
|
+
let(:options) do
|
|
662
|
+
{ inverse_of: :objects_list }
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
it 'returns the inverse_of value' do
|
|
666
|
+
expect(association.inverse_of).to eq(options[:inverse_of])
|
|
667
|
+
end
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
context 'when :inverse_of is not specified in the options' do
|
|
671
|
+
|
|
672
|
+
it 'returns nil' do
|
|
673
|
+
expect(association.inverse_of).to be_nil
|
|
674
|
+
end
|
|
675
|
+
end
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
describe '#key' do
|
|
679
|
+
|
|
680
|
+
it 'returns the name of the relation as a string' do
|
|
681
|
+
expect(association.key).to eq(name.to_s)
|
|
682
|
+
end
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
describe '#setter' do
|
|
686
|
+
|
|
687
|
+
it 'returns a string of the name followed by =' do
|
|
688
|
+
expect(association.setter).to eq("#{name}=")
|
|
689
|
+
end
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
describe '#validate?' do
|
|
693
|
+
|
|
694
|
+
context 'when :validate is specified in the options' do
|
|
695
|
+
|
|
696
|
+
context 'when validate is true' do
|
|
697
|
+
|
|
698
|
+
let(:options) do
|
|
699
|
+
{ validate: true }
|
|
700
|
+
end
|
|
701
|
+
|
|
702
|
+
it 'returns true' do
|
|
703
|
+
expect(association.send(:validate?)).to be(true)
|
|
704
|
+
end
|
|
705
|
+
end
|
|
706
|
+
|
|
707
|
+
context 'when validate is false' do
|
|
708
|
+
|
|
709
|
+
let(:options) do
|
|
710
|
+
{ validate: false }
|
|
711
|
+
end
|
|
712
|
+
|
|
713
|
+
it 'returns false' do
|
|
714
|
+
expect(association.send(:validate?)).to be(false)
|
|
715
|
+
end
|
|
716
|
+
end
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
context 'when :validate is not specified in the options' do
|
|
720
|
+
|
|
721
|
+
it 'returns the validation_default' do
|
|
722
|
+
expect(association.send(:validate?)).to eq(association.validation_default)
|
|
723
|
+
end
|
|
724
|
+
end
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
describe '#autobuilding?' do
|
|
728
|
+
|
|
729
|
+
context 'when :autobuild is specified in the options' do
|
|
730
|
+
|
|
731
|
+
context 'when autobuild is true' do
|
|
732
|
+
|
|
733
|
+
let(:options) do
|
|
734
|
+
{ autobuild: true }
|
|
735
|
+
end
|
|
736
|
+
|
|
737
|
+
it 'returns true' do
|
|
738
|
+
expect(association.autobuilding?).to be(true)
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
context 'when autobuild is false' do
|
|
743
|
+
|
|
744
|
+
let(:options) do
|
|
745
|
+
{ autobuild: false }
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
it 'returns true' do
|
|
749
|
+
expect(association.autobuilding?).to be(false)
|
|
750
|
+
end
|
|
751
|
+
end
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
context 'when :validate is not specified in the options' do
|
|
755
|
+
|
|
756
|
+
it 'returns false' do
|
|
757
|
+
expect(association.autobuilding?).to be(false)
|
|
758
|
+
end
|
|
759
|
+
end
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
describe '#forced_nil_inverse?' do
|
|
763
|
+
|
|
764
|
+
it 'returns false' do
|
|
765
|
+
expect(association.forced_nil_inverse?).to be(false)
|
|
766
|
+
end
|
|
767
|
+
end
|
|
768
|
+
|
|
769
|
+
describe '#stores_foreign_key?' do
|
|
770
|
+
|
|
771
|
+
it 'returns false' do
|
|
772
|
+
expect(association.stores_foreign_key?).to be(false)
|
|
773
|
+
end
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
describe '#inverse_setter' do
|
|
777
|
+
|
|
778
|
+
context 'when an inverse can be determined' do
|
|
779
|
+
|
|
780
|
+
before do
|
|
781
|
+
EmbeddedObject.embedded_in :container
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
it 'returns the name of the inverse followed by =' do
|
|
785
|
+
expect(association.inverse_setter).to eq('container=')
|
|
786
|
+
end
|
|
787
|
+
end
|
|
788
|
+
|
|
789
|
+
context 'when an inverse cannot be determined' do
|
|
790
|
+
|
|
791
|
+
it 'returns nil' do
|
|
792
|
+
expect(association.inverse_setter).to be_nil
|
|
793
|
+
end
|
|
794
|
+
end
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
describe '#extension' do
|
|
798
|
+
|
|
799
|
+
context 'when a block is passed' do
|
|
800
|
+
|
|
801
|
+
let(:association) do
|
|
802
|
+
embeds_one_class.embeds_one name, options do; end
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
it 'defines an extension module' do
|
|
806
|
+
expect(association.extension).to be_a(Module)
|
|
807
|
+
end
|
|
808
|
+
|
|
809
|
+
it 'returns the extension' do
|
|
810
|
+
expect(association.extension).to eq(
|
|
811
|
+
"#{embeds_one_class.name}::#{embeds_one_class.name}#{name.to_s.camelize}RelationExtension".constantize)
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
context 'when an :extension is not specified in the options' do
|
|
816
|
+
|
|
817
|
+
it 'returns false' do
|
|
818
|
+
expect(association.extension).to be_nil
|
|
819
|
+
end
|
|
820
|
+
end
|
|
821
|
+
end
|
|
822
|
+
|
|
823
|
+
describe '#criteria' do
|
|
824
|
+
|
|
825
|
+
it 'does not respond to the method' do
|
|
826
|
+
expect {
|
|
827
|
+
association.criteria
|
|
828
|
+
}.to raise_exception(NoMethodError)
|
|
829
|
+
end
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
describe '#destructive?' do
|
|
833
|
+
|
|
834
|
+
it 'returns false' do
|
|
835
|
+
expect(association.destructive?).to be(false)
|
|
836
|
+
end
|
|
837
|
+
end
|
|
838
|
+
|
|
839
|
+
describe '#nested_builder' do
|
|
840
|
+
|
|
841
|
+
it 'returns an instance of Association::Nested::One' do
|
|
842
|
+
expect(association.nested_builder({}, {})).to be_a(Mongoid::Association::Nested::One)
|
|
843
|
+
end
|
|
844
|
+
end
|
|
845
|
+
|
|
846
|
+
describe '#cascading_callbacks?' do
|
|
847
|
+
|
|
848
|
+
context 'when cascade_callbacks is specified in the options' do
|
|
849
|
+
|
|
850
|
+
context 'when :cascade_callbacks is true' do
|
|
851
|
+
|
|
852
|
+
let(:options) do
|
|
853
|
+
{ cascade_callbacks: true }
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
it 'returns true' do
|
|
857
|
+
expect(association.cascading_callbacks?).to be(true)
|
|
858
|
+
end
|
|
859
|
+
end
|
|
860
|
+
|
|
861
|
+
context 'when :cascade_callbacks is false' do
|
|
862
|
+
|
|
863
|
+
let(:options) do
|
|
864
|
+
{ cascade_callbacks: false }
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
it 'returns false' do
|
|
868
|
+
expect(association.cascading_callbacks?).to be(false)
|
|
869
|
+
end
|
|
870
|
+
end
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
context 'when cascade_callbacks is not specified in the options' do
|
|
874
|
+
|
|
875
|
+
it 'returns false' do
|
|
876
|
+
expect(association.cascading_callbacks?).to be(false)
|
|
877
|
+
end
|
|
878
|
+
end
|
|
879
|
+
end
|
|
880
|
+
|
|
881
|
+
describe '#path' do
|
|
882
|
+
|
|
883
|
+
it 'returns an instance of Mongoid::Atomic::Paths::Root' do
|
|
884
|
+
expect(association.path(double( :_parent => true))).to be_a(Mongoid::Atomic::Paths::Embedded::One)
|
|
885
|
+
end
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
describe '#create_relation' do
|
|
889
|
+
|
|
890
|
+
let(:owner) do
|
|
891
|
+
Container.new
|
|
892
|
+
end
|
|
893
|
+
|
|
894
|
+
let(:target) do
|
|
895
|
+
EmbeddedObject.new
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
before do
|
|
899
|
+
association
|
|
900
|
+
EmbeddedObject.embedded_in :container
|
|
901
|
+
end
|
|
902
|
+
|
|
903
|
+
it 'returns an the target (EmbeddedObject)' do
|
|
904
|
+
expect(Mongoid::Association::Embedded::EmbedsOne::Proxy).to receive(:new).and_call_original
|
|
905
|
+
expect(association.create_relation(owner, target)).to be_a(EmbeddedObject)
|
|
906
|
+
end
|
|
907
|
+
end
|
|
908
|
+
end
|