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
|
@@ -12,8 +12,8 @@ describe Mongoid::Clients::Factory do
|
|
|
12
12
|
|
|
13
13
|
let(:config) do
|
|
14
14
|
{
|
|
15
|
-
default: { hosts:
|
|
16
|
-
secondary: { hosts:
|
|
15
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
|
16
|
+
secondary: { hosts: SpecConfig.instance.addresses, database: database_id }
|
|
17
17
|
}
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -38,7 +38,7 @@ describe Mongoid::Clients::Factory do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "sets the cluster's seeds" do
|
|
41
|
-
expect(cluster.addresses.first.to_s).to eq(
|
|
41
|
+
expect(cluster.addresses.first.to_s).to eq(SpecConfig.instance.addresses.first)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "sets the platform to Mongoid's platform constant" do
|
|
@@ -80,11 +80,11 @@ describe Mongoid::Clients::Factory do
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
it "sets the cluster's seed ports to 27017" do
|
|
83
|
-
expect(
|
|
83
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it "sets ips with no ports to 27017" do
|
|
87
|
-
expect(
|
|
87
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -120,7 +120,7 @@ describe Mongoid::Clients::Factory do
|
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
it "sets the cluster's seeds" do
|
|
123
|
-
expect(
|
|
123
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
it "sets the database" do
|
|
@@ -181,7 +181,7 @@ describe Mongoid::Clients::Factory do
|
|
|
181
181
|
context "when no name is provided" do
|
|
182
182
|
|
|
183
183
|
let(:config) do
|
|
184
|
-
{ default: { hosts:
|
|
184
|
+
{ default: { hosts: SpecConfig.instance.addresses, database: database_id }}
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
before do
|
|
@@ -200,7 +200,7 @@ describe Mongoid::Clients::Factory do
|
|
|
200
200
|
client.cluster
|
|
201
201
|
end
|
|
202
202
|
|
|
203
|
-
let(:
|
|
203
|
+
let(:cluster_addresses) do
|
|
204
204
|
cluster.addresses.map{ |address| address.to_s }
|
|
205
205
|
end
|
|
206
206
|
|
|
@@ -208,8 +208,10 @@ describe Mongoid::Clients::Factory do
|
|
|
208
208
|
expect(client).to be_a(Mongo::Client)
|
|
209
209
|
end
|
|
210
210
|
|
|
211
|
-
it "sets the cluster's
|
|
212
|
-
|
|
211
|
+
it "sets the cluster's addresses" do
|
|
212
|
+
SpecConfig.instance.addresses.each do |address|
|
|
213
|
+
expect(cluster_addresses).to include(address)
|
|
214
|
+
end
|
|
213
215
|
end
|
|
214
216
|
end
|
|
215
217
|
|
|
@@ -230,7 +232,7 @@ describe Mongoid::Clients::Factory do
|
|
|
230
232
|
describe ".default" do
|
|
231
233
|
|
|
232
234
|
let(:config) do
|
|
233
|
-
{ default: { hosts:
|
|
235
|
+
{ default: { hosts: SpecConfig.instance.addresses, database: database_id }}
|
|
234
236
|
end
|
|
235
237
|
|
|
236
238
|
before do
|
|
@@ -249,7 +251,7 @@ describe Mongoid::Clients::Factory do
|
|
|
249
251
|
client.cluster
|
|
250
252
|
end
|
|
251
253
|
|
|
252
|
-
let(:
|
|
254
|
+
let(:cluster_addresses) do
|
|
253
255
|
cluster.addresses.map{ |address| address.to_s }
|
|
254
256
|
end
|
|
255
257
|
|
|
@@ -257,8 +259,10 @@ describe Mongoid::Clients::Factory do
|
|
|
257
259
|
expect(client).to be_a(Mongo::Client)
|
|
258
260
|
end
|
|
259
261
|
|
|
260
|
-
it "sets the cluster's
|
|
261
|
-
|
|
262
|
+
it "sets the cluster's addresses" do
|
|
263
|
+
SpecConfig.instance.addresses.each do |address|
|
|
264
|
+
expect(cluster_addresses).to include(address)
|
|
265
|
+
end
|
|
262
266
|
end
|
|
263
267
|
end
|
|
264
268
|
|
|
@@ -267,7 +271,7 @@ describe Mongoid::Clients::Factory do
|
|
|
267
271
|
let(:config) do
|
|
268
272
|
{
|
|
269
273
|
default: {
|
|
270
|
-
hosts:
|
|
274
|
+
hosts: SpecConfig.instance.addresses,
|
|
271
275
|
database: database_id,
|
|
272
276
|
options: {
|
|
273
277
|
"server_selection_timeout" => 10,
|
|
@@ -293,7 +297,7 @@ describe Mongoid::Clients::Factory do
|
|
|
293
297
|
client.cluster
|
|
294
298
|
end
|
|
295
299
|
|
|
296
|
-
let(:
|
|
300
|
+
let(:cluster_addresses) do
|
|
297
301
|
cluster.addresses.map{ |address| address.to_s }
|
|
298
302
|
end
|
|
299
303
|
|
|
@@ -301,8 +305,10 @@ describe Mongoid::Clients::Factory do
|
|
|
301
305
|
expect(client).to be_a(Mongo::Client)
|
|
302
306
|
end
|
|
303
307
|
|
|
304
|
-
it "sets the cluster's
|
|
305
|
-
|
|
308
|
+
it "sets the cluster's addresses" do
|
|
309
|
+
SpecConfig.instance.addresses.each do |address|
|
|
310
|
+
expect(cluster_addresses).to include(address)
|
|
311
|
+
end
|
|
306
312
|
end
|
|
307
313
|
|
|
308
314
|
it "sets the server selection timeout" do
|
|
@@ -2,12 +2,21 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Clients::Options do
|
|
4
4
|
|
|
5
|
+
before do
|
|
6
|
+
# This test asserts on numbers of open connections,
|
|
7
|
+
# to make these assertions work in jruby we cannot have connections
|
|
8
|
+
# bleeding from one test to another and this includes background SDAM
|
|
9
|
+
# threads in the driver
|
|
10
|
+
Mongoid.disconnect_clients
|
|
11
|
+
Mongoid::Clients.clients.clear
|
|
12
|
+
end
|
|
13
|
+
|
|
5
14
|
describe '#with', if: non_legacy_server? do
|
|
6
15
|
|
|
7
16
|
context 'when passing some options' do
|
|
8
17
|
|
|
9
18
|
let(:persistence_context) do
|
|
10
|
-
|
|
19
|
+
Minim.with(options) do |klass|
|
|
11
20
|
klass.persistence_context
|
|
12
21
|
end
|
|
13
22
|
end
|
|
@@ -19,13 +28,13 @@ describe Mongoid::Clients::Options do
|
|
|
19
28
|
end
|
|
20
29
|
|
|
21
30
|
it 'does not set the options on class level' do
|
|
22
|
-
expect(
|
|
31
|
+
expect(Minim.persistence_context.client.options['database']).to eq('mongoid_test')
|
|
23
32
|
end
|
|
24
33
|
|
|
25
34
|
context 'when the options are not valid mongo client options' do
|
|
26
35
|
|
|
27
36
|
let(:persistence_context) do
|
|
28
|
-
|
|
37
|
+
Minim.with(invalid_options) do |klass|
|
|
29
38
|
klass.persistence_context
|
|
30
39
|
end
|
|
31
40
|
end
|
|
@@ -40,7 +49,7 @@ describe Mongoid::Clients::Options do
|
|
|
40
49
|
|
|
41
50
|
it 'clears the persistence context' do
|
|
42
51
|
begin; persistence_context; rescue Mongoid::Errors::InvalidPersistenceOption; end
|
|
43
|
-
expect(
|
|
52
|
+
expect(Minim.persistence_context).to eq(Mongoid::PersistenceContext.new(Minim))
|
|
44
53
|
end
|
|
45
54
|
end
|
|
46
55
|
|
|
@@ -66,14 +75,14 @@ describe Mongoid::Clients::Options do
|
|
|
66
75
|
context 'when passing a block', if: testing_locally? do
|
|
67
76
|
|
|
68
77
|
let!(:connections_before) do
|
|
69
|
-
|
|
78
|
+
Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
70
79
|
end
|
|
71
80
|
|
|
72
81
|
let!(:connections_and_cluster_during) do
|
|
73
82
|
connections = nil
|
|
74
|
-
cluster =
|
|
83
|
+
cluster = Minim.with(options) do |klass|
|
|
75
84
|
klass.where(name: 'emily').to_a
|
|
76
|
-
connections =
|
|
85
|
+
connections = Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
77
86
|
end
|
|
78
87
|
[ connections, cluster ]
|
|
79
88
|
end
|
|
@@ -87,15 +96,15 @@ describe Mongoid::Clients::Options do
|
|
|
87
96
|
end
|
|
88
97
|
|
|
89
98
|
let(:connections_after) do
|
|
90
|
-
|
|
99
|
+
Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
91
100
|
end
|
|
92
101
|
|
|
93
102
|
let!(:cluster_before) do
|
|
94
|
-
|
|
103
|
+
Minim.persistence_context.cluster
|
|
95
104
|
end
|
|
96
105
|
|
|
97
106
|
let(:cluster_after) do
|
|
98
|
-
|
|
107
|
+
Minim.persistence_context.cluster
|
|
99
108
|
end
|
|
100
109
|
|
|
101
110
|
context 'when the options create a new cluster' do
|
|
@@ -134,8 +143,8 @@ describe Mongoid::Clients::Options do
|
|
|
134
143
|
|
|
135
144
|
let(:config) do
|
|
136
145
|
{
|
|
137
|
-
default: { hosts:
|
|
138
|
-
secondary: { uri: "mongodb
|
|
146
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
|
147
|
+
secondary: { uri: "mongodb://#{SpecConfig.instance.addresses.first}/secondary-db?connectTimeoutMS=3000" }
|
|
139
148
|
}
|
|
140
149
|
end
|
|
141
150
|
|
|
@@ -148,7 +157,7 @@ describe Mongoid::Clients::Options do
|
|
|
148
157
|
end
|
|
149
158
|
|
|
150
159
|
let(:persistence_context) do
|
|
151
|
-
|
|
160
|
+
Minim.with(client: :secondary) do |klass|
|
|
152
161
|
klass.persistence_context
|
|
153
162
|
end
|
|
154
163
|
end
|
|
@@ -181,7 +190,7 @@ describe Mongoid::Clients::Options do
|
|
|
181
190
|
|
|
182
191
|
let(:context_and_criteria) do
|
|
183
192
|
collection = nil
|
|
184
|
-
cxt =
|
|
193
|
+
cxt = Minim.with(read_secondary_option) do |klass|
|
|
185
194
|
collection = klass.all.collection
|
|
186
195
|
klass.persistence_context
|
|
187
196
|
end
|
|
@@ -221,11 +230,11 @@ describe Mongoid::Clients::Options do
|
|
|
221
230
|
100.times do |i|
|
|
222
231
|
threads << Thread.new do
|
|
223
232
|
if i % 2 == 0
|
|
224
|
-
|
|
233
|
+
Minim.with(collection: 'British') do |klass|
|
|
225
234
|
klass.create(name: 'realised')
|
|
226
235
|
end
|
|
227
236
|
else
|
|
228
|
-
|
|
237
|
+
Minim.with(collection: 'American') do |klass|
|
|
229
238
|
klass.create(name: 'realized')
|
|
230
239
|
end
|
|
231
240
|
end
|
|
@@ -235,13 +244,13 @@ describe Mongoid::Clients::Options do
|
|
|
235
244
|
end
|
|
236
245
|
|
|
237
246
|
let(:british_count) do
|
|
238
|
-
|
|
247
|
+
Minim.with(collection: 'British') do |klass|
|
|
239
248
|
klass.all.count
|
|
240
249
|
end
|
|
241
250
|
end
|
|
242
251
|
|
|
243
252
|
let(:american_count) do
|
|
244
|
-
|
|
253
|
+
Minim.with(collection: 'American') do |klass|
|
|
245
254
|
klass.all.count
|
|
246
255
|
end
|
|
247
256
|
end
|
|
@@ -256,7 +265,7 @@ describe Mongoid::Clients::Options do
|
|
|
256
265
|
context 'when passing a persistence context' do
|
|
257
266
|
|
|
258
267
|
let(:instance) do
|
|
259
|
-
|
|
268
|
+
Minim.new
|
|
260
269
|
end
|
|
261
270
|
|
|
262
271
|
let(:persistence_context) do
|
|
@@ -268,8 +277,8 @@ describe Mongoid::Clients::Options do
|
|
|
268
277
|
let(:options) { { database: 'other' } }
|
|
269
278
|
|
|
270
279
|
it 'sets the persistence context on the object' do
|
|
271
|
-
|
|
272
|
-
expect(
|
|
280
|
+
Minim.new.with(persistence_context) do |model_instance|
|
|
281
|
+
expect(model_instance.persistence_context.options).to eq(persistence_context.options)
|
|
273
282
|
end
|
|
274
283
|
end
|
|
275
284
|
end
|
|
@@ -283,12 +292,12 @@ describe Mongoid::Clients::Options do
|
|
|
283
292
|
{ database: 'other' }
|
|
284
293
|
end
|
|
285
294
|
|
|
286
|
-
let(:
|
|
287
|
-
|
|
295
|
+
let(:test_model) do
|
|
296
|
+
Minim.create
|
|
288
297
|
end
|
|
289
298
|
|
|
290
299
|
let(:persistence_context) do
|
|
291
|
-
|
|
300
|
+
test_model.with(options) do |object|
|
|
292
301
|
object.persistence_context
|
|
293
302
|
end
|
|
294
303
|
end
|
|
@@ -298,13 +307,13 @@ describe Mongoid::Clients::Options do
|
|
|
298
307
|
end
|
|
299
308
|
|
|
300
309
|
it 'does not set the options on instance level' do
|
|
301
|
-
expect(
|
|
310
|
+
expect(test_model.persistence_context.client.database.name).to eq('mongoid_test')
|
|
302
311
|
end
|
|
303
312
|
|
|
304
313
|
context 'when the options are not valid mongo client options' do
|
|
305
314
|
|
|
306
315
|
let(:persistence_context) do
|
|
307
|
-
|
|
316
|
+
test_model.with(invalid_options) do |object|
|
|
308
317
|
object.persistence_context
|
|
309
318
|
end
|
|
310
319
|
end
|
|
@@ -319,7 +328,7 @@ describe Mongoid::Clients::Options do
|
|
|
319
328
|
|
|
320
329
|
it 'clears the persistence context' do
|
|
321
330
|
begin; persistence_context; rescue Mongoid::Errors::InvalidPersistenceOption; end
|
|
322
|
-
expect(
|
|
331
|
+
expect(test_model.persistence_context).to eq(Mongoid::PersistenceContext.new(test_model))
|
|
323
332
|
end
|
|
324
333
|
end
|
|
325
334
|
|
|
@@ -327,8 +336,13 @@ describe Mongoid::Clients::Options do
|
|
|
327
336
|
|
|
328
337
|
let(:config) do
|
|
329
338
|
{
|
|
330
|
-
default: { hosts:
|
|
331
|
-
secondary: {
|
|
339
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
|
340
|
+
secondary: {
|
|
341
|
+
uri: "mongodb://#{SpecConfig.instance.addresses.first}/secondary-db",
|
|
342
|
+
options: {
|
|
343
|
+
server_selection_timeout: 0.5,
|
|
344
|
+
},
|
|
345
|
+
}
|
|
332
346
|
}
|
|
333
347
|
end
|
|
334
348
|
|
|
@@ -337,7 +351,7 @@ describe Mongoid::Clients::Options do
|
|
|
337
351
|
end
|
|
338
352
|
|
|
339
353
|
let(:persistence_context) do
|
|
340
|
-
|
|
354
|
+
test_model.with(client: :secondary) do |object|
|
|
341
355
|
object.persistence_context
|
|
342
356
|
end
|
|
343
357
|
end
|
|
@@ -351,14 +365,14 @@ describe Mongoid::Clients::Options do
|
|
|
351
365
|
context 'when passing a block', if: testing_locally? do
|
|
352
366
|
|
|
353
367
|
let!(:connections_before) do
|
|
354
|
-
|
|
368
|
+
test_model.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
355
369
|
end
|
|
356
370
|
|
|
357
371
|
let!(:connections_and_cluster_during) do
|
|
358
372
|
connections = nil
|
|
359
|
-
cluster =
|
|
373
|
+
cluster = test_model.with(options) do |b|
|
|
360
374
|
b.reload
|
|
361
|
-
connections =
|
|
375
|
+
connections = test_model.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
362
376
|
b.persistence_context.cluster
|
|
363
377
|
end
|
|
364
378
|
[ connections, cluster ]
|
|
@@ -373,15 +387,15 @@ describe Mongoid::Clients::Options do
|
|
|
373
387
|
end
|
|
374
388
|
|
|
375
389
|
let(:connections_after) do
|
|
376
|
-
|
|
390
|
+
test_model.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
|
377
391
|
end
|
|
378
392
|
|
|
379
393
|
let!(:cluster_before) do
|
|
380
|
-
|
|
394
|
+
test_model.persistence_context.cluster
|
|
381
395
|
end
|
|
382
396
|
|
|
383
397
|
let(:cluster_after) do
|
|
384
|
-
|
|
398
|
+
test_model.persistence_context.cluster
|
|
385
399
|
end
|
|
386
400
|
|
|
387
401
|
context 'when the options create a new cluster' do
|
|
@@ -431,15 +445,15 @@ describe Mongoid::Clients::Options do
|
|
|
431
445
|
before do
|
|
432
446
|
threads = []
|
|
433
447
|
100.times do |i|
|
|
434
|
-
|
|
448
|
+
test_model = Minim.create
|
|
435
449
|
threads << Thread.new do
|
|
436
450
|
if i % 2 == 0
|
|
437
|
-
|
|
451
|
+
test_model.with(collection: 'British') do |b|
|
|
438
452
|
b.name = 'realised'
|
|
439
453
|
b.upsert
|
|
440
454
|
end
|
|
441
455
|
else
|
|
442
|
-
|
|
456
|
+
test_model.with(collection: 'American') do |b|
|
|
443
457
|
b.name = 'realized'
|
|
444
458
|
b.upsert
|
|
445
459
|
end
|
|
@@ -450,13 +464,13 @@ describe Mongoid::Clients::Options do
|
|
|
450
464
|
end
|
|
451
465
|
|
|
452
466
|
let(:british_count) do
|
|
453
|
-
|
|
467
|
+
Minim.with(collection: 'British') do |klass|
|
|
454
468
|
klass.all.count
|
|
455
469
|
end
|
|
456
470
|
end
|
|
457
471
|
|
|
458
472
|
let(:american_count) do
|
|
459
|
-
|
|
473
|
+
Minim.with(collection: 'British') do |klass|
|
|
460
474
|
klass.all.count
|
|
461
475
|
end
|
|
462
476
|
end
|
|
@@ -471,7 +485,7 @@ describe Mongoid::Clients::Options do
|
|
|
471
485
|
context 'when passing a persistence context' do
|
|
472
486
|
|
|
473
487
|
let(:persistence_context) do
|
|
474
|
-
|
|
488
|
+
Minim.with(options) do |klass|
|
|
475
489
|
klass.persistence_context
|
|
476
490
|
end
|
|
477
491
|
end
|
|
@@ -479,8 +493,8 @@ describe Mongoid::Clients::Options do
|
|
|
479
493
|
let(:options) { { database: 'other' } }
|
|
480
494
|
|
|
481
495
|
it 'sets the persistence context on the object' do
|
|
482
|
-
|
|
483
|
-
expect(
|
|
496
|
+
Minim.with(persistence_context) do |test_model_class|
|
|
497
|
+
expect(test_model_class.persistence_context.options).to eq(persistence_context.options)
|
|
484
498
|
end
|
|
485
499
|
end
|
|
486
500
|
end
|