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
|
@@ -57,7 +57,7 @@ describe Mongoid::Persistable do
|
|
|
57
57
|
"$bit" => { "likes" => { :and => 13 }},
|
|
58
58
|
"$set" => { "name" => "Placebo" },
|
|
59
59
|
"$unset" => { "origin" => true }},
|
|
60
|
-
|
|
60
|
+
{ :session => nil } ]
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
before do
|
|
@@ -83,8 +83,8 @@ describe Mongoid::Persistable do
|
|
|
83
83
|
"$inc" => { "member_count" => 10 },
|
|
84
84
|
"$bit" => { "likes" => { :and => 13 }},
|
|
85
85
|
"$set" => { "name" => "Placebo" },
|
|
86
|
-
"$unset" => { "origin" => true }},
|
|
87
|
-
|
|
86
|
+
"$unset" => { "origin" => true } },
|
|
87
|
+
{ :session => nil } ]
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
before do
|
|
@@ -107,12 +107,12 @@ describe Mongoid::Persistable do
|
|
|
107
107
|
context "when given multiple operations of the same type" do
|
|
108
108
|
|
|
109
109
|
let(:operations) do
|
|
110
|
-
|
|
110
|
+
[{
|
|
111
111
|
"$inc" => { "member_count" => 10, "other_count" => 10 },
|
|
112
112
|
"$bit" => { "likes" => { :and => 13 }},
|
|
113
113
|
"$set" => { "name" => "Placebo" },
|
|
114
114
|
"$unset" => { "origin" => true }},
|
|
115
|
-
{ session
|
|
115
|
+
{ :session => nil } ]
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
before do
|
|
@@ -149,7 +149,7 @@ describe Mongoid::Persistable do
|
|
|
149
149
|
"$bit" => { "likes" => { :and => 13 }},
|
|
150
150
|
"$set" => { "name" => "Placebo" },
|
|
151
151
|
"$unset" => { "origin" => true }},
|
|
152
|
-
{ session
|
|
152
|
+
{ :session => nil } ]
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
before do
|
|
@@ -200,6 +200,21 @@ describe Mongoid::Persistable do
|
|
|
200
200
|
expect(document.atomically).to be true
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
|
+
|
|
204
|
+
context "when the block has no operations" do
|
|
205
|
+
before do
|
|
206
|
+
expect_any_instance_of(Mongo::Collection::View).to_not receive(:update_one)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
let!(:update) do
|
|
210
|
+
document.atomically do
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "doesn't update the document" do
|
|
215
|
+
expect(document.reload.origin).to eq("London")
|
|
216
|
+
end
|
|
217
|
+
end
|
|
203
218
|
end
|
|
204
219
|
|
|
205
220
|
describe "#fail_due_to_valiation!" do
|
|
@@ -536,7 +536,7 @@ describe Mongoid::PersistenceContext do
|
|
|
536
536
|
end
|
|
537
537
|
|
|
538
538
|
before do
|
|
539
|
-
Mongoid.clients[:alternative] = { database: :mongoid_test, hosts:
|
|
539
|
+
Mongoid.clients[:alternative] = { database: :mongoid_test, hosts: SpecConfig.instance.addresses }
|
|
540
540
|
end
|
|
541
541
|
|
|
542
542
|
after do
|
|
@@ -31,28 +31,14 @@ describe Mongoid::QueryCache do
|
|
|
31
31
|
:posts
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
context '
|
|
34
|
+
context 'does not query for the relation and instead sets the base' do
|
|
35
35
|
|
|
36
36
|
before do
|
|
37
37
|
Mongoid::QueryCache.enabled = false
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it 'queries for each access to the base' do
|
|
41
|
-
expect(server).to receive(:with_connection).exactly(
|
|
42
|
-
relations.each do |object|
|
|
43
|
-
object.person
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'when query cache is enabled' do
|
|
49
|
-
|
|
50
|
-
before do
|
|
51
|
-
Mongoid::QueryCache.enabled = true
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'queries only once for the base' do
|
|
55
|
-
expect(server).to receive(:with_connection).exactly(1).times.and_call_original
|
|
41
|
+
expect(server).to receive(:with_connection).exactly(0).times.and_call_original
|
|
56
42
|
relations.each do |object|
|
|
57
43
|
object.person
|
|
58
44
|
end
|
|
@@ -137,6 +123,36 @@ describe Mongoid::QueryCache do
|
|
|
137
123
|
end
|
|
138
124
|
end
|
|
139
125
|
|
|
126
|
+
context 'querying all documents after a single document' do
|
|
127
|
+
before do
|
|
128
|
+
3.times do
|
|
129
|
+
Person.create
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'returns all documents' do
|
|
134
|
+
expect(Person.all.to_a.count).to eq(3)
|
|
135
|
+
Person.first
|
|
136
|
+
expect(Person.all.to_a.count).to eq(3)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
context 'with conditions specified' do
|
|
140
|
+
it 'returns all documents' do
|
|
141
|
+
expect(Person.gt(age: 0).to_a.count).to eq(3)
|
|
142
|
+
Person.gt(age: 0).first
|
|
143
|
+
expect(Person.gt(age: 0).to_a.count).to eq(3)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
context 'with order specified' do
|
|
148
|
+
it 'returns all documents' do
|
|
149
|
+
expect(Person.order_by(name: 1).to_a.count).to eq(3)
|
|
150
|
+
Person.order_by(name: 1).first
|
|
151
|
+
expect(Person.order_by(name: 1).to_a.count).to eq(3)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
140
156
|
context "when querying in the same collection" do
|
|
141
157
|
|
|
142
158
|
before do
|
|
@@ -425,18 +441,18 @@ describe Mongoid::QueryCache do
|
|
|
425
441
|
end
|
|
426
442
|
end
|
|
427
443
|
|
|
428
|
-
context "when querying
|
|
444
|
+
context "when querying collection smaller than the batch size" do
|
|
429
445
|
|
|
430
446
|
before do
|
|
431
|
-
|
|
447
|
+
99.times { Band.create! }
|
|
432
448
|
end
|
|
433
449
|
|
|
434
450
|
it "returns the right number of records" do
|
|
435
|
-
expect(Band.all.to_a.length).to eq(
|
|
451
|
+
expect(Band.all.to_a.length).to eq(99)
|
|
436
452
|
end
|
|
437
453
|
|
|
438
454
|
it "#pluck returns the same count of objects" do
|
|
439
|
-
expect(Band.pluck(:name).length).to eq(
|
|
455
|
+
expect(Band.pluck(:name).length).to eq(99)
|
|
440
456
|
end
|
|
441
457
|
|
|
442
458
|
context "when loading all the documents" do
|
|
@@ -447,12 +463,12 @@ describe Mongoid::QueryCache do
|
|
|
447
463
|
|
|
448
464
|
it "caches the complete result of the query" do
|
|
449
465
|
expect_no_queries do
|
|
450
|
-
expect(Band.all.to_a.length).to eq(
|
|
466
|
+
expect(Band.all.to_a.length).to eq(99)
|
|
451
467
|
end
|
|
452
468
|
end
|
|
453
469
|
|
|
454
470
|
it "returns the same count of objects when using #pluck" do
|
|
455
|
-
expect(Band.pluck(:name).length).to eq(
|
|
471
|
+
expect(Band.pluck(:name).length).to eq(99)
|
|
456
472
|
end
|
|
457
473
|
end
|
|
458
474
|
end
|
|
@@ -464,6 +480,29 @@ describe Mongoid::QueryCache do
|
|
|
464
480
|
Band.collection.indexes.create_one(name: 1)
|
|
465
481
|
end
|
|
466
482
|
end
|
|
483
|
+
|
|
484
|
+
context 'when the initial query does not exhaust the results' do
|
|
485
|
+
before do
|
|
486
|
+
Mongoid::QueryCache.enabled = true
|
|
487
|
+
10.times { Band.create! }
|
|
488
|
+
|
|
489
|
+
Band.batch_size(4).all.any?
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
it 'does not cache the result' do
|
|
493
|
+
expect(Band.all.map(&:id).size).to eq(10)
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
context 'when a batch size smaller than the result set is specified' do
|
|
497
|
+
let(:batch_size) do
|
|
498
|
+
4
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
it 'does not cache the result' do
|
|
502
|
+
expect(Band.batch_size(batch_size).all.map(&:id).size).to eq(10)
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
end
|
|
467
506
|
end
|
|
468
507
|
|
|
469
508
|
describe Mongoid::QueryCache::Middleware do
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Mongoid::Relations::Proxy do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
end
|
|
1
|
+
# require "spec_helper"
|
|
2
|
+
#
|
|
3
|
+
# describe Mongoid::Relations::Proxy do
|
|
4
|
+
#
|
|
5
|
+
# describe '#with', if: non_legacy_server? do
|
|
6
|
+
#
|
|
7
|
+
# let(:circus) do
|
|
8
|
+
# Circus.new
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# let(:animal) do
|
|
12
|
+
# Animal.new
|
|
13
|
+
# end
|
|
14
|
+
#
|
|
15
|
+
# before do
|
|
16
|
+
# circus.animals << animal
|
|
17
|
+
# circus.save
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# it 'uses the new persistence options' do
|
|
21
|
+
# expect {
|
|
22
|
+
# animal.with(write: { w: 100 }) do |an|
|
|
23
|
+
# an.update_attribute(:name, 'kangaroo')
|
|
24
|
+
# end
|
|
25
|
+
# }.to raise_exception(Mongo::Error::OperationFailure)
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
#
|
|
29
|
+
# describe "#find" do
|
|
30
|
+
# let(:person) do
|
|
31
|
+
# Person.create
|
|
32
|
+
# end
|
|
33
|
+
#
|
|
34
|
+
# let(:messages) do
|
|
35
|
+
# person.messages
|
|
36
|
+
# end
|
|
37
|
+
#
|
|
38
|
+
# let(:msg1) do
|
|
39
|
+
# messages.create(body: 'msg1')
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# it "returns nil with no arguments" do
|
|
43
|
+
# expect(messages.find).to be_nil
|
|
44
|
+
# expect(messages.send(:find)).to be_nil
|
|
45
|
+
# expect(messages.__send__(:find)).to be_nil
|
|
46
|
+
# expect(messages.public_send(:find)).to be_nil
|
|
47
|
+
# end
|
|
48
|
+
#
|
|
49
|
+
# it "returns the object corresponding to the id" do
|
|
50
|
+
# expect(messages.find(msg1.id)).to eq(msg1)
|
|
51
|
+
# expect(messages.send(:find, msg1.id)).to eq(msg1)
|
|
52
|
+
# expect(messages.__send__(:find, msg1.id)).to eq(msg1)
|
|
53
|
+
# expect(messages.public_send(:find, msg1.id)).to eq(msg1)
|
|
54
|
+
# end
|
|
55
|
+
# end
|
|
56
|
+
#
|
|
57
|
+
# describe "#extend" do
|
|
58
|
+
#
|
|
59
|
+
# before(:all) do
|
|
60
|
+
# Person.reset_callbacks(:validate)
|
|
61
|
+
# module Testable
|
|
62
|
+
# end
|
|
63
|
+
# end
|
|
64
|
+
#
|
|
65
|
+
# after(:all) do
|
|
66
|
+
# Object.send(:remove_const, :Testable)
|
|
67
|
+
# end
|
|
68
|
+
#
|
|
69
|
+
# let(:person) do
|
|
70
|
+
# Person.create
|
|
71
|
+
# end
|
|
72
|
+
#
|
|
73
|
+
# let(:name) do
|
|
74
|
+
# person.build_name
|
|
75
|
+
# end
|
|
76
|
+
#
|
|
77
|
+
# before do
|
|
78
|
+
# name.namable.extend(Testable)
|
|
79
|
+
# end
|
|
80
|
+
#
|
|
81
|
+
# it "extends the proxied object" do
|
|
82
|
+
# expect(person).to be_a(Testable)
|
|
83
|
+
# end
|
|
84
|
+
#
|
|
85
|
+
# context "when extending from the relation definition" do
|
|
86
|
+
#
|
|
87
|
+
# let!(:address) do
|
|
88
|
+
# person.addresses.create(street: "hobrecht")
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# let(:found) do
|
|
92
|
+
# person.addresses.find_by_street("hobrecht")
|
|
93
|
+
# end
|
|
94
|
+
#
|
|
95
|
+
# it "extends the proxy" do
|
|
96
|
+
# expect(found).to eq(address)
|
|
97
|
+
# end
|
|
98
|
+
# end
|
|
99
|
+
# end
|
|
100
|
+
#
|
|
101
|
+
# describe "equality" do
|
|
102
|
+
# let(:messages) do
|
|
103
|
+
# Person.create.messages
|
|
104
|
+
# end
|
|
105
|
+
#
|
|
106
|
+
# it "is #equal? to itself" do
|
|
107
|
+
# expect(messages.equal?(messages)).to eq(true)
|
|
108
|
+
# end
|
|
109
|
+
#
|
|
110
|
+
# it "is == to itself" do
|
|
111
|
+
# expect(messages == messages).to eq(true)
|
|
112
|
+
# end
|
|
113
|
+
#
|
|
114
|
+
# it "is not #equal? to its target" do
|
|
115
|
+
# expect(messages.equal?(messages.target)).to eq(false)
|
|
116
|
+
# expect(messages.target.equal?(messages)).to eq(false)
|
|
117
|
+
# end
|
|
118
|
+
#
|
|
119
|
+
# it "is == to its target" do
|
|
120
|
+
# expect(messages == messages.target).to eq(true)
|
|
121
|
+
# expect(messages.target == messages).to eq(true)
|
|
122
|
+
# end
|
|
123
|
+
# end
|
|
124
|
+
# end
|
|
@@ -1130,6 +1130,19 @@ describe Mongoid::Scopable do
|
|
|
1130
1130
|
it "sets the threading options" do
|
|
1131
1131
|
Band.without_default_scope do
|
|
1132
1132
|
expect(Mongoid::Threaded).to be_executing(:without_default_scope)
|
|
1133
|
+
expect(Mongoid::Threaded.without_default_scope?(Band)).to be(true)
|
|
1134
|
+
end
|
|
1135
|
+
end
|
|
1136
|
+
|
|
1137
|
+
it "suppresses default scope on the given model within the given block" do
|
|
1138
|
+
Appointment.without_default_scope do
|
|
1139
|
+
expect(Appointment.all.selector).to be_empty
|
|
1140
|
+
end
|
|
1141
|
+
end
|
|
1142
|
+
|
|
1143
|
+
it "does not affect other models' default scopes within the given block" do
|
|
1144
|
+
Appointment.without_default_scope do
|
|
1145
|
+
expect(Audio.all.selector).not_to be_empty
|
|
1133
1146
|
end
|
|
1134
1147
|
end
|
|
1135
1148
|
end
|
|
@@ -49,23 +49,43 @@ describe Mongoid::Shardable do
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
describe
|
|
52
|
+
describe '#shard_key_selector' do
|
|
53
|
+
subject { instance.shard_key_selector }
|
|
54
|
+
let(:klass) { Band }
|
|
55
|
+
let(:value) { 'a-brand-name' }
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
Band
|
|
56
|
-
end
|
|
57
|
+
before { klass.shard_key(:name) }
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
klass.new
|
|
60
|
-
end
|
|
59
|
+
context 'when record is new' do
|
|
60
|
+
let(:instance) { klass.new(name: value) }
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
it { is_expected.to eq({ 'name' => value }) }
|
|
63
|
+
|
|
64
|
+
context 'changing shard key value' do
|
|
65
|
+
let(:new_value) { 'a-new-value' }
|
|
66
|
+
|
|
67
|
+
before do
|
|
68
|
+
instance.name = new_value
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it { is_expected.to eq({ 'name' => new_value }) }
|
|
72
|
+
end
|
|
65
73
|
end
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
context 'when record is persisted' do
|
|
76
|
+
let(:instance) { klass.create(name: value) }
|
|
77
|
+
|
|
78
|
+
it { is_expected.to eq({ 'name' => value }) }
|
|
79
|
+
|
|
80
|
+
context 'changing shard key value' do
|
|
81
|
+
let(:new_value) { 'a-new-value' }
|
|
82
|
+
|
|
83
|
+
before do
|
|
84
|
+
instance.name = new_value
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it { is_expected.to eq({ 'name' => value }) }
|
|
88
|
+
end
|
|
69
89
|
end
|
|
70
90
|
end
|
|
71
91
|
end
|
|
@@ -233,4 +233,72 @@ describe Mongoid::Threaded do
|
|
|
233
233
|
end
|
|
234
234
|
end
|
|
235
235
|
end
|
|
236
|
+
|
|
237
|
+
describe "#begin_without_default_scope" do
|
|
238
|
+
|
|
239
|
+
let(:klass) do
|
|
240
|
+
Appointment
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
after do
|
|
244
|
+
described_class.exit_without_default_scope(klass)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
it "adds the given class to the without_default_scope stack" do
|
|
248
|
+
described_class.begin_without_default_scope(klass)
|
|
249
|
+
|
|
250
|
+
expect(described_class.stack(:without_default_scope)).to include(klass)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
describe "#exit_without_default_scope" do
|
|
255
|
+
|
|
256
|
+
let(:klass) do
|
|
257
|
+
Appointment
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
before do
|
|
261
|
+
described_class.begin_without_default_scope(klass)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
it "removes the given class from the without_default_scope stack" do
|
|
265
|
+
described_class.exit_without_default_scope(klass)
|
|
266
|
+
|
|
267
|
+
expect(described_class.stack(:without_default_scope)).not_to include(klass)
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
describe "#without_default_scope?" do
|
|
272
|
+
|
|
273
|
+
let(:klass) do
|
|
274
|
+
Appointment
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
context "when klass has begun without_default_scope" do
|
|
278
|
+
|
|
279
|
+
before do
|
|
280
|
+
described_class.begin_without_default_scope(klass)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
after do
|
|
284
|
+
described_class.exit_without_default_scope(klass)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
it "returns true" do
|
|
288
|
+
expect(described_class.without_default_scope?(klass)).to be(true)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
context "when klass has exited without_default_scope" do
|
|
293
|
+
|
|
294
|
+
before do
|
|
295
|
+
described_class.begin_without_default_scope(klass)
|
|
296
|
+
described_class.exit_without_default_scope(klass)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
it "returns false" do
|
|
300
|
+
expect(described_class.without_default_scope?(klass)).to be(false)
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
end
|
|
236
304
|
end
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
|
-
describe Mongoid::
|
|
3
|
+
describe Mongoid::Touchable do
|
|
4
4
|
|
|
5
5
|
describe "#touch" do
|
|
6
6
|
|
|
7
|
+
context "when the document has no associations" do
|
|
8
|
+
let(:updatable) do
|
|
9
|
+
Updatable.create
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "responds to #touch" do
|
|
13
|
+
expect(updatable).to respond_to(:touch)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "updates the timestamp when called" do
|
|
17
|
+
expect(updatable.updated_at).to be_nil
|
|
18
|
+
|
|
19
|
+
updatable.touch
|
|
20
|
+
updated_at = updatable.updated_at
|
|
21
|
+
expect(updated_at).not_to be_nil
|
|
22
|
+
|
|
23
|
+
updatable.touch
|
|
24
|
+
expect(updatable.updated_at).to be > updated_at
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
7
28
|
context "when the document is embedded" do
|
|
8
29
|
|
|
30
|
+
before do
|
|
31
|
+
Label.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
32
|
+
end
|
|
33
|
+
|
|
9
34
|
let(:band) do
|
|
10
35
|
Band.create(name: "Placebo")
|
|
11
36
|
end
|
|
@@ -29,6 +54,11 @@ describe Mongoid::Relations::Touchable do
|
|
|
29
54
|
|
|
30
55
|
context "when no relations have touch options" do
|
|
31
56
|
|
|
57
|
+
before do
|
|
58
|
+
Person.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
59
|
+
Agent.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
60
|
+
end
|
|
61
|
+
|
|
32
62
|
context "when no updated at is defined" do
|
|
33
63
|
|
|
34
64
|
let(:person) do
|
|
@@ -209,6 +239,11 @@ describe Mongoid::Relations::Touchable do
|
|
|
209
239
|
|
|
210
240
|
context "when the relation is a parent of an embedded doc" do
|
|
211
241
|
|
|
242
|
+
before do
|
|
243
|
+
Page.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
244
|
+
Edit.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
245
|
+
end
|
|
246
|
+
|
|
212
247
|
let(:page) do
|
|
213
248
|
WikiPage.create(title: "test")
|
|
214
249
|
end
|
|
@@ -229,6 +264,10 @@ describe Mongoid::Relations::Touchable do
|
|
|
229
264
|
|
|
230
265
|
context "when the parent of embedded doc has cascade callbacks" do
|
|
231
266
|
|
|
267
|
+
before do
|
|
268
|
+
Band.send(:include, Mongoid::Touchable::InstanceMethods)
|
|
269
|
+
end
|
|
270
|
+
|
|
232
271
|
let!(:book) do
|
|
233
272
|
Book.new
|
|
234
273
|
end
|
|
@@ -171,7 +171,7 @@ describe Mongoid::Validatable::AssociatedValidator do
|
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
-
context "when the
|
|
174
|
+
context "when the association has all valid documents" do
|
|
175
175
|
|
|
176
176
|
let(:associated) do
|
|
177
177
|
double(valid?: true, flagged_for_destroy?: false)
|