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,1027 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Association::Referenced::HasAndBelongsToMany do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
class HasManyLeftObject; include Mongoid::Document; end
|
|
7
|
+
class HasManyRightObject; include Mongoid::Document; end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
after do
|
|
11
|
+
Object.send(:remove_const, :HasManyLeftObject)
|
|
12
|
+
Object.send(:remove_const, :HasManyRightObject)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:has_many_left_class) do
|
|
16
|
+
HasManyLeftObject
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
let(:name) do
|
|
20
|
+
:has_many_right_objects
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
let(:association) do
|
|
24
|
+
has_many_left_class.has_and_belongs_to_many 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::Referenced::HasAndBelongsToMany,
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'returns the relation complements' do
|
|
40
|
+
expect(association.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
|
+
context 'autosave' do
|
|
62
|
+
|
|
63
|
+
context 'when the :autosave option is true' do
|
|
64
|
+
|
|
65
|
+
let(:options) do
|
|
66
|
+
{
|
|
67
|
+
autosave: true
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
let(:association) do
|
|
72
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
73
|
+
# setup! method will be called by the :has_many macro
|
|
74
|
+
described_class.new(has_many_left_class, name, options)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'sets up autosave' do
|
|
78
|
+
expect(Mongoid::Association::Referenced::AutoSave).to receive(:define_autosave!).with(association)
|
|
79
|
+
association.setup!
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context 'when the :autosave option is false' do
|
|
84
|
+
|
|
85
|
+
let(:options) do
|
|
86
|
+
{
|
|
87
|
+
autosave: false
|
|
88
|
+
}
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'does not set up autosave' do
|
|
92
|
+
expect(Mongoid::Association::Referenced::AutoSave).not_to receive(:define_autosave!)
|
|
93
|
+
association.setup!
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context 'when the :autosave option is not provided' do
|
|
98
|
+
|
|
99
|
+
let(:association) do
|
|
100
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
101
|
+
# setup! method will be called by the :has_many macro
|
|
102
|
+
described_class.new(has_many_left_class, name, options)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'does not set up autosave' do
|
|
106
|
+
expect(Mongoid::Association::Referenced::AutoSave).not_to receive(:define_autosave!)
|
|
107
|
+
association.setup!
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
context 'when the :validate option is true' do
|
|
113
|
+
|
|
114
|
+
let(:options) do
|
|
115
|
+
{
|
|
116
|
+
validate: true
|
|
117
|
+
}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
let(:association) do
|
|
121
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
122
|
+
# setup! method will be called by the :has_and_belongs_to_many macro
|
|
123
|
+
described_class.new(has_many_left_class, name, options)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'sets up validation' do
|
|
127
|
+
expect(has_many_left_class).to receive(:validates_associated).with(name).and_call_original
|
|
128
|
+
association.setup!
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
context 'when the :validate option is false' do
|
|
133
|
+
|
|
134
|
+
let(:options) do
|
|
135
|
+
{
|
|
136
|
+
validate: false
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'does not set up validation' do
|
|
141
|
+
expect(has_many_left_class).not_to receive(:validates_associated)
|
|
142
|
+
association.setup!
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context 'when the :validate option is not provided' do
|
|
147
|
+
|
|
148
|
+
let(:association) do
|
|
149
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
150
|
+
# setup! method will be called by the :has_many macro
|
|
151
|
+
described_class.new(has_many_left_class, name, options)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it 'sets up the validation because it uses the validation default (true)' do
|
|
155
|
+
expect(has_many_left_class).to receive(:validates_associated).with(name).and_call_original
|
|
156
|
+
association.setup!
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context 'foreign key field' do
|
|
161
|
+
|
|
162
|
+
before do
|
|
163
|
+
association
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it 'sets up the foreign key field' do
|
|
167
|
+
expect(has_many_left_class.fields.keys).to include(association.foreign_key)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context 'index' do
|
|
172
|
+
|
|
173
|
+
before do
|
|
174
|
+
association
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context 'when index is true' do
|
|
178
|
+
|
|
179
|
+
let(:options) do
|
|
180
|
+
{
|
|
181
|
+
index: true
|
|
182
|
+
}
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'sets up the index with the key' do
|
|
186
|
+
expect(has_many_left_class.index_specifications.first.fields).to match_array([association.key.to_sym])
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context 'when index is false' do
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
it 'does not set up an index' do
|
|
194
|
+
expect(has_many_left_class.index_specifications).to eq([])
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
context 'dependent' do
|
|
200
|
+
|
|
201
|
+
context 'when the dependent option is provided' do
|
|
202
|
+
|
|
203
|
+
context 'when the dependent option is :delete_all' do
|
|
204
|
+
|
|
205
|
+
let(:options) do
|
|
206
|
+
{
|
|
207
|
+
dependent: :delete_all
|
|
208
|
+
}
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
let(:association) do
|
|
212
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
213
|
+
# setup! method will be called by the :belongs_to macro
|
|
214
|
+
described_class.new(has_many_left_class, name, options)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it 'sets up the dependency' do
|
|
218
|
+
expect(Mongoid::Association::Depending).to receive(:define_dependency!)
|
|
219
|
+
association.setup!
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context 'when the dependent option is :destroy' do
|
|
224
|
+
|
|
225
|
+
let(:options) do
|
|
226
|
+
{
|
|
227
|
+
dependent: :destroy
|
|
228
|
+
}
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
let(:association) do
|
|
232
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
233
|
+
# setup! method will be called by the :belongs_to macro
|
|
234
|
+
described_class.new(has_many_left_class, name, options)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'sets up the dependency' do
|
|
238
|
+
expect(Mongoid::Association::Depending).to receive(:define_dependency!)
|
|
239
|
+
association.setup!
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
context 'when the dependent option is :nullify' do
|
|
244
|
+
|
|
245
|
+
let(:options) do
|
|
246
|
+
{
|
|
247
|
+
dependent: :nullify
|
|
248
|
+
}
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
let(:association) do
|
|
252
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
253
|
+
# setup! method will be called by the :belongs_to macro
|
|
254
|
+
described_class.new(has_many_left_class, name, options)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it 'sets up the dependency' do
|
|
258
|
+
expect(Mongoid::Association::Depending).to receive(:define_dependency!)
|
|
259
|
+
association.setup!
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
context 'when the dependent option is :restrict_with_exception' do
|
|
264
|
+
|
|
265
|
+
let(:options) do
|
|
266
|
+
{
|
|
267
|
+
dependent: :restrict_with_exception
|
|
268
|
+
}
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
let(:association) do
|
|
272
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
273
|
+
# setup! method will be called by the :belongs_to macro
|
|
274
|
+
described_class.new(has_many_left_class, name, options)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it 'sets up the dependency' do
|
|
278
|
+
expect(Mongoid::Association::Depending).to receive(:define_dependency!)
|
|
279
|
+
association.setup!
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
context 'when the dependent option is :restrict_with_error' do
|
|
284
|
+
|
|
285
|
+
let(:options) do
|
|
286
|
+
{
|
|
287
|
+
dependent: :restrict_with_error
|
|
288
|
+
}
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
let(:association) do
|
|
292
|
+
# Note that it is necessary to create the association directly, otherwise the
|
|
293
|
+
# setup! method will be called by the :belongs_to macro
|
|
294
|
+
described_class.new(has_many_left_class, name, options)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it 'sets up the dependency' do
|
|
298
|
+
expect(Mongoid::Association::Depending).to receive(:define_dependency!)
|
|
299
|
+
association.setup!
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
context 'when the dependent option is not provided' do
|
|
305
|
+
|
|
306
|
+
it 'does not set up the dependency' do
|
|
307
|
+
expect(Mongoid::Association::Depending).not_to receive(:define_dependency!)
|
|
308
|
+
association.setup!
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
describe '#type' do
|
|
315
|
+
|
|
316
|
+
it 'returns nil' do
|
|
317
|
+
expect(association.type).to be_nil
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
describe '#inverse_type' do
|
|
322
|
+
|
|
323
|
+
it 'returns nil' do
|
|
324
|
+
expect(association.inverse_type).to be_nil
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
describe '#inverse_type_setter' do
|
|
329
|
+
|
|
330
|
+
it 'returns nil' do
|
|
331
|
+
expect(association.inverse_type_setter).to be_nil
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
describe '#foreign_key' do
|
|
336
|
+
|
|
337
|
+
context 'when options has foreign_key specified' do
|
|
338
|
+
|
|
339
|
+
let(:options) do
|
|
340
|
+
{ foreign_key: :other_object_id }
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it 'raises returns the foreign key as a String' do
|
|
344
|
+
expect(association.foreign_key).to eq(options[:foreign_key].to_s)
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
context 'when options does not have foreign_key specified' do
|
|
349
|
+
|
|
350
|
+
it 'returns the default foreign key, the name of the inverse followed by "_ids"' do
|
|
351
|
+
expect(association.foreign_key).to eq("#{name.to_s.singularize}_ids")
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
describe '#embedded?' do
|
|
357
|
+
|
|
358
|
+
it 'returns false' do
|
|
359
|
+
expect(association.embedded?).to be(false)
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe '#primary_key' do
|
|
364
|
+
|
|
365
|
+
context 'when the :primary_key option is specified' do
|
|
366
|
+
|
|
367
|
+
let(:options) do
|
|
368
|
+
{
|
|
369
|
+
primary_key: 'guid'
|
|
370
|
+
}
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
it 'returns the primary_key' do
|
|
374
|
+
expect(association.primary_key).to eq(options[:primary_key])
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
context 'when the :primary_key option is not specified' do
|
|
379
|
+
|
|
380
|
+
it 'returns the primary_key default' do
|
|
381
|
+
expect(association.primary_key).to eq(Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT)
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
describe '#indexed?' do
|
|
387
|
+
|
|
388
|
+
context 'when :index is specified in the options' do
|
|
389
|
+
|
|
390
|
+
context 'when :index is true' do
|
|
391
|
+
|
|
392
|
+
let(:options) do
|
|
393
|
+
{
|
|
394
|
+
index: true
|
|
395
|
+
}
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
it 'returns true' do
|
|
399
|
+
expect(association.indexed?).to be(true)
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
context 'when :index is false' do
|
|
404
|
+
|
|
405
|
+
let(:options) do
|
|
406
|
+
{
|
|
407
|
+
index: false
|
|
408
|
+
}
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
it 'returns false' do
|
|
412
|
+
expect(association.indexed?).to be(false)
|
|
413
|
+
end
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
context 'when :index is not specified in the options' do
|
|
418
|
+
|
|
419
|
+
it 'returns nil' do
|
|
420
|
+
expect(association.indexed?).to be(false)
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
describe '#relation' do
|
|
426
|
+
|
|
427
|
+
it 'returns Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy' do
|
|
428
|
+
expect(association.relation).to be(Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy)
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
describe '#validation_default' do
|
|
433
|
+
|
|
434
|
+
it 'returns true' do
|
|
435
|
+
expect(association.validation_default).to be(true)
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
describe '#name' do
|
|
440
|
+
|
|
441
|
+
it 'returns the name of the relation' do
|
|
442
|
+
expect(association.name).to be(name)
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
describe '#options' do
|
|
447
|
+
|
|
448
|
+
it 'returns the options' do
|
|
449
|
+
expect(association.options).to be(options)
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
describe '#merge!' do
|
|
454
|
+
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
describe '#store_as' do
|
|
458
|
+
|
|
459
|
+
it 'returns nil' do
|
|
460
|
+
expect(association.store_as).to be_nil
|
|
461
|
+
end
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
describe '#touchable?' do
|
|
465
|
+
|
|
466
|
+
it 'return false' do
|
|
467
|
+
expect(association.send(:touchable?)).to be(false)
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
describe '#order' do
|
|
472
|
+
|
|
473
|
+
context 'when order is specified in the options' do
|
|
474
|
+
|
|
475
|
+
let(:options) do
|
|
476
|
+
{
|
|
477
|
+
order: :rating.desc
|
|
478
|
+
}
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
it 'returns a Criteria Queryable Key' do
|
|
482
|
+
expect(association.order).to be_a(Mongoid::Criteria::Queryable::Key)
|
|
483
|
+
end
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
context 'when order is not specified in the options' do
|
|
487
|
+
|
|
488
|
+
it 'returns nil' do
|
|
489
|
+
expect(association.order).to be_nil
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
describe '#as' do
|
|
495
|
+
|
|
496
|
+
it 'returns nil' do
|
|
497
|
+
expect(association.as).to be_nil
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
describe '#polymorphic?' do
|
|
502
|
+
|
|
503
|
+
it 'returns false' do
|
|
504
|
+
expect(association.polymorphic?).to be(false)
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
describe '#type_setter' do
|
|
509
|
+
|
|
510
|
+
it 'returns nil' do
|
|
511
|
+
expect(association.type).to be_nil
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
describe '#dependent' do
|
|
516
|
+
|
|
517
|
+
it 'returns nil' do
|
|
518
|
+
expect(association.dependent).to be_nil
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
describe '#bindable?' do
|
|
523
|
+
|
|
524
|
+
it 'returns false' do
|
|
525
|
+
expect(association.bindable?(Person.new)).to be(false)
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
describe '#inverses' do
|
|
530
|
+
|
|
531
|
+
before do
|
|
532
|
+
HasManyRightObject.has_and_belongs_to_many :has_many_left_objects
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
context 'when inverse_of is specified' do
|
|
536
|
+
|
|
537
|
+
before do
|
|
538
|
+
options.merge!(inverse_of: :inverse_name)
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
it 'returns the :inverse_of value' do
|
|
542
|
+
expect(association.inverses).to eq([:inverse_name])
|
|
543
|
+
end
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
context 'when inverse_of is not specified' do
|
|
547
|
+
|
|
548
|
+
it 'uses the inverse class to find the inverse name' do
|
|
549
|
+
expect(association.inverses).to eq([:has_many_left_objects])
|
|
550
|
+
end
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
context 'when :cyclic is specified' do
|
|
554
|
+
|
|
555
|
+
it 'returns the cyclic inverse name' do
|
|
556
|
+
|
|
557
|
+
end
|
|
558
|
+
end
|
|
559
|
+
end
|
|
560
|
+
|
|
561
|
+
describe '##inverse' do
|
|
562
|
+
|
|
563
|
+
before do
|
|
564
|
+
HasManyRightObject.has_and_belongs_to_many :has_many_left_objects
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
context 'when inverse_of is specified' do
|
|
568
|
+
|
|
569
|
+
before do
|
|
570
|
+
options.merge!(inverse_of: :inverse_name)
|
|
571
|
+
end
|
|
572
|
+
|
|
573
|
+
it 'returns the :inverse_of value' do
|
|
574
|
+
expect(association.inverse).to eq(:inverse_name)
|
|
575
|
+
end
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
context 'when inverse_of is not specified' do
|
|
579
|
+
|
|
580
|
+
it 'uses the inverse class to find the inverse name' do
|
|
581
|
+
expect(association.inverse).to eq(:has_many_left_objects)
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
context 'when :cyclic is specified' do
|
|
586
|
+
|
|
587
|
+
it 'returns the cyclic inverse name' do
|
|
588
|
+
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
describe '#inverse_association' do
|
|
594
|
+
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
describe '#autosave' do
|
|
598
|
+
|
|
599
|
+
context 'when the autosave option is specified' do
|
|
600
|
+
|
|
601
|
+
context 'when the autosave option is true' do
|
|
602
|
+
|
|
603
|
+
let(:options) do
|
|
604
|
+
{
|
|
605
|
+
autosave: true
|
|
606
|
+
}
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
it 'returns true' do
|
|
610
|
+
expect(association.autosave).to be(true)
|
|
611
|
+
end
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
context 'when the autosave option is false' do
|
|
615
|
+
|
|
616
|
+
let(:options) do
|
|
617
|
+
{
|
|
618
|
+
autosave: false
|
|
619
|
+
}
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
it 'returns false' do
|
|
623
|
+
expect(association.autosave).to be(false)
|
|
624
|
+
end
|
|
625
|
+
end
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
context 'when the autosave option is not specified' do
|
|
629
|
+
|
|
630
|
+
it 'returns false' do
|
|
631
|
+
expect(association.autosave).to be(false)
|
|
632
|
+
end
|
|
633
|
+
end
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
describe '#relation_class_name' do
|
|
637
|
+
|
|
638
|
+
context 'when the :class_name option is specified' do
|
|
639
|
+
|
|
640
|
+
let(:options) do
|
|
641
|
+
{ class_name: 'OtherHasManyRightObject' }
|
|
642
|
+
end
|
|
643
|
+
|
|
644
|
+
it 'returns the class name option' do
|
|
645
|
+
expect(association.relation_class_name).to eq('OtherHasManyRightObject')
|
|
646
|
+
end
|
|
647
|
+
end
|
|
648
|
+
|
|
649
|
+
context 'when the class_name option is not specified' do
|
|
650
|
+
|
|
651
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
652
|
+
expect(association.relation_class_name).to eq('HasManyRightObject')
|
|
653
|
+
end
|
|
654
|
+
end
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
describe '#relation_class' do
|
|
658
|
+
|
|
659
|
+
context 'when the :class_name option is specified' do
|
|
660
|
+
|
|
661
|
+
let!(:_class) do
|
|
662
|
+
class OtherHasManyRightObject; end
|
|
663
|
+
OtherHasManyRightObject
|
|
664
|
+
end
|
|
665
|
+
|
|
666
|
+
let(:options) do
|
|
667
|
+
{ class_name: 'OtherHasManyRightObject' }
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
it 'returns the class name option' do
|
|
671
|
+
expect(association.relation_class).to eq(_class)
|
|
672
|
+
end
|
|
673
|
+
end
|
|
674
|
+
|
|
675
|
+
context 'when the class_name option is not specified' do
|
|
676
|
+
|
|
677
|
+
it 'uses the name of the relation to deduce the class name' do
|
|
678
|
+
expect(association.relation_class).to eq(HasManyRightObject)
|
|
679
|
+
end
|
|
680
|
+
end
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
describe '#inverse_class_name' do
|
|
684
|
+
|
|
685
|
+
it 'returns the name of the owner class' do
|
|
686
|
+
expect(association.inverse_class_name).to eq(HasManyLeftObject.name)
|
|
687
|
+
end
|
|
688
|
+
end
|
|
689
|
+
|
|
690
|
+
describe '#inverse_class' do
|
|
691
|
+
|
|
692
|
+
it 'returns the owner class' do
|
|
693
|
+
expect(association.inverse_class).to be(HasManyLeftObject)
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
|
|
697
|
+
describe '#inverse_of' do
|
|
698
|
+
|
|
699
|
+
context 'when :inverse_of is specified in the options' do
|
|
700
|
+
|
|
701
|
+
let(:options) do
|
|
702
|
+
{ inverse_of: :a_has_many_left_object }
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
it 'returns the inverse_of value' do
|
|
706
|
+
expect(association.inverse_of).to eq(options[:inverse_of])
|
|
707
|
+
end
|
|
708
|
+
end
|
|
709
|
+
|
|
710
|
+
context 'when :inverse_of is not specified in the options' do
|
|
711
|
+
|
|
712
|
+
it 'returns nil' do
|
|
713
|
+
expect(association.inverse_of).to be_nil
|
|
714
|
+
end
|
|
715
|
+
end
|
|
716
|
+
end
|
|
717
|
+
|
|
718
|
+
# describe '#key' do
|
|
719
|
+
#
|
|
720
|
+
# it 'returns the primary key' do
|
|
721
|
+
# expect(association.key).to eq(association.primary_key)
|
|
722
|
+
# end
|
|
723
|
+
# end
|
|
724
|
+
|
|
725
|
+
describe '#setter' do
|
|
726
|
+
|
|
727
|
+
it 'returns a string of the name followed by =' do
|
|
728
|
+
expect(association.setter).to eq("#{name}=")
|
|
729
|
+
end
|
|
730
|
+
end
|
|
731
|
+
|
|
732
|
+
describe '#validate?' do
|
|
733
|
+
|
|
734
|
+
context 'when :validate is specified in the options' do
|
|
735
|
+
|
|
736
|
+
context 'when validate is true' do
|
|
737
|
+
|
|
738
|
+
let(:options) do
|
|
739
|
+
{ validate: true }
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
it 'returns true' do
|
|
743
|
+
expect(association.send(:validate?)).to be(true)
|
|
744
|
+
end
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
context 'when validate is false' do
|
|
748
|
+
|
|
749
|
+
let(:options) do
|
|
750
|
+
{ validate: false }
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
it 'returns false' do
|
|
754
|
+
expect(association.send(:validate?)).to be(false)
|
|
755
|
+
end
|
|
756
|
+
end
|
|
757
|
+
end
|
|
758
|
+
|
|
759
|
+
context 'when :validate is not specified in the options' do
|
|
760
|
+
|
|
761
|
+
it 'returns the validation_default' do
|
|
762
|
+
expect(association.send(:validate?)).to eq(association.validation_default)
|
|
763
|
+
end
|
|
764
|
+
end
|
|
765
|
+
end
|
|
766
|
+
|
|
767
|
+
describe '#forced_nil_inverse?' do
|
|
768
|
+
|
|
769
|
+
context 'when inverse_of is specified in the options' do
|
|
770
|
+
|
|
771
|
+
context 'when :inverse_of is nil' do
|
|
772
|
+
|
|
773
|
+
let(:options) do
|
|
774
|
+
{
|
|
775
|
+
inverse_of: nil
|
|
776
|
+
}
|
|
777
|
+
end
|
|
778
|
+
|
|
779
|
+
it 'returns true' do
|
|
780
|
+
expect(association.forced_nil_inverse?).to be(true)
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
context 'when :inverse_of is a symbol' do
|
|
785
|
+
|
|
786
|
+
let(:options) do
|
|
787
|
+
{
|
|
788
|
+
inverse_of: :inverse_name
|
|
789
|
+
}
|
|
790
|
+
end
|
|
791
|
+
|
|
792
|
+
it 'returns false' do
|
|
793
|
+
expect(association.forced_nil_inverse?).to be(false)
|
|
794
|
+
end
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
context 'when :inverse_of is false' do
|
|
798
|
+
|
|
799
|
+
let(:options) do
|
|
800
|
+
{
|
|
801
|
+
inverse_of: false
|
|
802
|
+
}
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
it 'returns true' do
|
|
806
|
+
expect(association.forced_nil_inverse?).to be(true)
|
|
807
|
+
end
|
|
808
|
+
end
|
|
809
|
+
end
|
|
810
|
+
|
|
811
|
+
context 'when :inverse_of is not specified in the options' do
|
|
812
|
+
|
|
813
|
+
it 'returns false' do
|
|
814
|
+
expect(association.forced_nil_inverse?).to be(false)
|
|
815
|
+
end
|
|
816
|
+
end
|
|
817
|
+
end
|
|
818
|
+
|
|
819
|
+
describe '#stores_foreign_key?' do
|
|
820
|
+
|
|
821
|
+
it 'returns false' do
|
|
822
|
+
expect(association.stores_foreign_key?).to be(true)
|
|
823
|
+
end
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
describe '#inverse_setter' do
|
|
827
|
+
|
|
828
|
+
context 'when an inverse can be determined' do
|
|
829
|
+
|
|
830
|
+
before do
|
|
831
|
+
HasManyRightObject.has_and_belongs_to_many :has_many_left_objects
|
|
832
|
+
end
|
|
833
|
+
|
|
834
|
+
it 'returns the name of the inverse followed by =' do
|
|
835
|
+
expect(association.inverse_setter).to eq('has_many_left_objects=')
|
|
836
|
+
end
|
|
837
|
+
end
|
|
838
|
+
|
|
839
|
+
context 'when an inverse cannot be determined' do
|
|
840
|
+
|
|
841
|
+
it 'returns nil' do
|
|
842
|
+
expect(association.inverse_setter).to be_nil
|
|
843
|
+
end
|
|
844
|
+
end
|
|
845
|
+
end
|
|
846
|
+
|
|
847
|
+
describe '#extension' do
|
|
848
|
+
|
|
849
|
+
context 'when a block is passed' do
|
|
850
|
+
|
|
851
|
+
let(:association) do
|
|
852
|
+
has_many_left_class.has_and_belongs_to_many name, options do; end
|
|
853
|
+
end
|
|
854
|
+
|
|
855
|
+
it 'defines an extension module' do
|
|
856
|
+
expect(association.extension).to be_a(Module)
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
it 'returns the extension' do
|
|
860
|
+
expect(association.extension).to eq(
|
|
861
|
+
"#{has_many_left_class.name}::#{has_many_left_class.name}#{name.to_s.camelize}RelationExtension".constantize)
|
|
862
|
+
end
|
|
863
|
+
end
|
|
864
|
+
|
|
865
|
+
context 'when an :extension is not specified in the options' do
|
|
866
|
+
|
|
867
|
+
it 'returns false' do
|
|
868
|
+
expect(association.extension).to be_nil
|
|
869
|
+
end
|
|
870
|
+
end
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
describe '#foreign_key_setter' do
|
|
874
|
+
|
|
875
|
+
it 'returns the foreign key followed by "="' do
|
|
876
|
+
expect(association.foreign_key_setter).to eq("#{association.foreign_key}=")
|
|
877
|
+
end
|
|
878
|
+
end
|
|
879
|
+
|
|
880
|
+
describe '#criteria' do
|
|
881
|
+
|
|
882
|
+
it 'returns a criteria object' do
|
|
883
|
+
expect(association.criteria(BSON::ObjectId.new, HasManyLeftObject)).to be_a(Mongoid::Criteria)
|
|
884
|
+
end
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
describe '#destructive?' do
|
|
888
|
+
|
|
889
|
+
context 'when the dependent option is provided' do
|
|
890
|
+
|
|
891
|
+
context 'when the dependent option is :delete_all' do
|
|
892
|
+
|
|
893
|
+
let(:options) do
|
|
894
|
+
{
|
|
895
|
+
dependent: :delete_all
|
|
896
|
+
}
|
|
897
|
+
end
|
|
898
|
+
|
|
899
|
+
it 'returns true' do
|
|
900
|
+
expect(association.destructive?).to be(true)
|
|
901
|
+
end
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
context 'when the dependent option is :destroy' do
|
|
905
|
+
|
|
906
|
+
let(:options) do
|
|
907
|
+
{
|
|
908
|
+
dependent: :destroy
|
|
909
|
+
}
|
|
910
|
+
end
|
|
911
|
+
|
|
912
|
+
it 'returns true' do
|
|
913
|
+
expect(association.destructive?).to be(true)
|
|
914
|
+
end
|
|
915
|
+
end
|
|
916
|
+
|
|
917
|
+
context 'when the dependent option is :nullify' do
|
|
918
|
+
|
|
919
|
+
let(:options) do
|
|
920
|
+
{
|
|
921
|
+
dependent: :nullify
|
|
922
|
+
}
|
|
923
|
+
end
|
|
924
|
+
|
|
925
|
+
it 'returns false' do
|
|
926
|
+
expect(association.destructive?).to be(false)
|
|
927
|
+
end
|
|
928
|
+
end
|
|
929
|
+
|
|
930
|
+
context 'when the dependent option is :restrict_with_exception' do
|
|
931
|
+
|
|
932
|
+
let(:options) do
|
|
933
|
+
{
|
|
934
|
+
dependent: :restrict_with_exception
|
|
935
|
+
}
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
it 'returns false' do
|
|
939
|
+
expect(association.destructive?).to be(false)
|
|
940
|
+
end
|
|
941
|
+
end
|
|
942
|
+
|
|
943
|
+
context 'when the dependent option is :restrict_with_error' do
|
|
944
|
+
|
|
945
|
+
let(:options) do
|
|
946
|
+
{
|
|
947
|
+
dependent: :restrict_with_error
|
|
948
|
+
}
|
|
949
|
+
end
|
|
950
|
+
|
|
951
|
+
it 'returns false' do
|
|
952
|
+
expect(association.destructive?).to be(false)
|
|
953
|
+
end
|
|
954
|
+
end
|
|
955
|
+
end
|
|
956
|
+
|
|
957
|
+
context 'when the dependent option is not provided' do
|
|
958
|
+
|
|
959
|
+
it 'returns false' do
|
|
960
|
+
expect(association.destructive?).to be(false)
|
|
961
|
+
end
|
|
962
|
+
end
|
|
963
|
+
end
|
|
964
|
+
|
|
965
|
+
describe '#nested_builder' do
|
|
966
|
+
|
|
967
|
+
it 'returns an instance of Association::Nested::Many' do
|
|
968
|
+
expect(association.nested_builder({}, {})).to be_a(Mongoid::Association::Nested::Many)
|
|
969
|
+
end
|
|
970
|
+
end
|
|
971
|
+
|
|
972
|
+
describe '#cascading_callbacks?' do
|
|
973
|
+
|
|
974
|
+
it 'returns false' do
|
|
975
|
+
expect(association.cascading_callbacks?).to be(false)
|
|
976
|
+
end
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
describe '#path' do
|
|
980
|
+
|
|
981
|
+
it 'returns an instance of Mongoid::Atomic::Paths::Root' do
|
|
982
|
+
expect(association.path(double)).to be_a(Mongoid::Atomic::Paths::Root)
|
|
983
|
+
end
|
|
984
|
+
end
|
|
985
|
+
|
|
986
|
+
describe '#foreign_key_check' do
|
|
987
|
+
|
|
988
|
+
it 'returns the foreign_key followed by "_changed?"' do
|
|
989
|
+
expect(association.foreign_key_check).to eq('has_many_right_object_ids_changed?')
|
|
990
|
+
end
|
|
991
|
+
end
|
|
992
|
+
|
|
993
|
+
describe '#create_relation' do
|
|
994
|
+
|
|
995
|
+
let(:left_object) do
|
|
996
|
+
HasManyLeftObject.new
|
|
997
|
+
end
|
|
998
|
+
|
|
999
|
+
let(:target) do
|
|
1000
|
+
[ HasManyRightObject.new ]
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
before do
|
|
1004
|
+
association
|
|
1005
|
+
HasManyRightObject.has_and_belongs_to_many :has_many_left_objects
|
|
1006
|
+
end
|
|
1007
|
+
|
|
1008
|
+
it 'returns an the target' do
|
|
1009
|
+
expect(Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy).to receive(:new).and_call_original
|
|
1010
|
+
expect(association.create_relation(left_object, target)).to be_a(Array)
|
|
1011
|
+
end
|
|
1012
|
+
end
|
|
1013
|
+
|
|
1014
|
+
describe '#inverse_foreign_key' do
|
|
1015
|
+
|
|
1016
|
+
it 'returns nil' do
|
|
1017
|
+
expect(association.inverse_foreign_key).to eq('has_many_left_object_ids')
|
|
1018
|
+
end
|
|
1019
|
+
end
|
|
1020
|
+
|
|
1021
|
+
describe '#inverse_foreign_key_setter' do
|
|
1022
|
+
|
|
1023
|
+
it 'returns nil' do
|
|
1024
|
+
expect(association.inverse_foreign_key_setter).to eq('has_many_left_object_ids=')
|
|
1025
|
+
end
|
|
1026
|
+
end
|
|
1027
|
+
end
|