mongoid 6.4.8 → 7.0.0
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
- checksums.yaml.gz.sig +0 -0
- data/Rakefile +0 -26
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +116 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +21 -21
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +529 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +20 -50
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +31 -58
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +159 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +310 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +415 -0
- data/lib/mongoid/association/touchable.rb +97 -0
- data/lib/mongoid/association.rb +150 -0
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +10 -10
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/sessions.rb +2 -2
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -4
- data/lib/mongoid/contextual/memory.rb +25 -7
- data/lib/mongoid/contextual/mongo.rb +13 -11
- data/lib/mongoid/copyable.rb +6 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +10 -34
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +6 -6
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +5 -2
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +0 -1
- data/lib/mongoid/extensions/string.rb +1 -3
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/fields.rb +3 -3
- data/lib/mongoid/indexable.rb +8 -5
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable.rb +0 -3
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +9 -8
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +5 -6
- data/lib/mongoid/persistence_context.rb +1 -5
- data/lib/mongoid/query_cache.rb +19 -64
- data/lib/mongoid/railtie.rb +0 -17
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/tasks/database.rb +2 -2
- data/lib/mongoid/threaded.rb +0 -36
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +1 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +1 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +613 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +140 -428
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -73
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +7 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +9 -9
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +1963 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +5 -5
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_spec.rb +1244 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations → association}/touchable_spec.rb +19 -1
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +14 -12
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +28 -52
- data/spec/mongoid/clients/options_spec.rb +65 -69
- data/spec/mongoid/clients/sessions_spec.rb +4 -13
- data/spec/mongoid/config_spec.rb +24 -0
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +30 -5
- data/spec/mongoid/copyable_spec.rb +34 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +43 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +3 -42
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +0 -81
- data/spec/mongoid/criteria_spec.rb +16 -19
- data/spec/mongoid/document_spec.rb +2 -56
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/extensions/regexp_spec.rb +0 -23
- data/spec/mongoid/extensions/string_spec.rb +7 -35
- data/spec/mongoid/factory_spec.rb +19 -1
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +2 -2
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +18 -8
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable_spec.rb +1 -26
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +1 -35
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/query_cache_spec.rb +16 -99
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +0 -13
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +0 -68
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -14
- data.tar.gz.sig +1 -1
- metadata +192 -207
- metadata.gz.sig +0 -0
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/railties/controller_runtime.rb +0 -86
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/lib/mongoid/relations.rb +0 -148
- data/spec/app/models/array_field.rb +0 -7
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/integration/document_spec.rb +0 -22
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/rails/controller_extension/controller_runtime_spec.rb +0 -110
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/constraints.rb +0 -101
- data/spec/support/macros.rb +0 -20
- data/spec/support/session_registry.rb +0 -50
- data/spec/support/spec_config.rb +0 -42
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
|
@@ -7,20 +7,6 @@ describe Mongoid::QueryCache do
|
|
|
7
7
|
Mongoid::QueryCache.cache { spec.run }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
before(:all) do
|
|
11
|
-
# It is likely that there are other session leaks in the driver
|
|
12
|
-
# and/or Mongoid that are unrelated to the query cache. Clear the
|
|
13
|
-
# SessionRegistry at the start of these tests in order to detect leaks that
|
|
14
|
-
# occur only within the scope of these tests.
|
|
15
|
-
#
|
|
16
|
-
# Other session leaks will be detected and addressed as part of RUBY-2391.
|
|
17
|
-
SessionRegistry.instance.clear_registry
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
after do
|
|
21
|
-
SessionRegistry.instance.verify_sessions_ended!
|
|
22
|
-
end
|
|
23
|
-
|
|
24
10
|
context 'when iterating over objects sharing the same base' do
|
|
25
11
|
|
|
26
12
|
let(:server) do
|
|
@@ -45,32 +31,16 @@ describe Mongoid::QueryCache do
|
|
|
45
31
|
:posts
|
|
46
32
|
end
|
|
47
33
|
|
|
48
|
-
context '
|
|
34
|
+
context 'does not query for the relation and instead sets the base' do
|
|
49
35
|
|
|
50
36
|
before do
|
|
51
37
|
Mongoid::QueryCache.enabled = false
|
|
52
38
|
end
|
|
53
39
|
|
|
54
40
|
it 'queries for each access to the base' do
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'when query cache is enabled' do
|
|
64
|
-
|
|
65
|
-
before do
|
|
66
|
-
Mongoid::QueryCache.enabled = true
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'queries only once for the base' do
|
|
70
|
-
expect_query(1) do
|
|
71
|
-
relations.each do |object|
|
|
72
|
-
object.person
|
|
73
|
-
end
|
|
41
|
+
expect(server).to receive(:with_connection).exactly(0).times.and_call_original
|
|
42
|
+
relations.each do |object|
|
|
43
|
+
object.person
|
|
74
44
|
end
|
|
75
45
|
end
|
|
76
46
|
end
|
|
@@ -221,10 +191,6 @@ describe Mongoid::QueryCache do
|
|
|
221
191
|
end
|
|
222
192
|
|
|
223
193
|
before do
|
|
224
|
-
10.times do |i|
|
|
225
|
-
game.ratings << Rating.create!(value: i+1)
|
|
226
|
-
end
|
|
227
|
-
|
|
228
194
|
game.ratings.where(:value.gt => 5).asc(:id).all.to_a
|
|
229
195
|
end
|
|
230
196
|
|
|
@@ -232,9 +198,7 @@ describe Mongoid::QueryCache do
|
|
|
232
198
|
|
|
233
199
|
it "uses the cache" do
|
|
234
200
|
expect_no_queries do
|
|
235
|
-
|
|
236
|
-
expect(result.length).to eq(2)
|
|
237
|
-
expect(result.map { |r| r['value'] }).to eq([6, 7])
|
|
201
|
+
game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
|
|
238
202
|
end
|
|
239
203
|
end
|
|
240
204
|
end
|
|
@@ -247,23 +211,14 @@ describe Mongoid::QueryCache do
|
|
|
247
211
|
end
|
|
248
212
|
|
|
249
213
|
before do
|
|
250
|
-
10.times do |i|
|
|
251
|
-
game.ratings << Rating.create!(value: i+1)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
214
|
game.ratings.where(:value.gt => 5).limit(3).asc(:id).all.to_a
|
|
255
215
|
end
|
|
256
216
|
|
|
257
217
|
context "when the next query has a limit" do
|
|
258
|
-
# Server versions older than 3.2 also perform a killCursors operation,
|
|
259
|
-
# which causes this test to fail.
|
|
260
|
-
min_server_version '3.2'
|
|
261
218
|
|
|
262
219
|
it "queries again" do
|
|
263
220
|
expect_query(1) do
|
|
264
|
-
|
|
265
|
-
expect(result.length).to eq(2)
|
|
266
|
-
expect(result.map { |r| r['value'] }).to eq([6, 7])
|
|
221
|
+
game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
|
|
267
222
|
end
|
|
268
223
|
end
|
|
269
224
|
end
|
|
@@ -272,9 +227,7 @@ describe Mongoid::QueryCache do
|
|
|
272
227
|
|
|
273
228
|
it "queries again" do
|
|
274
229
|
expect_query(1) do
|
|
275
|
-
|
|
276
|
-
expect(result.length).to eq(5)
|
|
277
|
-
expect(result.map { |r| r['value'] }).to eq([6, 7, 8, 9, 10])
|
|
230
|
+
game.ratings.where(:value.gt => 5).asc(:id).to_a
|
|
278
231
|
end
|
|
279
232
|
end
|
|
280
233
|
end
|
|
@@ -287,34 +240,21 @@ describe Mongoid::QueryCache do
|
|
|
287
240
|
end
|
|
288
241
|
|
|
289
242
|
before do
|
|
290
|
-
10.times do |i|
|
|
291
|
-
game.ratings << Rating.create!(value: i+1)
|
|
292
|
-
end
|
|
293
|
-
|
|
294
243
|
game.ratings.where(:value.gt => 5).asc(:id).all.to_a
|
|
295
244
|
end
|
|
296
245
|
|
|
297
246
|
it "does not query again" do
|
|
298
247
|
expect_no_queries do
|
|
299
|
-
|
|
300
|
-
expect(result['value']).to eq(6)
|
|
248
|
+
game.ratings.where(:value.gt => 5).asc(:id).first
|
|
301
249
|
end
|
|
302
250
|
end
|
|
303
251
|
end
|
|
304
252
|
|
|
305
253
|
context "when limiting the result" do
|
|
306
|
-
before do
|
|
307
|
-
Band.destroy_all
|
|
308
|
-
|
|
309
|
-
5.times { |i| Band.create!(name: "Band #{i}") }
|
|
310
|
-
Band.all.to_a
|
|
311
|
-
end
|
|
312
254
|
|
|
313
255
|
it "does not query again" do
|
|
314
256
|
expect_query(0) do
|
|
315
|
-
|
|
316
|
-
expect(result.length).to eq(2)
|
|
317
|
-
expect(result.map { |r| r["name"] }).to eq(["Band 0", "Band 1"])
|
|
257
|
+
Band.limit(2).all.to_a
|
|
318
258
|
end
|
|
319
259
|
end
|
|
320
260
|
end
|
|
@@ -322,16 +262,12 @@ describe Mongoid::QueryCache do
|
|
|
322
262
|
context "when specifying a different skip value" do
|
|
323
263
|
|
|
324
264
|
before do
|
|
325
|
-
Band.
|
|
326
|
-
|
|
327
|
-
5.times { |i| Band.create!(name: "Band #{i}") }
|
|
265
|
+
Band.limit(2).skip(1).all.to_a
|
|
328
266
|
end
|
|
329
267
|
|
|
330
268
|
it "queries again" do
|
|
331
269
|
expect_query(1) do
|
|
332
|
-
|
|
333
|
-
expect(result.length).to eq(2)
|
|
334
|
-
expect(result.map { |r| r["name"] }).to eq(["Band 3", "Band 4"])
|
|
270
|
+
Band.limit(2).skip(3).all.to_a
|
|
335
271
|
end
|
|
336
272
|
end
|
|
337
273
|
end
|
|
@@ -367,25 +303,6 @@ describe Mongoid::QueryCache do
|
|
|
367
303
|
end
|
|
368
304
|
end
|
|
369
305
|
|
|
370
|
-
context 'when querying colleciton larger than the batch size' do
|
|
371
|
-
before do
|
|
372
|
-
Band.destroy_all
|
|
373
|
-
101.times { |i| Band.create!(_id: i) }
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
it 'does not raise an exception when querying multiple times' do
|
|
377
|
-
expect do
|
|
378
|
-
results1 = Band.all.to_a
|
|
379
|
-
expect(results1.length).to eq(101)
|
|
380
|
-
expect(results1.map { |band| band["_id"] }).to eq([*0..100])
|
|
381
|
-
|
|
382
|
-
results2 = Band.all.to_a
|
|
383
|
-
expect(results2.length).to eq(101)
|
|
384
|
-
expect(results2.map { |band| band["_id"] }).to eq([*0..100])
|
|
385
|
-
end.not_to raise_error
|
|
386
|
-
end
|
|
387
|
-
end
|
|
388
|
-
|
|
389
306
|
context "when query caching is enabled and the batch_size is set" do
|
|
390
307
|
|
|
391
308
|
around(:each) do |example|
|
|
@@ -497,15 +414,15 @@ describe Mongoid::QueryCache do
|
|
|
497
414
|
context "when querying a very large collection" do
|
|
498
415
|
|
|
499
416
|
before do
|
|
500
|
-
|
|
417
|
+
123.times { Band.create! }
|
|
501
418
|
end
|
|
502
419
|
|
|
503
420
|
it "returns the right number of records" do
|
|
504
|
-
expect(Band.all.to_a.length).to eq(
|
|
421
|
+
expect(Band.all.to_a.length).to eq(123)
|
|
505
422
|
end
|
|
506
423
|
|
|
507
424
|
it "#pluck returns the same count of objects" do
|
|
508
|
-
expect(Band.pluck(:name).length).to eq(
|
|
425
|
+
expect(Band.pluck(:name).length).to eq(123)
|
|
509
426
|
end
|
|
510
427
|
|
|
511
428
|
context "when loading all the documents" do
|
|
@@ -516,12 +433,12 @@ describe Mongoid::QueryCache do
|
|
|
516
433
|
|
|
517
434
|
it "caches the complete result of the query" do
|
|
518
435
|
expect_no_queries do
|
|
519
|
-
expect(Band.all.to_a.length).to eq(
|
|
436
|
+
expect(Band.all.to_a.length).to eq(123)
|
|
520
437
|
end
|
|
521
438
|
end
|
|
522
439
|
|
|
523
440
|
it "returns the same count of objects when using #pluck" do
|
|
524
|
-
expect(Band.pluck(:name).length).to eq(
|
|
441
|
+
expect(Band.pluck(:name).length).to eq(123)
|
|
525
442
|
end
|
|
526
443
|
end
|
|
527
444
|
end
|
|
@@ -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,19 +1130,6 @@ 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
|
|
1146
1133
|
end
|
|
1147
1134
|
end
|
|
1148
1135
|
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,72 +233,4 @@ 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
|
|
304
236
|
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)
|
|
@@ -211,13 +211,14 @@ describe Mongoid::Validatable::PresenceValidator do
|
|
|
211
211
|
|
|
212
212
|
context "when the relation is a has one" do
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
around do |example|
|
|
215
|
+
original_relations = Person.relations
|
|
216
|
+
Person.has_one :game, autosave: true
|
|
215
217
|
Person.validates :game, presence: true
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
after do
|
|
218
|
+
example.run
|
|
219
219
|
Person.reset_callbacks(:save)
|
|
220
220
|
Person.reset_callbacks(:validate)
|
|
221
|
+
Person.relations = original_relations
|
|
221
222
|
end
|
|
222
223
|
|
|
223
224
|
context "when the relation is new" do
|
|
@@ -249,7 +250,7 @@ describe Mongoid::Validatable::PresenceValidator do
|
|
|
249
250
|
context "when the relation is a has one and autosave is false" do
|
|
250
251
|
|
|
251
252
|
before do
|
|
252
|
-
Person.relations["game"][:autosave] = false
|
|
253
|
+
Person.relations["game"].options[:autosave] = false
|
|
253
254
|
Person.validates :game, presence: true
|
|
254
255
|
end
|
|
255
256
|
|
|
@@ -258,7 +259,7 @@ describe Mongoid::Validatable::PresenceValidator do
|
|
|
258
259
|
end
|
|
259
260
|
|
|
260
261
|
it "does not change autosave on the relation" do
|
|
261
|
-
expect(Person.relations["game"]
|
|
262
|
+
expect(Person.relations["game"].autosave?).to be false
|
|
262
263
|
end
|
|
263
264
|
|
|
264
265
|
context "when the relation is new" do
|