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,843 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Association::Embedded::EmbeddedIn 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
|
+
Object.send(:remove_const, :Container)
|
|
12
|
+
Object.send(:remove_const, :EmbeddedObject)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:embedded_class) do
|
|
16
|
+
EmbeddedObject
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
let(:name) do
|
|
20
|
+
:container
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
let(:association) do
|
|
24
|
+
embedded_class.embedded_in name, options
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:options) do
|
|
28
|
+
{ }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#VALID_OPTIONS' do
|
|
32
|
+
|
|
33
|
+
it 'returns the SHARED options with the ASSOCIATION_OPTIONS' do
|
|
34
|
+
expect(association.class::VALID_OPTIONS).to match_array(Mongoid::Association::Relatable::SHARED_OPTIONS +
|
|
35
|
+
association.class::ASSOCIATION_OPTIONS)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#relation_complements' do
|
|
40
|
+
|
|
41
|
+
let(:expected_complements) do
|
|
42
|
+
[
|
|
43
|
+
Mongoid::Association::Embedded::EmbedsMany,
|
|
44
|
+
Mongoid::Association::Embedded::EmbedsOne
|
|
45
|
+
]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'returns the relation complements' do
|
|
49
|
+
expect(association.send(:relation_complements)).to eq(expected_complements)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#setup_instance_methods!' do
|
|
54
|
+
|
|
55
|
+
it 'sets up a getter for the relation' do
|
|
56
|
+
expect(Mongoid::Association::Accessors).to receive(:define_getter!).with(association)
|
|
57
|
+
association.send(:setup_instance_methods!)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'sets up a setter for the relation' do
|
|
61
|
+
expect(Mongoid::Association::Accessors).to receive(:define_setter!).with(association)
|
|
62
|
+
association.send(:setup_instance_methods!)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'sets up an existence check for the relation' do
|
|
66
|
+
expect(Mongoid::Association::Accessors).to receive(:define_existence_check!).with(association)
|
|
67
|
+
association.send(:setup_instance_methods!)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#inverse_type_setter' do
|
|
72
|
+
|
|
73
|
+
context 'when polymorphic' do
|
|
74
|
+
|
|
75
|
+
let(:options) do
|
|
76
|
+
{ polymorphic: true }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'returns nil' do
|
|
80
|
+
expect(association.inverse_type).to be_nil
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context 'when not polymorphic' do
|
|
85
|
+
|
|
86
|
+
it 'returns nil' do
|
|
87
|
+
expect(association.inverse_type).to be_nil
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
describe '#embedded?' do
|
|
93
|
+
|
|
94
|
+
it 'returns true' do
|
|
95
|
+
expect(association.embedded?).to be(true)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe '#relation' do
|
|
100
|
+
|
|
101
|
+
it 'returns Mongoid::Association::Embedded::EmbeddedIn::Proxy' do
|
|
102
|
+
expect(association.relation).to be(Mongoid::Association::Embedded::EmbeddedIn::Proxy)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
describe '#validation_default' do
|
|
107
|
+
|
|
108
|
+
it 'returns false' do
|
|
109
|
+
expect(association.validation_default).to be(false)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe '#name' do
|
|
114
|
+
|
|
115
|
+
it 'returns the name of the relation' do
|
|
116
|
+
expect(association.name).to be(name)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe '#options' do
|
|
121
|
+
|
|
122
|
+
it 'returns the options' do
|
|
123
|
+
expect(association.options).to be(options)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe '#cyclic?' do
|
|
128
|
+
|
|
129
|
+
context 'when :cyclic is specified in the options' do
|
|
130
|
+
|
|
131
|
+
let(:options) do
|
|
132
|
+
{ cyclic: true }
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'returns true' do
|
|
136
|
+
expect(association.cyclic?).to be(true)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
context 'when :cyclic is not specified in the options' do
|
|
141
|
+
|
|
142
|
+
it 'returns false' do
|
|
143
|
+
expect(association.cyclic?).to be(false)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
describe '#merge!' do
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
describe '#touchable?' do
|
|
154
|
+
|
|
155
|
+
context 'when :touch is in the options' do
|
|
156
|
+
|
|
157
|
+
let(:options) do
|
|
158
|
+
{ touch: true}
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'returns true' do
|
|
162
|
+
expect(association.send(:touchable?)).to be(true)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context 'when :touch is not in the options' do
|
|
167
|
+
|
|
168
|
+
it 'return false' do
|
|
169
|
+
expect(association.send(:touchable?)).to be(false)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe '#polymorphic?' do
|
|
175
|
+
|
|
176
|
+
context 'when :polymorphic is specified in the options as true' do
|
|
177
|
+
|
|
178
|
+
let(:options) do
|
|
179
|
+
{ polymorphic: true }
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it 'returns true' do
|
|
183
|
+
expect(association.polymorphic?).to be(true)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
context 'when :polymorphic is specified in the options as false' do
|
|
188
|
+
|
|
189
|
+
let(:options) do
|
|
190
|
+
{ polymorphic: false }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'returns false' do
|
|
194
|
+
expect(association.polymorphic?).to be(false)
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
context 'when :polymorphic is not specified in the options' do
|
|
199
|
+
|
|
200
|
+
it 'returns false' do
|
|
201
|
+
expect(association.polymorphic?).to be(false)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe '#bindable?' do
|
|
207
|
+
|
|
208
|
+
it 'returns false' do
|
|
209
|
+
expect(association.bindable?(Person.new)).to be(false)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
describe '#inverses' do
|
|
214
|
+
|
|
215
|
+
context 'when polymorphic' do
|
|
216
|
+
|
|
217
|
+
let(:options) do
|
|
218
|
+
{
|
|
219
|
+
polymorphic: true
|
|
220
|
+
}
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
let(:name) do
|
|
224
|
+
:containable
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
context 'when another object is passed to the method' do
|
|
228
|
+
|
|
229
|
+
let(:instance_of_other_class) do
|
|
230
|
+
Container.new
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
234
|
+
|
|
235
|
+
before do
|
|
236
|
+
Container.embeds_many :embedded_objects, as: :containable
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
context 'when :inverse_of is specified' do
|
|
240
|
+
|
|
241
|
+
before do
|
|
242
|
+
options.merge!(inverse_of: :inverse_name)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'returns the :inverse_of value' do
|
|
246
|
+
expect(association.inverses(instance_of_other_class)).to eq([ :inverse_name ])
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
context 'when inverse_of is not specified' do
|
|
251
|
+
|
|
252
|
+
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
253
|
+
expect(association.inverses(instance_of_other_class)).to match_array([ :embedded_objects ])
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
context 'when the relation class has two associations with the same name' do
|
|
257
|
+
|
|
258
|
+
before do
|
|
259
|
+
Container.embeds_many :embedded_objects, as: :containable
|
|
260
|
+
Container.embeds_many :other_embedded_objects, as: :containable
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it 'returns only the relations whose :as attribute and class match' do
|
|
264
|
+
expect(association.inverses(instance_of_other_class)).to match_array([ :embedded_objects ])
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
context 'when the relation class has more than one relation whose class matches the owning class' do
|
|
271
|
+
|
|
272
|
+
before do
|
|
273
|
+
Container.embeds_many :embedded_objects, as: :containable
|
|
274
|
+
Container.embeds_one :other_embedded_object, as: :containable, class_name: 'EmbeddedObject'
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
context 'when :inverse_of is specified' do
|
|
278
|
+
|
|
279
|
+
before do
|
|
280
|
+
options.merge!(inverse_of: :inverse_name)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
it 'returns the :inverse_of value' do
|
|
284
|
+
expect(association.inverses(instance_of_other_class)).to eq([ :inverse_name ])
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
context 'when inverse_of is not specified' do
|
|
289
|
+
|
|
290
|
+
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
291
|
+
expect(association.inverses(instance_of_other_class)).to match_array([ :embedded_objects,
|
|
292
|
+
:other_embedded_object ])
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
context 'when another object is not passed to the method' do
|
|
299
|
+
|
|
300
|
+
context 'when inverse_of is specified' do
|
|
301
|
+
|
|
302
|
+
before do
|
|
303
|
+
options.merge!(inverse_of: :inverse_name)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
it 'returns the :inverse_of value' do
|
|
307
|
+
expect(association.inverses).to eq([ :inverse_name ])
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
context 'when inverse_of is not specified' do
|
|
312
|
+
|
|
313
|
+
it 'returns nil' do
|
|
314
|
+
expect(association.inverses).to eq(nil)
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
context 'when not polymorphic' do
|
|
321
|
+
|
|
322
|
+
context 'when inverse_of is specified' do
|
|
323
|
+
|
|
324
|
+
before do
|
|
325
|
+
options.merge!(inverse_of: :inverse_name)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
it 'returns the :inverse_of value' do
|
|
329
|
+
expect(association.inverses).to eq([ :inverse_name ])
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
context 'when inverse_of is not specified' do
|
|
334
|
+
|
|
335
|
+
before do
|
|
336
|
+
Container.embeds_many :embedded_objects
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it 'uses the inverse class to find the inverse name' do
|
|
340
|
+
expect(association.inverses).to eq([ :embedded_objects ])
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
context 'when :cyclic is specified' do
|
|
345
|
+
|
|
346
|
+
it 'returns the cyclic inverse name' do
|
|
347
|
+
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
context 'when the inverse class has more than one relation with objects of the owner class' do
|
|
352
|
+
|
|
353
|
+
before do
|
|
354
|
+
Container.embeds_many :embedded_objects
|
|
355
|
+
Container.embeds_many :other_embedded_objects, class_name: 'EmbeddedObject'
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
it 'raises a Mongoid::Errors::AmbiguousRelationship exception' do
|
|
359
|
+
expect {
|
|
360
|
+
association.inverses
|
|
361
|
+
}.to raise_exception(Mongoid::Errors::AmbiguousRelationship)
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
context 'when the inverse class only has one relation with objects of the owner class' do
|
|
366
|
+
|
|
367
|
+
before do
|
|
368
|
+
Container.embeds_many :embedded_objects
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
it 'uses the inverse class to find the inverse name' do
|
|
372
|
+
expect(association.inverses).to eq([ :embedded_objects ])
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
describe '#inverse' do
|
|
379
|
+
|
|
380
|
+
context 'when polymorphic' do
|
|
381
|
+
|
|
382
|
+
let(:options) do
|
|
383
|
+
{
|
|
384
|
+
polymorphic: true
|
|
385
|
+
}
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
let(:name) do
|
|
389
|
+
:containable
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
context 'when another object is passed to the method' do
|
|
393
|
+
|
|
394
|
+
let(:instance_of_other_class) do
|
|
395
|
+
Container.new
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
399
|
+
|
|
400
|
+
before do
|
|
401
|
+
Container.embeds_many :embedded_objects, as: :containable
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
context 'when :inverse_of is specified' do
|
|
405
|
+
|
|
406
|
+
before do
|
|
407
|
+
options.merge!(inverse_of: :inverse_name)
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
it 'returns the :inverse_of value' do
|
|
411
|
+
expect(association.inverse(instance_of_other_class)).to eq(:inverse_name)
|
|
412
|
+
end
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
context 'when inverse_of is not specified' do
|
|
416
|
+
|
|
417
|
+
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
418
|
+
expect(association.inverse(instance_of_other_class)).to eq(:embedded_objects)
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
context 'when the relation class has more than one relation whose class matches the owning class' do
|
|
424
|
+
|
|
425
|
+
before do
|
|
426
|
+
Container.embeds_many :embedded_objects, as: :containable
|
|
427
|
+
Container.embeds_one :other_embedded_object, as: :containable
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
context 'when :inverse_of is specified' do
|
|
431
|
+
|
|
432
|
+
before do
|
|
433
|
+
options.merge!(inverse_of: :inverse_name)
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
it 'returns the :inverse_of value' do
|
|
437
|
+
expect(association.inverse(instance_of_other_class)).to eq(:inverse_name)
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
context 'when inverse_of is not specified' do
|
|
442
|
+
|
|
443
|
+
it 'returns the first candidate whose :as attribute matches the name of this association' do
|
|
444
|
+
expect(association.inverse(instance_of_other_class)).to eq(:embedded_objects)
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
context 'when another object is not passed to the method' do
|
|
451
|
+
|
|
452
|
+
context 'when inverse_of is specified' do
|
|
453
|
+
|
|
454
|
+
before do
|
|
455
|
+
options.merge!(inverse_of: :inverse_name)
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
it 'returns the :inverse_of value' do
|
|
459
|
+
expect(association.inverse).to eq(:inverse_name)
|
|
460
|
+
end
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
context 'when inverse_of is not specified' do
|
|
464
|
+
|
|
465
|
+
it 'returns nil' do
|
|
466
|
+
expect(association.inverse).to eq(nil)
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
context 'when not polymorphic' do
|
|
473
|
+
|
|
474
|
+
context 'when inverse_of is specified' do
|
|
475
|
+
|
|
476
|
+
before do
|
|
477
|
+
options.merge!(inverse_of: :inverse_name)
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
it 'returns the :inverse_of value' do
|
|
481
|
+
expect(association.inverse).to eq(:inverse_name)
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
context 'when inverse_of is not specified' do
|
|
486
|
+
|
|
487
|
+
before do
|
|
488
|
+
Container.embeds_many :embedded_objects
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
it 'uses the inverse class to find the inverse name' do
|
|
492
|
+
expect(association.inverse).to eq(:embedded_objects)
|
|
493
|
+
end
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
context 'when :cyclic is specified' do
|
|
497
|
+
|
|
498
|
+
it 'returns the cyclic inverse name' do
|
|
499
|
+
|
|
500
|
+
end
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
context 'when the inverse class has more than one relation with objects of the owner class' do
|
|
504
|
+
|
|
505
|
+
before do
|
|
506
|
+
Container.embeds_many :embedded_objects
|
|
507
|
+
Container.embeds_many :other_embedded_objects, class_name: 'EmbeddedObject'
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
it 'raises a Mongoid::Errors::AmbiguousRelationship exception' do
|
|
511
|
+
expect {
|
|
512
|
+
association.inverse
|
|
513
|
+
}.to raise_exception(Mongoid::Errors::AmbiguousRelationship)
|
|
514
|
+
end
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
context 'when the inverse class only has one relation with objects of the owner class' do
|
|
518
|
+
|
|
519
|
+
before do
|
|
520
|
+
Container.embeds_many :embedded_objects
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
it 'uses the inverse class to find the inverse name' do
|
|
524
|
+
expect(association.inverse).to eq(:embedded_objects)
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
describe '#inverse_association' do
|
|
531
|
+
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
describe '#autosave' do
|
|
535
|
+
|
|
536
|
+
it 'returns false' do
|
|
537
|
+
expect(association.autosave).to be(false)
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
describe '#relation_class_name' do
|
|
542
|
+
|
|
543
|
+
context 'when the :class_name option is specified' do
|
|
544
|
+
|
|
545
|
+
let(:options) do
|
|
546
|
+
{ class_name: 'OtherContainer' }
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
it 'returns the class name option' do
|
|
550
|
+
expect(association.relation_class_name).to eq('OtherContainer')
|
|
551
|
+
end
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
context 'when the class_name option is not specified' do
|
|
555
|
+
|
|
556
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
557
|
+
expect(association.relation_class_name).to eq('Container')
|
|
558
|
+
end
|
|
559
|
+
end
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
describe '#klass' do
|
|
563
|
+
|
|
564
|
+
context 'when the :class_name option is specified' do
|
|
565
|
+
|
|
566
|
+
let!(:_class) do
|
|
567
|
+
class OtherContainer; end
|
|
568
|
+
OtherContainer
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
let(:options) do
|
|
572
|
+
{ class_name: 'OtherContainer' }
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
it 'returns the class name option' do
|
|
576
|
+
expect(association.klass).to eq(_class)
|
|
577
|
+
end
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
context 'when the class_name option is not specified' do
|
|
581
|
+
|
|
582
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
583
|
+
expect(association.klass).to eq(Container)
|
|
584
|
+
end
|
|
585
|
+
end
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
describe '#inverse_class_name' do
|
|
589
|
+
|
|
590
|
+
it 'returns the name of the owner class' do
|
|
591
|
+
expect(association.inverse_class_name).to eq(embedded_class.name)
|
|
592
|
+
end
|
|
593
|
+
end
|
|
594
|
+
|
|
595
|
+
describe '#inverse_class' do
|
|
596
|
+
|
|
597
|
+
it 'returns the owner class' do
|
|
598
|
+
expect(association.inverse_class).to be(embedded_class)
|
|
599
|
+
end
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
describe '#inverse_of' do
|
|
603
|
+
|
|
604
|
+
context 'when :inverse_of is specified in the options' do
|
|
605
|
+
|
|
606
|
+
let(:options) do
|
|
607
|
+
{ inverse_of: :a_container }
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
it 'returns the inverse_of value' do
|
|
611
|
+
expect(association.inverse_of).to eq(options[:inverse_of])
|
|
612
|
+
end
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
context 'when :inverse_of is not specified in the options' do
|
|
616
|
+
|
|
617
|
+
it 'returns nil' do
|
|
618
|
+
expect(association.inverse_of).to be_nil
|
|
619
|
+
end
|
|
620
|
+
end
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
describe '#key' do
|
|
624
|
+
|
|
625
|
+
it 'returns the name of the relation as a string' do
|
|
626
|
+
expect(association.key).to eq(name.to_s)
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
|
|
630
|
+
describe '#setter' do
|
|
631
|
+
|
|
632
|
+
it 'returns a string of the name followed by =' do
|
|
633
|
+
expect(association.setter).to eq("#{name}=")
|
|
634
|
+
end
|
|
635
|
+
end
|
|
636
|
+
|
|
637
|
+
describe '#validate?' do
|
|
638
|
+
|
|
639
|
+
context 'when :validate is specified in the options' do
|
|
640
|
+
|
|
641
|
+
context 'when validate is true' do
|
|
642
|
+
|
|
643
|
+
let(:options) do
|
|
644
|
+
{ validate: true }
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
it 'returns true' do
|
|
648
|
+
expect(association.send(:validate?)).to be(true)
|
|
649
|
+
end
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
context 'when validate is false' do
|
|
653
|
+
|
|
654
|
+
let(:options) do
|
|
655
|
+
{ validate: false }
|
|
656
|
+
end
|
|
657
|
+
|
|
658
|
+
it 'returns false' do
|
|
659
|
+
expect(association.send(:validate?)).to be(false)
|
|
660
|
+
end
|
|
661
|
+
end
|
|
662
|
+
end
|
|
663
|
+
|
|
664
|
+
context 'when :validate is not specified in the options' do
|
|
665
|
+
|
|
666
|
+
it 'returns the validation_default' do
|
|
667
|
+
expect(association.send(:validate?)).to eq(association.validation_default)
|
|
668
|
+
end
|
|
669
|
+
end
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
describe '#autobuilding?' do
|
|
673
|
+
|
|
674
|
+
context 'when :autobuild is specified in the options' do
|
|
675
|
+
|
|
676
|
+
context 'when autobuild is true' do
|
|
677
|
+
|
|
678
|
+
let(:options) do
|
|
679
|
+
{ autobuild: true }
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
it 'returns true' do
|
|
683
|
+
expect(association.autobuilding?).to be(true)
|
|
684
|
+
end
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
context 'when autobuild is false' do
|
|
688
|
+
|
|
689
|
+
let(:options) do
|
|
690
|
+
{ autobuild: false }
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
it 'returns true' do
|
|
694
|
+
expect(association.autobuilding?).to be(false)
|
|
695
|
+
end
|
|
696
|
+
end
|
|
697
|
+
end
|
|
698
|
+
|
|
699
|
+
context 'when :validate is not specified in the options' do
|
|
700
|
+
|
|
701
|
+
it 'returns false' do
|
|
702
|
+
expect(association.autobuilding?).to be(false)
|
|
703
|
+
end
|
|
704
|
+
end
|
|
705
|
+
end
|
|
706
|
+
|
|
707
|
+
describe '#forced_nil_inverse?' do
|
|
708
|
+
|
|
709
|
+
it 'returns false' do
|
|
710
|
+
expect(association.forced_nil_inverse?).to be(false)
|
|
711
|
+
end
|
|
712
|
+
end
|
|
713
|
+
|
|
714
|
+
describe '#stores_foreign_key?' do
|
|
715
|
+
|
|
716
|
+
it 'returns false' do
|
|
717
|
+
expect(association.stores_foreign_key?).to be(false)
|
|
718
|
+
end
|
|
719
|
+
end
|
|
720
|
+
|
|
721
|
+
describe '#inverse_setter' do
|
|
722
|
+
|
|
723
|
+
context 'when an inverse can be determined' do
|
|
724
|
+
|
|
725
|
+
before do
|
|
726
|
+
Container.embeds_many :embedded_objects
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
it 'returns the name of the inverse followed by =' do
|
|
730
|
+
expect(association.inverse_setter).to eq('embedded_objects=')
|
|
731
|
+
end
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
context 'when an inverse cannot be determined' do
|
|
735
|
+
|
|
736
|
+
it 'returns nil' do
|
|
737
|
+
expect(association.inverse_setter).to be_nil
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
describe '#extension' do
|
|
743
|
+
|
|
744
|
+
context 'when a block is passed' do
|
|
745
|
+
|
|
746
|
+
let(:association) do
|
|
747
|
+
embedded_class.embedded_in name, options do; end
|
|
748
|
+
end
|
|
749
|
+
|
|
750
|
+
it 'defines an extension module' do
|
|
751
|
+
expect(association.extension).to be_a(Module)
|
|
752
|
+
end
|
|
753
|
+
|
|
754
|
+
it 'returns the extension' do
|
|
755
|
+
expect(association.extension).to eq(
|
|
756
|
+
"#{embedded_class.name}::#{embedded_class.name}#{name.capitalize}RelationExtension".constantize)
|
|
757
|
+
end
|
|
758
|
+
end
|
|
759
|
+
|
|
760
|
+
context 'when an :extension is not specified in the options' do
|
|
761
|
+
|
|
762
|
+
it 'returns false' do
|
|
763
|
+
expect(association.extension).to be_nil
|
|
764
|
+
end
|
|
765
|
+
end
|
|
766
|
+
end
|
|
767
|
+
|
|
768
|
+
describe '#criteria' do
|
|
769
|
+
|
|
770
|
+
it 'does not respond to the method' do
|
|
771
|
+
expect {
|
|
772
|
+
association.criteria
|
|
773
|
+
}.to raise_exception(NoMethodError)
|
|
774
|
+
end
|
|
775
|
+
end
|
|
776
|
+
|
|
777
|
+
describe '#destructive?' do
|
|
778
|
+
|
|
779
|
+
it 'returns false' do
|
|
780
|
+
expect(association.destructive?).to be(false)
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
describe '#nested_builder' do
|
|
785
|
+
|
|
786
|
+
it 'returns an instance of Association::Nested::One' do
|
|
787
|
+
expect(association.nested_builder({}, {})).to be_a(Mongoid::Association::Nested::One)
|
|
788
|
+
end
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
describe '#cascading_callbacks?' do
|
|
792
|
+
|
|
793
|
+
context 'when cascade_callbacks is specified in the options' do
|
|
794
|
+
|
|
795
|
+
let(:options) do
|
|
796
|
+
{cascade_callbacks: true}
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
it 'raises a Mongoid::Errors::InvalidRelationOption exception' do
|
|
800
|
+
expect {
|
|
801
|
+
association.cascading_callbacks?
|
|
802
|
+
}.to raise_exception(Mongoid::Errors::InvalidRelationOption)
|
|
803
|
+
end
|
|
804
|
+
end
|
|
805
|
+
|
|
806
|
+
context 'when cascade_callbacks is not specified in the options' do
|
|
807
|
+
|
|
808
|
+
it 'returns false' do
|
|
809
|
+
expect(association.cascading_callbacks?).to be(false)
|
|
810
|
+
end
|
|
811
|
+
end
|
|
812
|
+
end
|
|
813
|
+
|
|
814
|
+
describe '#path' do
|
|
815
|
+
|
|
816
|
+
it 'returns an instance of Mongoid::Atomic::Paths::Root' do
|
|
817
|
+
expect(association.path({})).to be_a(Mongoid::Atomic::Paths::Root)
|
|
818
|
+
end
|
|
819
|
+
end
|
|
820
|
+
|
|
821
|
+
describe '#foreign_key_check' do
|
|
822
|
+
|
|
823
|
+
it 'returns nil' do
|
|
824
|
+
expect(association.foreign_key_check).to be_nil
|
|
825
|
+
end
|
|
826
|
+
end
|
|
827
|
+
|
|
828
|
+
describe '#create_relation' do
|
|
829
|
+
|
|
830
|
+
let(:owner) do
|
|
831
|
+
Container.new
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
let(:target) do
|
|
835
|
+
EmbeddedObject.new
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
it 'returns an instance of Mongoid::Association::Embedded::EmbeddedIn::Proxy' do
|
|
839
|
+
expect(Mongoid::Association::Embedded::EmbeddedIn::Proxy).to receive(:new).and_call_original
|
|
840
|
+
expect(association.create_relation(owner, target)).to be_a(EmbeddedObject)
|
|
841
|
+
end
|
|
842
|
+
end
|
|
843
|
+
end
|