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,369 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Clients::Sessions do
|
|
4
|
+
|
|
5
|
+
before(:all) do
|
|
6
|
+
CONFIG[:clients][:other] = CONFIG[:clients][:default].dup
|
|
7
|
+
CONFIG[:clients][:other][:database] = 'other'
|
|
8
|
+
Mongoid::Clients.clients.values.each(&:close)
|
|
9
|
+
Mongoid::Config.send(:clients=, CONFIG[:clients])
|
|
10
|
+
Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
after(:all) do
|
|
14
|
+
Mongoid::Clients.with_name(:other).close
|
|
15
|
+
Mongoid::Clients.clients.delete(:other)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:subscriber) do
|
|
19
|
+
Mongoid::Clients.with_name(:other).send(:monitoring).subscribers['Command'].find do |s|
|
|
20
|
+
s.is_a?(EventSubscriber)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:insert_events) do
|
|
25
|
+
subscriber.started_events.select { |event| event.command_name == 'insert' }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
let(:insert_events_txn_numbers) do
|
|
29
|
+
insert_events.map { |i| i.instance_variable_get(:@integer) }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
let(:update_events) do
|
|
33
|
+
subscriber.started_events.select { |event| event.command_name == 'update' }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
let(:update_events_txn_numbers) do
|
|
37
|
+
update_events.map { |i| i.instance_variable_get(:@integer) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
let(:other_events) do
|
|
41
|
+
subscriber.started_events.reject { |event| ['insert', 'update'].include?(event.command_name) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'when a transaction is used on a model class' do
|
|
45
|
+
|
|
46
|
+
context 'when transactions are supported', if: testing_transactions? do
|
|
47
|
+
|
|
48
|
+
around do |example|
|
|
49
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
50
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
51
|
+
Mongoid::Clients.with_name(:other).command(create: :posts)
|
|
52
|
+
subscriber.clear_events!
|
|
53
|
+
Person.with(client: :other) do
|
|
54
|
+
example.run
|
|
55
|
+
end
|
|
56
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context 'when another thread is started' do
|
|
60
|
+
|
|
61
|
+
let!(:last_use_diff) do
|
|
62
|
+
Person.with_session do |s|
|
|
63
|
+
s.start_transaction
|
|
64
|
+
Person.create
|
|
65
|
+
Person.create
|
|
66
|
+
Thread.new { Person.create }.value
|
|
67
|
+
s.commit_transaction
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'does not use the transaction for that thread' do
|
|
72
|
+
expect(Person.count).to be(2)
|
|
73
|
+
expect(Person.with(client: :default) { Person.count }).to be(1)
|
|
74
|
+
expect(insert_events.count { |e| e.command['startTransaction'] }).to be(1)
|
|
75
|
+
expect(other_events.count { |e| e.command_name == 'commitTransaction' }).to be(1)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'when the operations in the transactions block are all on the class' do
|
|
80
|
+
|
|
81
|
+
before do
|
|
82
|
+
Person.with_session do |s|
|
|
83
|
+
s.start_transaction
|
|
84
|
+
Person.create
|
|
85
|
+
Person.create
|
|
86
|
+
s.commit_transaction
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
91
|
+
expect(Person.count).to be(2)
|
|
92
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
93
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context 'when the operations in the transactions block are also on another class' do
|
|
98
|
+
|
|
99
|
+
context 'when the other class uses the same client' do
|
|
100
|
+
|
|
101
|
+
before do
|
|
102
|
+
Post.with(client: :other) do
|
|
103
|
+
Person.with_session do |s|
|
|
104
|
+
s.start_transaction
|
|
105
|
+
Person.create
|
|
106
|
+
Person.create
|
|
107
|
+
Post.create
|
|
108
|
+
s.commit_transaction
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
114
|
+
expect(Post.with(client: :other) { |klass| klass.count }).to be(1)
|
|
115
|
+
expect(insert_events_txn_numbers.size).to eq(3)
|
|
116
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
context 'when the other class uses a different client' do
|
|
121
|
+
|
|
122
|
+
let!(:error) do
|
|
123
|
+
e = nil
|
|
124
|
+
begin
|
|
125
|
+
Person.with_session do |s|
|
|
126
|
+
s.start_transaction
|
|
127
|
+
Person.create
|
|
128
|
+
Person.create
|
|
129
|
+
Post.create
|
|
130
|
+
s.commit_transaction
|
|
131
|
+
end
|
|
132
|
+
rescue => ex
|
|
133
|
+
e = ex
|
|
134
|
+
end
|
|
135
|
+
e
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it 'raises an error' do
|
|
139
|
+
expect(error).to be_a(Mongoid::Errors::InvalidSessionUse)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'aborted the transaction' do
|
|
143
|
+
expect(Person.count).to be(0)
|
|
144
|
+
expect(Post.count).to be(0)
|
|
145
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
146
|
+
expect(other_events.count { |e| e.command_name == 'abortTransaction'}).to be(1)
|
|
147
|
+
expect(other_events.count { |e| e.command_name == 'commitTransaction'}).to be(0)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context 'when transactions are nested' do
|
|
152
|
+
|
|
153
|
+
let!(:error) do
|
|
154
|
+
e = nil
|
|
155
|
+
begin
|
|
156
|
+
Person.with_session do |s|
|
|
157
|
+
s.start_transaction
|
|
158
|
+
s.start_transaction
|
|
159
|
+
Person.create
|
|
160
|
+
Post.create
|
|
161
|
+
s.commit_transaction
|
|
162
|
+
end
|
|
163
|
+
rescue => ex
|
|
164
|
+
e = ex
|
|
165
|
+
end
|
|
166
|
+
e
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'raises an error' do
|
|
170
|
+
expect(error).to be_a(Mongo::Error::InvalidTransactionOperation)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'does not execute any operations' do
|
|
174
|
+
expect(Person.count).to be(0)
|
|
175
|
+
expect(Post.count).to be(0)
|
|
176
|
+
expect(insert_events).to be_empty
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
|
|
183
|
+
|
|
184
|
+
let!(:error) do
|
|
185
|
+
e = nil
|
|
186
|
+
begin
|
|
187
|
+
Person.with_session do |s|
|
|
188
|
+
s.start_transaction
|
|
189
|
+
Person.create
|
|
190
|
+
s.commit_transaction
|
|
191
|
+
end
|
|
192
|
+
rescue => ex
|
|
193
|
+
e = ex
|
|
194
|
+
end
|
|
195
|
+
e
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it 'raises a transactions not supported error' do
|
|
199
|
+
expect(Person.count).to eq(0)
|
|
200
|
+
expect(error).to be_a(Mongo::Error::OperationFailure)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
context 'when a transaction is used on a model instance' do
|
|
206
|
+
|
|
207
|
+
let!(:person) do
|
|
208
|
+
Person.with(client: :other) do |klass|
|
|
209
|
+
klass.create
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
context 'when transactions are supported', if: testing_transactions? do
|
|
214
|
+
|
|
215
|
+
around do |example|
|
|
216
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
217
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
218
|
+
Mongoid::Clients.with_name(:other).command(create: :posts)
|
|
219
|
+
subscriber.clear_events!
|
|
220
|
+
person.with(client: :other) do
|
|
221
|
+
example.run
|
|
222
|
+
end
|
|
223
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
context 'when the operations in the transaction block are all on the instance' do
|
|
227
|
+
|
|
228
|
+
before do
|
|
229
|
+
person.with_session do |s|
|
|
230
|
+
s.start_transaction
|
|
231
|
+
person.username = 'Emily'
|
|
232
|
+
person.save
|
|
233
|
+
person.age = 80
|
|
234
|
+
person.save
|
|
235
|
+
s.commit_transaction
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
240
|
+
expect(person.reload.username).to eq('Emily')
|
|
241
|
+
expect(person.reload.age).to eq(80)
|
|
242
|
+
expect(update_events_txn_numbers.size).to eq(2)
|
|
243
|
+
expect(update_events_txn_numbers.uniq.size).to eq(1)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
context 'when the operations in the transaction block are also on another class' do
|
|
248
|
+
|
|
249
|
+
context 'when the other class uses the same client' do
|
|
250
|
+
|
|
251
|
+
before do
|
|
252
|
+
Post.with(client: :other) do
|
|
253
|
+
person.with_session do |s|
|
|
254
|
+
s.start_transaction
|
|
255
|
+
person.username = 'Emily'
|
|
256
|
+
person.save
|
|
257
|
+
person.posts << Post.create
|
|
258
|
+
s.commit_transaction
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
264
|
+
expect(person.reload.username).to eq('Emily')
|
|
265
|
+
expect(Post.with(client: :other) { Post.count }).to be(1)
|
|
266
|
+
expect(update_events_txn_numbers.size).to eq(3) # person update, counter cache, post assignment
|
|
267
|
+
expect(update_events_txn_numbers.uniq.size).to eq(1) # person update, counter cache, post assignment
|
|
268
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
269
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
270
|
+
expect(update_events_txn_numbers.uniq).to eq(insert_events_txn_numbers.uniq)
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
context 'when the other class uses a different client' do
|
|
275
|
+
|
|
276
|
+
let!(:error) do
|
|
277
|
+
e = nil
|
|
278
|
+
begin
|
|
279
|
+
person.with_session do |s|
|
|
280
|
+
s.start_transaction
|
|
281
|
+
person.username = 'Emily'
|
|
282
|
+
person.save
|
|
283
|
+
person.posts << Post.create
|
|
284
|
+
s.commit_transaction
|
|
285
|
+
end
|
|
286
|
+
rescue => ex
|
|
287
|
+
e = ex
|
|
288
|
+
end
|
|
289
|
+
e
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it 'raises an error' do
|
|
293
|
+
expect(error).to be_a(Mongoid::Errors::InvalidSessionUse)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it 'aborted the transction' do
|
|
297
|
+
expect(person.reload.username).not_to eq('Emily')
|
|
298
|
+
expect(Post.count).to be(0)
|
|
299
|
+
expect(update_events_txn_numbers.size).to eq(1)
|
|
300
|
+
expect(insert_events_txn_numbers.size).to eq(1)
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
context 'when transactions are nested' do
|
|
305
|
+
|
|
306
|
+
let!(:error) do
|
|
307
|
+
e = nil
|
|
308
|
+
begin
|
|
309
|
+
person.with_session do |s|
|
|
310
|
+
s.start_transaction
|
|
311
|
+
s.start_transaction
|
|
312
|
+
person.username = 'Emily'
|
|
313
|
+
person.save
|
|
314
|
+
person.posts << Post.create
|
|
315
|
+
s.commit_transaction
|
|
316
|
+
end
|
|
317
|
+
rescue => ex
|
|
318
|
+
e = ex
|
|
319
|
+
end
|
|
320
|
+
e
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
it 'raises an error' do
|
|
324
|
+
expect(error).to be_a(Mongo::Error::InvalidTransactionOperation)
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
it 'does not execute any operations' do
|
|
328
|
+
expect(person.reload.username).not_to eq('Emily')
|
|
329
|
+
expect(Post.count).to be(0)
|
|
330
|
+
expect(update_events).to be_empty
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
|
|
337
|
+
|
|
338
|
+
around do |example|
|
|
339
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
340
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
341
|
+
subscriber.clear_events!
|
|
342
|
+
person.with(client: :other) do
|
|
343
|
+
example.run
|
|
344
|
+
end
|
|
345
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
let!(:error) do
|
|
349
|
+
e = nil
|
|
350
|
+
begin
|
|
351
|
+
person.with_session do |s|
|
|
352
|
+
s.start_transaction
|
|
353
|
+
person.username = 'Emily'
|
|
354
|
+
person.save
|
|
355
|
+
s.commit_transaction
|
|
356
|
+
end
|
|
357
|
+
rescue => ex
|
|
358
|
+
e = ex
|
|
359
|
+
end
|
|
360
|
+
e
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
it 'raises a sessions not supported error' do
|
|
364
|
+
expect(person.reload.username).not_to be('Emily')
|
|
365
|
+
expect(error).to be_a(Mongo::Error::OperationFailure)
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
end
|
|
@@ -208,6 +208,72 @@ describe Mongoid::Clients do
|
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
it_behaves_like "an overridden collection name at the class level"
|
|
211
|
+
|
|
212
|
+
context 'when nesting #with calls' do
|
|
213
|
+
let(:instance_collection_name) do
|
|
214
|
+
Band.with(collection: "ignore") do |klass|
|
|
215
|
+
Band.with(collection: "artists") do |klass|
|
|
216
|
+
klass.new.collection_name
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
let(:class_collection_name) do
|
|
222
|
+
Band.with(collection: "ignore") do |klass|
|
|
223
|
+
Band.with(collection: "artists") do |klass|
|
|
224
|
+
klass.collection_name
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
context 'when outer #with call specifies the collection' do
|
|
233
|
+
use_spec_mongoid_config
|
|
234
|
+
|
|
235
|
+
let(:instance_collection_name) do
|
|
236
|
+
Band.with(collection: "artists") do |klass|
|
|
237
|
+
Band.with(client: :reports) do |klass|
|
|
238
|
+
klass.new.collection_name
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
let(:class_collection_name) do
|
|
244
|
+
Band.with(collection: "artists") do |klass|
|
|
245
|
+
Band.with(client: :reports) do |klass|
|
|
246
|
+
klass.collection_name
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context 'restores outer context in outer block' do
|
|
255
|
+
use_spec_mongoid_config
|
|
256
|
+
|
|
257
|
+
let(:instance_collection_name) do
|
|
258
|
+
Band.with(collection: "artists") do |klass|
|
|
259
|
+
Band.with(collection: "scratch") do |klass|
|
|
260
|
+
# nothing
|
|
261
|
+
end
|
|
262
|
+
klass.new.collection_name
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
let(:class_collection_name) do
|
|
267
|
+
Band.with(collection: "artists") do |klass|
|
|
268
|
+
Band.with(collection: "scratch") do |klass|
|
|
269
|
+
# nothing
|
|
270
|
+
end
|
|
271
|
+
klass.collection_name
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
276
|
+
end
|
|
211
277
|
end
|
|
212
278
|
|
|
213
279
|
context "when overriding store_in and persistence options" do
|
|
@@ -427,7 +493,7 @@ describe Mongoid::Clients do
|
|
|
427
493
|
let(:client_name) { :alternative }
|
|
428
494
|
|
|
429
495
|
before do
|
|
430
|
-
Mongoid.clients[client_name] = { database: database_id_alt, hosts:
|
|
496
|
+
Mongoid.clients[client_name] = { database: database_id_alt, hosts: SpecConfig.instance.addresses }
|
|
431
497
|
end
|
|
432
498
|
|
|
433
499
|
after do
|
|
@@ -552,20 +618,14 @@ describe Mongoid::Clients do
|
|
|
552
618
|
end
|
|
553
619
|
|
|
554
620
|
context "when getting a client by name" do
|
|
555
|
-
|
|
556
|
-
let(:file) do
|
|
557
|
-
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
|
558
|
-
end
|
|
621
|
+
use_spec_mongoid_config
|
|
559
622
|
|
|
560
623
|
before do
|
|
561
|
-
described_class.clear
|
|
562
|
-
Mongoid.load!(file, :test)
|
|
563
624
|
Band.store_in(client: :reports)
|
|
564
625
|
end
|
|
565
626
|
|
|
566
627
|
after do
|
|
567
628
|
mongo_client.close
|
|
568
|
-
Mongoid::Config.reset
|
|
569
629
|
Band.reset_storage_options!
|
|
570
630
|
end
|
|
571
631
|
|
data/spec/mongoid/config_spec.rb
CHANGED
|
@@ -88,6 +88,30 @@ describe Mongoid::Config do
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
context 'when background_indexing option' do
|
|
92
|
+
context 'is not set in the config' do
|
|
93
|
+
it 'sets the value to false by default' do
|
|
94
|
+
Mongoid::Config.reset
|
|
95
|
+
configuration = CONFIG.merge(options: {})
|
|
96
|
+
|
|
97
|
+
Mongoid.configure { |config| config.load_configuration(configuration) }
|
|
98
|
+
|
|
99
|
+
expect(Mongoid::Config.background_indexing).to be(false)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context 'is set in the config' do
|
|
104
|
+
it 'sets the value' do
|
|
105
|
+
Mongoid::Config.reset
|
|
106
|
+
configuration = CONFIG.merge(options: {background_indexing: true})
|
|
107
|
+
|
|
108
|
+
Mongoid.configure { |config| config.load_configuration(configuration) }
|
|
109
|
+
|
|
110
|
+
expect(Mongoid::Config.background_indexing).to be(true)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
91
115
|
context 'when the belongs_to_required_by_default option is not set in the config' do
|
|
92
116
|
|
|
93
117
|
before do
|
|
@@ -346,7 +370,9 @@ describe Mongoid::Config do
|
|
|
346
370
|
end
|
|
347
371
|
|
|
348
372
|
it "sets the default hosts" do
|
|
349
|
-
expect(default[:hosts]).to eq(
|
|
373
|
+
expect(default[:hosts]).to eq(SpecConfig.instance.addresses)
|
|
374
|
+
# and make sure the value is not empty
|
|
375
|
+
expect(default[:hosts].first).to include(':')
|
|
350
376
|
end
|
|
351
377
|
|
|
352
378
|
context "when the default has options" do
|
|
@@ -987,6 +987,25 @@ describe Mongoid::Contextual::Memory do
|
|
|
987
987
|
end
|
|
988
988
|
end
|
|
989
989
|
|
|
990
|
+
describe '#inc' do
|
|
991
|
+
|
|
992
|
+
let(:criteria) do
|
|
993
|
+
Address.all.tap do |crit|
|
|
994
|
+
crit.documents = [ Address.new(number: 1),
|
|
995
|
+
Address.new(number: 2),
|
|
996
|
+
Address.new(number: 3) ]
|
|
997
|
+
end
|
|
998
|
+
end
|
|
999
|
+
|
|
1000
|
+
let(:context) do
|
|
1001
|
+
described_class.new(criteria)
|
|
1002
|
+
end
|
|
1003
|
+
|
|
1004
|
+
it 'increases each member' do
|
|
1005
|
+
expect(context.inc(number: 10).collect(&:number)).to eql([11, 12, 13])
|
|
1006
|
+
end
|
|
1007
|
+
end
|
|
1008
|
+
|
|
990
1009
|
describe "#skip" do
|
|
991
1010
|
|
|
992
1011
|
let(:hobrecht) do
|
|
@@ -451,7 +451,7 @@ describe Mongoid::Contextual::Mongo do
|
|
|
451
451
|
end
|
|
452
452
|
|
|
453
453
|
it "returns the distinct field values" do
|
|
454
|
-
expect(context.distinct(:years)).to eq([
|
|
454
|
+
expect(context.distinct(:years).sort).to eq([ 25, 30 ])
|
|
455
455
|
end
|
|
456
456
|
end
|
|
457
457
|
|
|
@@ -577,6 +577,31 @@ describe Mongoid::Contextual::Mongo do
|
|
|
577
577
|
end
|
|
578
578
|
end
|
|
579
579
|
end
|
|
580
|
+
|
|
581
|
+
context 'when the criteria has a parent document' do
|
|
582
|
+
|
|
583
|
+
before do
|
|
584
|
+
Post.create(person: person)
|
|
585
|
+
Post.create(person: person)
|
|
586
|
+
Post.create(person: person)
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
let(:person) do
|
|
590
|
+
Person.new
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
let(:criteria) do
|
|
594
|
+
person.posts.all
|
|
595
|
+
end
|
|
596
|
+
|
|
597
|
+
let(:persons) do
|
|
598
|
+
criteria.collect(&:person)
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
it 'sets the same parent object on each related object' do
|
|
602
|
+
expect(persons.uniq.size).to eq(1)
|
|
603
|
+
end
|
|
604
|
+
end
|
|
580
605
|
end
|
|
581
606
|
|
|
582
607
|
describe "#eager_load" do
|
|
@@ -591,12 +616,12 @@ describe Mongoid::Contextual::Mongo do
|
|
|
591
616
|
|
|
592
617
|
context "when no documents are returned" do
|
|
593
618
|
|
|
594
|
-
let(:
|
|
619
|
+
let(:game_association) do
|
|
595
620
|
Person.reflect_on_association(:game)
|
|
596
621
|
end
|
|
597
622
|
|
|
598
623
|
it "does not make any additional database queries" do
|
|
599
|
-
expect(
|
|
624
|
+
expect(game_association).to receive(:eager_load).never
|
|
600
625
|
context.send(:eager_load, [])
|
|
601
626
|
end
|
|
602
627
|
end
|
|
@@ -1693,6 +1718,9 @@ describe Mongoid::Contextual::Mongo do
|
|
|
1693
1718
|
end
|
|
1694
1719
|
|
|
1695
1720
|
context "when limiting is provided" do
|
|
1721
|
+
# map/reduce with limit is not supported on sharded clusters:
|
|
1722
|
+
# https://jira.mongodb.org/browse/SERVER-2099
|
|
1723
|
+
require_topology :single, :replica_set
|
|
1696
1724
|
|
|
1697
1725
|
let(:criteria) do
|
|
1698
1726
|
Band.limit(1)
|
|
@@ -2328,7 +2356,7 @@ describe Mongoid::Contextual::Mongo do
|
|
|
2328
2356
|
|
|
2329
2357
|
let!(:update) do
|
|
2330
2358
|
context.update_all({ '$set' => { 'labels.$[i].name' => 'Sony' } },
|
|
2331
|
-
|
|
2359
|
+
array_filters: [{ 'i.name' => 'Cbs' }])
|
|
2332
2360
|
end
|
|
2333
2361
|
|
|
2334
2362
|
it 'applies the array filters' do
|
|
@@ -2363,7 +2391,7 @@ describe Mongoid::Contextual::Mongo do
|
|
|
2363
2391
|
end
|
|
2364
2392
|
|
|
2365
2393
|
it 'creates a pipeline with the selector as one of the $match criteria' do
|
|
2366
|
-
expect(pipeline_match).to include({
|
|
2394
|
+
expect(pipeline_match).to include({ '$text' => { '$search' => "New Order" } })
|
|
2367
2395
|
end
|
|
2368
2396
|
|
|
2369
2397
|
it 'creates a pipeline with the $exists operator as one of the $match criteria' do
|