mongoid 5.4.0 → 6.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +3 -3
- data/Rakefile +26 -0
- data/lib/config/locales/en.yml +40 -0
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/atomic.rb +5 -5
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/attributes.rb +22 -21
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +36 -0
- data/lib/mongoid/clients/options.rb +55 -250
- data/lib/mongoid/clients/sessions.rb +113 -0
- data/lib/mongoid/clients/storage_options.rb +2 -69
- data/lib/mongoid/clients.rb +10 -63
- data/lib/mongoid/composable.rb +29 -2
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +4 -4
- data/lib/mongoid/contextual/map_reduce.rb +7 -3
- data/lib/mongoid/contextual/memory.rb +9 -4
- data/lib/mongoid/contextual/mongo.rb +65 -30
- data/lib/mongoid/contextual/none.rb +12 -0
- data/lib/mongoid/copyable.rb +13 -6
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +29 -3
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +273 -0
- data/lib/mongoid/criteria/queryable/optional.rb +429 -0
- data/lib/mongoid/criteria/queryable/options.rb +153 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +689 -0
- data/lib/mongoid/criteria/queryable/selector.rb +212 -0
- data/lib/mongoid/criteria/queryable/smash.rb +104 -0
- data/lib/mongoid/criteria/queryable.rb +87 -0
- data/lib/mongoid/criteria.rb +6 -2
- data/lib/mongoid/document.rb +34 -41
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/invalid_session_use.rb +24 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/decimal128.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -0
- data/lib/mongoid/extensions/string.rb +6 -3
- data/lib/mongoid/extensions/time.rb +4 -1
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +2 -1
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +2 -2
- data/lib/mongoid/indexable.rb +16 -14
- data/lib/mongoid/interceptable.rb +9 -22
- data/lib/mongoid/matchable/all.rb +2 -2
- data/lib/mongoid/matchable/and.rb +3 -3
- data/lib/mongoid/matchable/default.rb +2 -2
- data/lib/mongoid/matchable/elem_match.rb +28 -0
- data/lib/mongoid/matchable/exists.rb +2 -2
- data/lib/mongoid/matchable/gt.rb +4 -2
- data/lib/mongoid/matchable/gte.rb +4 -2
- data/lib/mongoid/matchable/in.rb +2 -2
- data/lib/mongoid/matchable/lt.rb +4 -2
- data/lib/mongoid/matchable/lte.rb +4 -2
- data/lib/mongoid/matchable/ne.rb +2 -2
- data/lib/mongoid/matchable/nin.rb +2 -2
- data/lib/mongoid/matchable/nor.rb +37 -0
- data/lib/mongoid/matchable/or.rb +3 -3
- data/lib/mongoid/matchable/regexp.rb +3 -3
- data/lib/mongoid/matchable/size.rb +2 -2
- data/lib/mongoid/matchable.rb +16 -7
- data/lib/mongoid/persistable/creatable.rb +5 -3
- data/lib/mongoid/persistable/deletable.rb +5 -3
- data/lib/mongoid/persistable/destroyable.rb +1 -5
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +7 -14
- data/lib/mongoid/persistable/upsertable.rb +2 -1
- data/lib/mongoid/persistable.rb +4 -6
- data/lib/mongoid/persistence_context.rb +220 -0
- data/lib/mongoid/query_cache.rb +67 -23
- data/lib/mongoid/railtie.rb +17 -1
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/relations/accessors.rb +3 -0
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
- data/lib/mongoid/relations/counter_cache.rb +15 -5
- data/lib/mongoid/relations/eager/base.rb +3 -3
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/relations/eager/has_many.rb +1 -1
- data/lib/mongoid/relations/eager.rb +6 -11
- data/lib/mongoid/relations/embedded/batchable.rb +20 -18
- data/lib/mongoid/relations/embedded/in.rb +13 -1
- data/lib/mongoid/relations/embedded/many.rb +51 -10
- data/lib/mongoid/relations/embedded/one.rb +14 -1
- data/lib/mongoid/relations/macros.rb +9 -1
- data/lib/mongoid/relations/many.rb +4 -0
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +1 -31
- data/lib/mongoid/relations/referenced/in.rb +19 -10
- data/lib/mongoid/relations/referenced/many.rb +30 -26
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +15 -1
- data/lib/mongoid/relations/synchronization.rb +12 -12
- data/lib/mongoid/relations/targets/enumerable.rb +24 -4
- data/lib/mongoid/relations/touchable.rb +7 -4
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +1 -1
- data/lib/mongoid/stateful.rb +1 -0
- data/lib/mongoid/tasks/database.rb +3 -2
- data/lib/mongoid/threaded.rb +74 -0
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +6 -6
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +18 -3
- data/spec/app/models/agent.rb +2 -0
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/array_field.rb +7 -0
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +3 -0
- data/spec/app/models/book.rb +2 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/app/models/dokument.rb +1 -0
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/page.rb +1 -1
- data/spec/app/models/person.rb +3 -3
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/subscription.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +15 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +3 -3
- data/spec/mongoid/atomic_spec.rb +5 -5
- data/spec/mongoid/attributes/nested_spec.rb +18 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +90 -5
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +80 -28
- data/spec/mongoid/clients/options_spec.rb +396 -95
- data/spec/mongoid/clients/sessions_spec.rb +334 -0
- data/spec/mongoid/clients_spec.rb +243 -101
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +67 -11
- data/spec/mongoid/contextual/atomic_spec.rb +3 -3
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -0
- data/spec/mongoid/contextual/mongo_spec.rb +275 -22
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +13 -4
- data/spec/mongoid/criteria/modifiable_spec.rb +297 -16
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin → criteria/queryable/extensions}/regexp_raw_spec.rb +2 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +90 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1799 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4242 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +844 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +156 -22
- data/spec/mongoid/document_spec.rb +100 -90
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +321 -19
- data/spec/mongoid/extensions/boolean_spec.rb +14 -0
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +1 -1
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/hash_spec.rb +15 -0
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/regexp_spec.rb +23 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -4
- data/spec/mongoid/extensions/time_spec.rb +2 -6
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/factory_spec.rb +11 -0
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/findable_spec.rb +47 -2
- data/spec/mongoid/indexable_spec.rb +15 -3
- data/spec/mongoid/interceptable_spec.rb +85 -19
- data/spec/mongoid/matchable/all_spec.rb +4 -4
- data/spec/mongoid/matchable/and_spec.rb +10 -10
- data/spec/mongoid/matchable/default_spec.rb +12 -12
- data/spec/mongoid/matchable/elem_match_spec.rb +86 -0
- data/spec/mongoid/matchable/exists_spec.rb +5 -5
- data/spec/mongoid/matchable/gt_spec.rb +18 -7
- data/spec/mongoid/matchable/gte_spec.rb +17 -7
- data/spec/mongoid/matchable/in_spec.rb +5 -5
- data/spec/mongoid/matchable/lt_spec.rb +18 -7
- data/spec/mongoid/matchable/lte_spec.rb +18 -7
- data/spec/mongoid/matchable/ne_spec.rb +5 -5
- data/spec/mongoid/matchable/nin_spec.rb +5 -5
- data/spec/mongoid/matchable/nor_spec.rb +209 -0
- data/spec/mongoid/matchable/or_spec.rb +7 -7
- data/spec/mongoid/matchable/regexp_spec.rb +5 -5
- data/spec/mongoid/matchable/size_spec.rb +3 -3
- data/spec/mongoid/matchable_spec.rb +199 -54
- data/spec/mongoid/persistable/creatable_spec.rb +7 -2
- data/spec/mongoid/persistable/deletable_spec.rb +35 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +25 -2
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +34 -29
- data/spec/mongoid/persistable/settable_spec.rb +77 -27
- data/spec/mongoid/persistable/updatable_spec.rb +182 -3
- data/spec/mongoid/persistable_spec.rb +16 -16
- data/spec/mongoid/persistence_context_spec.rb +694 -0
- data/spec/mongoid/positional_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +170 -12
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -3
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +16 -0
- data/spec/mongoid/relations/eager_spec.rb +40 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +305 -59
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +415 -7
- data/spec/mongoid/relations/metadata_spec.rb +15 -1
- data/spec/mongoid/relations/proxy_spec.rb +27 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +35 -25
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +14 -26
- data/spec/mongoid/relations/synchronization_spec.rb +48 -2
- data/spec/mongoid/relations/targets/enumerable_spec.rb +108 -0
- data/spec/mongoid/relations/touchable_spec.rb +40 -0
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +18 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +101 -8
- data/spec/support/cluster_config.rb +158 -0
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/session_registry.rb +50 -0
- data/spec/support/spec_config.rb +42 -0
- data.tar.gz.sig +0 -0
- metadata +163 -61
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/railties/document.rb +0 -12
- data/spec/mongoid/railties/document_spec.rb +0 -24
@@ -6,34 +6,38 @@ describe Mongoid::Clients do
|
|
6
6
|
|
7
7
|
shared_examples_for "an overridden collection at the class level" do
|
8
8
|
|
9
|
-
let(:band) do
|
10
|
-
klass.new
|
11
|
-
end
|
12
|
-
|
13
9
|
it "returns the collection for the model" do
|
14
|
-
expect(
|
10
|
+
expect(instance_collection).to be_a(Mongo::Collection)
|
15
11
|
end
|
16
12
|
|
17
13
|
it "sets the correct collection name" do
|
18
|
-
expect(
|
14
|
+
expect(instance_collection.name).to eq("artists")
|
19
15
|
end
|
20
16
|
|
21
17
|
context "when accessing from the class level" do
|
22
18
|
|
23
19
|
it "returns the collection for the model" do
|
24
|
-
expect(
|
20
|
+
expect(class_collection).to be_a(Mongo::Collection)
|
25
21
|
end
|
26
22
|
|
27
23
|
it "sets the correct collection name" do
|
28
|
-
expect(
|
24
|
+
expect(class_collection.name).to eq("artists")
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
29
|
context "when overriding the persistence options" do
|
34
30
|
|
35
|
-
let(:
|
36
|
-
Band.with(collection: "artists")
|
31
|
+
let(:instance_collection) do
|
32
|
+
Band.with(collection: "artists") do |klass|
|
33
|
+
klass.new.collection
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:class_collection) do
|
38
|
+
Band.with(collection: "artists") do |klass|
|
39
|
+
klass.collection
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
it_behaves_like "an overridden collection at the class level"
|
@@ -41,10 +45,6 @@ describe Mongoid::Clients do
|
|
41
45
|
|
42
46
|
context "when overriding store_in and persistence options" do
|
43
47
|
|
44
|
-
let(:klass) do
|
45
|
-
Band.with(collection: "artists")
|
46
|
-
end
|
47
|
-
|
48
48
|
before do
|
49
49
|
Band.store_in collection: "foo"
|
50
50
|
end
|
@@ -53,6 +53,18 @@ describe Mongoid::Clients do
|
|
53
53
|
Band.reset_storage_options!
|
54
54
|
end
|
55
55
|
|
56
|
+
let(:instance_collection) do
|
57
|
+
Band.with(collection: "artists") do |klass|
|
58
|
+
klass.new.collection
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:class_collection) do
|
63
|
+
Band.with(collection: "artists") do |klass|
|
64
|
+
klass.collection
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
56
68
|
it_behaves_like "an overridden collection at the class level"
|
57
69
|
end
|
58
70
|
|
@@ -77,19 +89,23 @@ describe Mongoid::Clients do
|
|
77
89
|
|
78
90
|
context "when overriding with a proc" do
|
79
91
|
|
80
|
-
let(:klass) { Band }
|
81
|
-
|
82
92
|
before do
|
83
93
|
Band.store_in(collection: ->{ "artists" })
|
84
94
|
end
|
85
95
|
|
96
|
+
let(:instance_collection) do
|
97
|
+
Band.new.collection
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:class_collection) do
|
101
|
+
Band.collection
|
102
|
+
end
|
103
|
+
|
86
104
|
it_behaves_like "an overridden collection at the class level"
|
87
105
|
end
|
88
106
|
|
89
107
|
context "when overriding with a string" do
|
90
108
|
|
91
|
-
let(:klass) { Band }
|
92
|
-
|
93
109
|
before do
|
94
110
|
Band.store_in(collection: "artists")
|
95
111
|
end
|
@@ -98,19 +114,33 @@ describe Mongoid::Clients do
|
|
98
114
|
Band.reset_storage_options!
|
99
115
|
end
|
100
116
|
|
117
|
+
let(:instance_collection) do
|
118
|
+
Band.new.collection
|
119
|
+
end
|
120
|
+
|
121
|
+
let(:class_collection) do
|
122
|
+
Band.collection
|
123
|
+
end
|
124
|
+
|
101
125
|
it_behaves_like "an overridden collection at the class level"
|
102
126
|
end
|
103
127
|
|
104
128
|
context "when overriding with a symbol" do
|
105
129
|
|
106
|
-
let(:klass) { Band }
|
107
|
-
|
108
130
|
before do
|
109
|
-
|
131
|
+
Band.store_in(collection: :artists)
|
110
132
|
end
|
111
133
|
|
112
134
|
after do
|
113
|
-
|
135
|
+
Band.reset_storage_options!
|
136
|
+
end
|
137
|
+
|
138
|
+
let(:instance_collection) do
|
139
|
+
Band.new.collection
|
140
|
+
end
|
141
|
+
|
142
|
+
let(:class_collection) do
|
143
|
+
Band.collection
|
114
144
|
end
|
115
145
|
|
116
146
|
it_behaves_like "an overridden collection at the class level"
|
@@ -148,29 +178,33 @@ describe Mongoid::Clients do
|
|
148
178
|
|
149
179
|
shared_examples_for "an overridden collection name at the class level" do
|
150
180
|
|
151
|
-
let(:band) do
|
152
|
-
klass.new
|
153
|
-
end
|
154
|
-
|
155
181
|
context "when accessing from the instance" do
|
156
182
|
|
157
183
|
it "returns the overridden value" do
|
158
|
-
expect(
|
184
|
+
expect(instance_collection_name).to eq(:artists)
|
159
185
|
end
|
160
186
|
end
|
161
187
|
|
162
188
|
context "when accessing from the class level" do
|
163
189
|
|
164
190
|
it "returns the overridden value" do
|
165
|
-
expect(
|
191
|
+
expect(class_collection_name).to eq(:artists)
|
166
192
|
end
|
167
193
|
end
|
168
194
|
end
|
169
195
|
|
170
196
|
context "when overriding the persistence options" do
|
171
197
|
|
172
|
-
let(:
|
173
|
-
Band.with(collection: "artists")
|
198
|
+
let(:instance_collection_name) do
|
199
|
+
Band.with(collection: "artists") do |klass|
|
200
|
+
klass.new.collection_name
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
let(:class_collection_name) do
|
205
|
+
Band.with(collection: "artists") do |klass|
|
206
|
+
klass.collection_name
|
207
|
+
end
|
174
208
|
end
|
175
209
|
|
176
210
|
it_behaves_like "an overridden collection name at the class level"
|
@@ -178,8 +212,16 @@ describe Mongoid::Clients do
|
|
178
212
|
|
179
213
|
context "when overriding store_in and persistence options" do
|
180
214
|
|
181
|
-
let(:
|
182
|
-
Band.with(collection: "artists")
|
215
|
+
let(:instance_collection_name) do
|
216
|
+
Band.with(collection: "artists") do |klass|
|
217
|
+
klass.new.collection_name
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
let(:class_collection_name) do
|
222
|
+
Band.with(collection: "artists") do |klass|
|
223
|
+
klass.collection_name
|
224
|
+
end
|
183
225
|
end
|
184
226
|
|
185
227
|
before do
|
@@ -195,7 +237,13 @@ describe Mongoid::Clients do
|
|
195
237
|
|
196
238
|
context "when overriding the default with store_in" do
|
197
239
|
|
198
|
-
let(:
|
240
|
+
let(:instance_collection_name) do
|
241
|
+
Band.new.collection_name
|
242
|
+
end
|
243
|
+
|
244
|
+
let(:class_collection_name) do
|
245
|
+
Band.collection_name
|
246
|
+
end
|
199
247
|
|
200
248
|
after do
|
201
249
|
Band.reset_storage_options!
|
@@ -266,38 +314,51 @@ describe Mongoid::Clients do
|
|
266
314
|
end
|
267
315
|
end
|
268
316
|
|
269
|
-
describe "#database_name"
|
317
|
+
describe "#database_name" do
|
270
318
|
|
271
319
|
shared_examples_for "an overridden database name" do
|
272
320
|
|
273
|
-
|
274
|
-
|
321
|
+
after do
|
322
|
+
class_mongo_client.close
|
275
323
|
end
|
276
324
|
|
277
325
|
context "when accessing from the instance" do
|
278
326
|
|
279
327
|
it "returns the overridden value" do
|
280
|
-
|
281
|
-
# expect(band.mongo_client.options[:database].to_s).to eq(database_id_alt)
|
328
|
+
expect(instance_database.name.to_s).to eq(database_id_alt)
|
282
329
|
end
|
283
330
|
end
|
284
331
|
|
285
332
|
context "when accessing from the class level" do
|
286
333
|
|
287
334
|
it "returns the overridden value" do
|
288
|
-
expect(
|
335
|
+
expect(class_database.name.to_s).to eq(database_id_alt)
|
289
336
|
end
|
290
337
|
|
291
338
|
it "client returns the overridden value" do
|
292
|
-
expect(
|
339
|
+
expect(class_mongo_client.database.name).to eq(database_id_alt)
|
293
340
|
end
|
294
341
|
end
|
295
342
|
end
|
296
343
|
|
297
344
|
context "when overriding the persistence options" do
|
298
345
|
|
299
|
-
let(:
|
300
|
-
Band.with(database: database_id_alt)
|
346
|
+
let(:instance_database) do
|
347
|
+
Band.with(database: database_id_alt) do |klass|
|
348
|
+
klass.new.mongo_client.database
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
let(:class_database) do
|
353
|
+
Band.with(database: database_id_alt) do |klass|
|
354
|
+
klass.mongo_client.database
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
let(:class_mongo_client) do
|
359
|
+
Band.with(database: database_id_alt) do |klass|
|
360
|
+
klass.new.mongo_client
|
361
|
+
end
|
301
362
|
end
|
302
363
|
|
303
364
|
it_behaves_like "an overridden database name"
|
@@ -305,7 +366,17 @@ describe Mongoid::Clients do
|
|
305
366
|
|
306
367
|
context "when overriding with store_in" do
|
307
368
|
|
308
|
-
let(:
|
369
|
+
let(:instance_database) do
|
370
|
+
Band.new.mongo_client.database
|
371
|
+
end
|
372
|
+
|
373
|
+
let(:class_database) do
|
374
|
+
Band.mongo_client.database
|
375
|
+
end
|
376
|
+
|
377
|
+
let(:class_mongo_client) do
|
378
|
+
Band.mongo_client
|
379
|
+
end
|
309
380
|
|
310
381
|
before do
|
311
382
|
Band.store_in database: database_id_alt
|
@@ -313,6 +384,7 @@ describe Mongoid::Clients do
|
|
313
384
|
|
314
385
|
after do
|
315
386
|
Band.reset_storage_options!
|
387
|
+
class_mongo_client.close
|
316
388
|
end
|
317
389
|
|
318
390
|
it_behaves_like "an overridden database name"
|
@@ -320,8 +392,22 @@ describe Mongoid::Clients do
|
|
320
392
|
|
321
393
|
context "when overriding store_in and persistence options" do
|
322
394
|
|
323
|
-
let(:
|
324
|
-
Band.with(database: database_id_alt)
|
395
|
+
let(:instance_database) do
|
396
|
+
Band.with(database: database_id_alt) do |klass|
|
397
|
+
klass.new.mongo_client.database
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
let(:class_database) do
|
402
|
+
Band.with(database: database_id_alt) do |klass|
|
403
|
+
klass.mongo_client.database
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
let(:class_mongo_client) do
|
408
|
+
Band.with(database: database_id_alt) do |klass|
|
409
|
+
klass.new.mongo_client
|
410
|
+
end
|
325
411
|
end
|
326
412
|
|
327
413
|
before do
|
@@ -330,6 +416,7 @@ describe Mongoid::Clients do
|
|
330
416
|
|
331
417
|
after do
|
332
418
|
Band.reset_storage_options!
|
419
|
+
class_mongo_client.close
|
333
420
|
end
|
334
421
|
|
335
422
|
it_behaves_like "an overridden database name"
|
@@ -349,8 +436,22 @@ describe Mongoid::Clients do
|
|
349
436
|
|
350
437
|
context "when overriding the persistence options" do
|
351
438
|
|
352
|
-
let(:
|
353
|
-
Band.with(client:
|
439
|
+
let(:instance_database) do
|
440
|
+
Band.with(client: :alternative) do |klass|
|
441
|
+
klass.new.mongo_client.database
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
let(:class_database) do
|
446
|
+
Band.with(client: :alternative) do |klass|
|
447
|
+
klass.mongo_client.database
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
let(:class_mongo_client) do
|
452
|
+
Band.with(client: :alternative) do |klass|
|
453
|
+
klass.new.mongo_client
|
454
|
+
end
|
354
455
|
end
|
355
456
|
|
356
457
|
it_behaves_like "an overridden database name"
|
@@ -358,7 +459,17 @@ describe Mongoid::Clients do
|
|
358
459
|
|
359
460
|
context "when overriding with store_in" do
|
360
461
|
|
361
|
-
let(:
|
462
|
+
let(:instance_database) do
|
463
|
+
Band.new.mongo_client.database
|
464
|
+
end
|
465
|
+
|
466
|
+
let(:class_database) do
|
467
|
+
Band.mongo_client.database
|
468
|
+
end
|
469
|
+
|
470
|
+
let(:class_mongo_client) do
|
471
|
+
Band.mongo_client
|
472
|
+
end
|
362
473
|
|
363
474
|
before do
|
364
475
|
Band.store_in(client: client_name)
|
@@ -366,6 +477,7 @@ describe Mongoid::Clients do
|
|
366
477
|
|
367
478
|
after do
|
368
479
|
Band.reset_storage_options!
|
480
|
+
class_mongo_client.close
|
369
481
|
end
|
370
482
|
|
371
483
|
it_behaves_like "an overridden database name"
|
@@ -373,7 +485,7 @@ describe Mongoid::Clients do
|
|
373
485
|
end
|
374
486
|
end
|
375
487
|
|
376
|
-
describe "#mongo_client"
|
488
|
+
describe "#mongo_client" do
|
377
489
|
|
378
490
|
let(:file) do
|
379
491
|
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
@@ -397,6 +509,10 @@ describe Mongoid::Clients do
|
|
397
509
|
Mongoid.clients[:default][:database] = database_id
|
398
510
|
end
|
399
511
|
|
512
|
+
after do
|
513
|
+
mongo_client.close
|
514
|
+
end
|
515
|
+
|
400
516
|
let!(:band) do
|
401
517
|
Band.new
|
402
518
|
end
|
@@ -424,10 +540,6 @@ describe Mongoid::Clients do
|
|
424
540
|
Band.store_in(client: :nonexistent)
|
425
541
|
end
|
426
542
|
|
427
|
-
after do
|
428
|
-
Band.reset_storage_options!
|
429
|
-
end
|
430
|
-
|
431
543
|
let(:band) do
|
432
544
|
Band.new
|
433
545
|
end
|
@@ -439,7 +551,7 @@ describe Mongoid::Clients do
|
|
439
551
|
end
|
440
552
|
end
|
441
553
|
|
442
|
-
context "when getting a client by name"
|
554
|
+
context "when getting a client by name" do
|
443
555
|
|
444
556
|
let(:file) do
|
445
557
|
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
@@ -457,11 +569,7 @@ describe Mongoid::Clients do
|
|
457
569
|
Band.reset_storage_options!
|
458
570
|
end
|
459
571
|
|
460
|
-
let
|
461
|
-
Band.store_in(client: :reports)
|
462
|
-
end
|
463
|
-
|
464
|
-
let!(:mongo_client) do
|
572
|
+
let(:mongo_client) do
|
465
573
|
Band.new.mongo_client
|
466
574
|
end
|
467
575
|
|
@@ -497,7 +605,7 @@ describe Mongoid::Clients do
|
|
497
605
|
end
|
498
606
|
end
|
499
607
|
|
500
|
-
describe ".mongo_client"
|
608
|
+
describe ".mongo_client" do
|
501
609
|
|
502
610
|
let(:file) do
|
503
611
|
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
@@ -526,7 +634,7 @@ describe Mongoid::Clients do
|
|
526
634
|
Mongoid.clients[:default][:database] = database_id
|
527
635
|
end
|
528
636
|
|
529
|
-
let(:mongo_client) do
|
637
|
+
let!(:mongo_client) do
|
530
638
|
Band.mongo_client
|
531
639
|
end
|
532
640
|
|
@@ -568,7 +676,7 @@ describe Mongoid::Clients do
|
|
568
676
|
end
|
569
677
|
end
|
570
678
|
|
571
|
-
context "when provided a class that
|
679
|
+
context "when provided a class that extends another document" do
|
572
680
|
|
573
681
|
let(:klass) do
|
574
682
|
Class.new(Band)
|
@@ -599,7 +707,9 @@ describe Mongoid::Clients do
|
|
599
707
|
context "when changing write concern options" do
|
600
708
|
|
601
709
|
let(:client_one) do
|
602
|
-
Band.with(write: { w: 2 })
|
710
|
+
Band.with(write: { w: 2 }) do |klass|
|
711
|
+
klass.mongo_client
|
712
|
+
end
|
603
713
|
end
|
604
714
|
|
605
715
|
let(:client_two) do
|
@@ -614,13 +724,17 @@ describe Mongoid::Clients do
|
|
614
724
|
context "when sending operations to a different database" do
|
615
725
|
|
616
726
|
after do
|
617
|
-
Band.with(database: database_id_alt)
|
727
|
+
Band.with(database: database_id_alt) do |klass|
|
728
|
+
klass.delete_all
|
729
|
+
end
|
618
730
|
end
|
619
731
|
|
620
732
|
describe ".create" do
|
621
733
|
|
622
734
|
let!(:band) do
|
623
|
-
Band.with(database: database_id_alt)
|
735
|
+
Band.with(database: database_id_alt) do |klass|
|
736
|
+
klass.create
|
737
|
+
end
|
624
738
|
end
|
625
739
|
|
626
740
|
it "does not persist to the default database" do
|
@@ -630,15 +744,23 @@ describe Mongoid::Clients do
|
|
630
744
|
end
|
631
745
|
|
632
746
|
let(:from_db) do
|
633
|
-
Band.with(database: database_id_alt)
|
747
|
+
Band.with(database: database_id_alt) do |klass|
|
748
|
+
klass.find(band.id)
|
749
|
+
end
|
634
750
|
end
|
635
751
|
|
636
752
|
it "persists to the specified database" do
|
637
753
|
expect(from_db).to eq(band)
|
638
754
|
end
|
639
755
|
|
756
|
+
let(:count) do
|
757
|
+
Band.with(database: database_id_alt) do |klass|
|
758
|
+
klass.count
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
640
762
|
it "persists the correct number of documents" do
|
641
|
-
expect(
|
763
|
+
expect(count).to eq(1)
|
642
764
|
end
|
643
765
|
end
|
644
766
|
end
|
@@ -648,7 +770,9 @@ describe Mongoid::Clients do
|
|
648
770
|
describe ".create" do
|
649
771
|
|
650
772
|
let!(:band) do
|
651
|
-
Band.with(collection: "artists")
|
773
|
+
Band.with(collection: "artists") do |klass|
|
774
|
+
klass.create
|
775
|
+
end
|
652
776
|
end
|
653
777
|
|
654
778
|
it "does not persist to the default database" do
|
@@ -658,15 +782,23 @@ describe Mongoid::Clients do
|
|
658
782
|
end
|
659
783
|
|
660
784
|
let(:from_db) do
|
661
|
-
Band.with(collection: "artists")
|
785
|
+
Band.with(collection: "artists") do |klass|
|
786
|
+
klass.find(band.id)
|
787
|
+
end
|
662
788
|
end
|
663
789
|
|
664
790
|
it "persists to the specified database" do
|
665
791
|
expect(from_db).to eq(band)
|
666
792
|
end
|
667
793
|
|
794
|
+
let(:count) do
|
795
|
+
Band.with(collection: "artists") do |klass|
|
796
|
+
klass.count
|
797
|
+
end
|
798
|
+
end
|
799
|
+
|
668
800
|
it "persists the correct number of documents" do
|
669
|
-
expect(
|
801
|
+
expect(count).to eq(1)
|
670
802
|
end
|
671
803
|
end
|
672
804
|
end
|
@@ -676,10 +808,15 @@ describe Mongoid::Clients do
|
|
676
808
|
describe ".create" do
|
677
809
|
|
678
810
|
before do
|
811
|
+
Person.index({ ssn: 1 }, { unique: true })
|
679
812
|
Person.create_indexes
|
680
813
|
Person.create(ssn: "432-97-1111")
|
681
814
|
end
|
682
815
|
|
816
|
+
after do
|
817
|
+
Person.collection.drop
|
818
|
+
end
|
819
|
+
|
683
820
|
context "when no error occurs" do
|
684
821
|
|
685
822
|
it "inserts the document" do
|
@@ -703,6 +840,10 @@ describe Mongoid::Clients do
|
|
703
840
|
Person.create!(ssn: "432-97-1112")
|
704
841
|
end
|
705
842
|
|
843
|
+
after do
|
844
|
+
Person.collection.drop
|
845
|
+
end
|
846
|
+
|
706
847
|
context "when no error occurs" do
|
707
848
|
|
708
849
|
it "inserts the document" do
|
@@ -713,9 +854,14 @@ describe Mongoid::Clients do
|
|
713
854
|
context "when a mongodb error occurs" do
|
714
855
|
|
715
856
|
before do
|
857
|
+
Person.index({ ssn: 1 }, { unique: true })
|
716
858
|
Person.create_indexes
|
717
859
|
end
|
718
860
|
|
861
|
+
after do
|
862
|
+
Person.collection.drop
|
863
|
+
end
|
864
|
+
|
719
865
|
it "bubbles up to the caller" do
|
720
866
|
expect {
|
721
867
|
Person.create!(ssn: "432-97-1112")
|
@@ -746,9 +892,14 @@ describe Mongoid::Clients do
|
|
746
892
|
end
|
747
893
|
|
748
894
|
before do
|
895
|
+
Person.index({ ssn: 1 }, { unique: true })
|
749
896
|
Person.create_indexes
|
750
897
|
end
|
751
898
|
|
899
|
+
after do
|
900
|
+
Person.collection.drop
|
901
|
+
end
|
902
|
+
|
752
903
|
it "bubbles up to the caller" do
|
753
904
|
expect {
|
754
905
|
person.save
|
@@ -770,9 +921,14 @@ describe Mongoid::Clients do
|
|
770
921
|
end
|
771
922
|
|
772
923
|
before do
|
924
|
+
Person.index({ ssn: 1 }, { unique: true })
|
773
925
|
Person.create_indexes
|
774
926
|
end
|
775
927
|
|
928
|
+
after do
|
929
|
+
Person.collection.drop
|
930
|
+
end
|
931
|
+
|
776
932
|
it "bubbles up to the caller" do
|
777
933
|
expect {
|
778
934
|
person.save!
|
@@ -796,7 +952,7 @@ describe Mongoid::Clients do
|
|
796
952
|
end
|
797
953
|
end
|
798
954
|
|
799
|
-
context "when overriding the default database"
|
955
|
+
context "when overriding the default database" do
|
800
956
|
|
801
957
|
let(:file) do
|
802
958
|
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
@@ -808,42 +964,28 @@ describe Mongoid::Clients do
|
|
808
964
|
|
809
965
|
context "when the override is global" do
|
810
966
|
|
811
|
-
|
812
|
-
|
813
|
-
before do
|
814
|
-
Mongoid.override_database(:mongoid_optional)
|
815
|
-
end
|
816
|
-
|
817
|
-
after do
|
818
|
-
Band.delete_all
|
819
|
-
Mongoid.override_database(nil)
|
820
|
-
end
|
821
|
-
|
822
|
-
let!(:band) do
|
823
|
-
klass.create(name: "Tool")
|
824
|
-
end
|
825
|
-
|
826
|
-
it "persists to the overridden database" do
|
827
|
-
mongo_client = Band.mongo_client.with(database: :mongoid_optional)
|
828
|
-
expect(mongo_client[:bands].count(name: "Tool")).to eq(1)
|
829
|
-
end
|
830
|
-
|
831
|
-
it 'uses that database for the model mongo_client' do
|
832
|
-
expect(Band.mongo_client.database.name).to eq('mongoid_optional')
|
833
|
-
end
|
967
|
+
before do
|
968
|
+
Mongoid.override_database(:mongoid_optional)
|
834
969
|
end
|
835
970
|
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
971
|
+
after do
|
972
|
+
Band.delete_all
|
973
|
+
Band.mongo_client.close
|
974
|
+
Mongoid.override_database(nil)
|
840
975
|
end
|
841
976
|
|
842
|
-
|
977
|
+
let!(:band) do
|
978
|
+
Band.create(name: "Tool")
|
979
|
+
end
|
843
980
|
|
844
|
-
|
981
|
+
it "persists to the overridden database" do
|
982
|
+
Band.mongo_client.with(database: :mongoid_optional) do |sess|
|
983
|
+
expect(sess[:bands].find(name: "Tool")).to_not be_nil
|
984
|
+
end
|
985
|
+
end
|
845
986
|
|
846
|
-
|
987
|
+
it 'uses that database for the model mongo_client' do
|
988
|
+
expect(Band.mongo_client.database.name).to eq('mongoid_optional')
|
847
989
|
end
|
848
990
|
end
|
849
991
|
end
|