mongoid 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -1
- data/README.md +11 -19
- data/lib/config/locales/en.yml +33 -30
- data/lib/mongoid/atomic.rb +2 -4
- data/lib/mongoid/attributes/processing.rb +4 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/attributes.rb +7 -7
- data/lib/mongoid/changeable.rb +4 -6
- data/lib/mongoid/clients/factory.rb +78 -0
- data/lib/mongoid/{sessions → clients}/options.rb +30 -19
- data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
- data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
- data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
- data/lib/mongoid/clients/validators.rb +2 -0
- data/lib/mongoid/clients.rb +141 -0
- data/lib/mongoid/composable.rb +3 -3
- data/lib/mongoid/config/environment.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
- data/lib/mongoid/config/validators/option.rb +1 -1
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config.rb +39 -41
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +11 -11
- data/lib/mongoid/contextual/command.rb +9 -6
- data/lib/mongoid/contextual/geo_near.rb +17 -1
- data/lib/mongoid/contextual/map_reduce.rb +12 -11
- data/lib/mongoid/contextual/memory.rb +2 -5
- data/lib/mongoid/contextual/mongo.rb +92 -82
- data/lib/mongoid/contextual/none.rb +13 -0
- data/lib/mongoid/copyable.rb +6 -1
- data/lib/mongoid/criteria.rb +37 -4
- data/lib/mongoid/document.rb +3 -4
- data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
- data/lib/mongoid/errors/mongoid_error.rb +15 -9
- data/lib/mongoid/errors/no_client_config.rb +22 -0
- data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
- data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
- data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
- data/lib/mongoid/errors/no_default_client.rb +23 -0
- data/lib/mongoid/errors.rb +6 -6
- data/lib/mongoid/extensions/hash.rb +5 -1
- data/lib/mongoid/extensions/object.rb +3 -2
- data/lib/mongoid/extensions/set.rb +5 -5
- data/lib/mongoid/factory.rb +4 -2
- data/lib/mongoid/fields.rb +7 -2
- data/lib/mongoid/findable.rb +4 -1
- data/lib/mongoid/indexable.rb +15 -9
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +3 -3
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/poppable.rb +1 -1
- data/lib/mongoid/persistable/pullable.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +2 -2
- data/lib/mongoid/persistable/renamable.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +2 -2
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +1 -2
- data/lib/mongoid/query_cache.rb +98 -104
- data/lib/mongoid/railtie.rb +4 -25
- data/lib/mongoid/railties/database.rake +1 -1
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +3 -2
- data/lib/mongoid/relations/builders.rb +3 -1
- data/lib/mongoid/relations/counter_cache.rb +1 -1
- data/lib/mongoid/relations/embedded/batchable.rb +3 -10
- data/lib/mongoid/relations/embedded/many.rb +4 -2
- data/lib/mongoid/relations/embedded/one.rb +1 -0
- data/lib/mongoid/relations/many.rb +1 -0
- data/lib/mongoid/relations/metadata.rb +14 -0
- data/lib/mongoid/relations/proxy.rb +6 -6
- data/lib/mongoid/relations/referenced/many.rb +2 -1
- data/lib/mongoid/relations/targets/enumerable.rb +11 -11
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +6 -17
- data/lib/mongoid/selectable.rb +1 -36
- data/lib/mongoid/serializable.rb +2 -2
- data/lib/mongoid/stateful.rb +0 -1
- data/lib/mongoid/tasks/database.rake +2 -2
- data/lib/mongoid/tasks/database.rb +24 -17
- data/lib/mongoid/threaded/lifecycle.rb +21 -16
- data/lib/mongoid/threaded.rb +54 -33
- data/lib/mongoid/traversable.rb +17 -1
- data/lib/mongoid/validatable/queryable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +3 -20
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +28 -21
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
- data/lib/rails/mongoid.rb +2 -2
- data/spec/app/models/audio.rb +1 -1
- data/spec/app/models/band.rb +1 -0
- data/spec/app/models/code.rb +6 -0
- data/spec/app/models/company.rb +5 -0
- data/spec/app/models/label.rb +7 -0
- data/spec/app/models/pub.rb +6 -0
- data/spec/app/models/staff.rb +7 -0
- data/spec/app/models/store_as_dup_test1.rb +5 -0
- data/spec/app/models/store_as_dup_test2.rb +5 -0
- data/spec/config/mongoid.yml +7 -25
- data/spec/mongoid/atomic/paths_spec.rb +3 -11
- data/spec/mongoid/attributes/nested_spec.rb +16 -16
- data/spec/mongoid/attributes/readonly_spec.rb +80 -18
- data/spec/mongoid/attributes_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +156 -0
- data/spec/mongoid/clients/factory_spec.rb +284 -0
- data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
- data/spec/mongoid/clients_spec.rb +754 -0
- data/spec/mongoid/config/environment_spec.rb +14 -11
- data/spec/mongoid/config_spec.rb +33 -48
- data/spec/mongoid/contextual/atomic_spec.rb +1 -17
- data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
- data/spec/mongoid/contextual/mongo_spec.rb +26 -83
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +35 -1
- data/spec/mongoid/criteria/findable_spec.rb +197 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
- data/spec/mongoid/criteria_spec.rb +74 -91
- data/spec/mongoid/document_spec.rb +1 -1
- data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
- data/spec/mongoid/errors/mongoid_error_spec.rb +19 -3
- data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
- data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
- data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
- data/spec/mongoid/fields/localized_spec.rb +1 -0
- data/spec/mongoid/fields_spec.rb +1 -0
- data/spec/mongoid/findable_spec.rb +2 -23
- data/spec/mongoid/indexable_spec.rb +12 -8
- data/spec/mongoid/interceptable_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +16 -0
- data/spec/mongoid/persistable/updatable_spec.rb +3 -2
- data/spec/mongoid/persistable_spec.rb +4 -4
- data/spec/mongoid/query_cache_spec.rb +13 -8
- data/spec/mongoid/relations/auto_save_spec.rb +1 -1
- data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
- data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
- data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
- data/spec/mongoid/relations/proxy_spec.rb +28 -0
- data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
- data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
- data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
- data/spec/mongoid/reloadable_spec.rb +6 -6
- data/spec/mongoid/scopable_spec.rb +41 -28
- data/spec/mongoid/selectable_spec.rb +6 -16
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +2 -2
- data/spec/mongoid/threaded_spec.rb +0 -7
- data/spec/mongoid/traversable_spec.rb +2 -2
- data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
- data/spec/mongoid_spec.rb +13 -15
- data/spec/rails/mongoid_spec.rb +13 -4
- data/spec/spec_helper.rb +44 -27
- data/spec/support/authorization.rb +12 -0
- data/spec/support/expectations.rb +14 -0
- metadata +50 -57
- data/lib/mongoid/contextual/find_and_modify.rb +0 -69
- data/lib/mongoid/contextual/text_search.rb +0 -178
- data/lib/mongoid/criteria/#findable.rb# +0 -141
- data/lib/mongoid/errors/no_default_session.rb +0 -23
- data/lib/mongoid/errors/no_session_config.rb +0 -22
- data/lib/mongoid/log_subscriber.rb +0 -55
- data/lib/mongoid/positional.rb +0 -71
- data/lib/mongoid/sessions/factory.rb +0 -131
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/sessions.rb +0 -125
- data/lib/mongoid/support/query_counter.rb +0 -23
- data/spec/helpers.rb +0 -18
- data/spec/mongoid/#atomic_spec.rb# +0 -365
- data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
- data/spec/mongoid/contextual/text_search_spec.rb +0 -209
- data/spec/mongoid/log_subscriber_spec.rb +0 -75
- data/spec/mongoid/positional_spec.rb +0 -222
- data/spec/mongoid/sessions/factory_spec.rb +0 -333
- data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
- data/spec/mongoid/sessions_spec.rb +0 -1252
|
@@ -292,7 +292,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
292
292
|
it "raises an error" do
|
|
293
293
|
expect {
|
|
294
294
|
person.posts.send(method, post)
|
|
295
|
-
}.to raise_error(
|
|
295
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
|
296
296
|
end
|
|
297
297
|
end
|
|
298
298
|
end
|
|
@@ -1536,7 +1536,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
1536
1536
|
person.posts.create do |doc|
|
|
1537
1537
|
doc._id = existing.id
|
|
1538
1538
|
end
|
|
1539
|
-
}.to raise_error(
|
|
1539
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
|
1540
1540
|
end
|
|
1541
1541
|
end
|
|
1542
1542
|
end
|
|
@@ -2164,30 +2164,24 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
2164
2164
|
|
|
2165
2165
|
describe "#find" do
|
|
2166
2166
|
|
|
2167
|
-
context "when
|
|
2167
|
+
context "when iterating after the find" do
|
|
2168
2168
|
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
Person.create
|
|
2173
|
-
end
|
|
2174
|
-
|
|
2175
|
-
before do
|
|
2176
|
-
person.posts.create(title: "Test")
|
|
2177
|
-
end
|
|
2169
|
+
let(:person) do
|
|
2170
|
+
Person.create!
|
|
2171
|
+
end
|
|
2178
2172
|
|
|
2179
|
-
|
|
2173
|
+
let(:post_id) do
|
|
2174
|
+
person.posts.first.id
|
|
2175
|
+
end
|
|
2180
2176
|
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2177
|
+
before do
|
|
2178
|
+
5.times { person.posts.create! }
|
|
2179
|
+
end
|
|
2184
2180
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
end
|
|
2190
|
-
end
|
|
2181
|
+
it "does not change the in memory size" do
|
|
2182
|
+
expect {
|
|
2183
|
+
person.posts.find(post_id)
|
|
2184
|
+
}.not_to change { person.posts.to_a.size }
|
|
2191
2185
|
end
|
|
2192
2186
|
end
|
|
2193
2187
|
|
|
@@ -2807,6 +2801,35 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
2807
2801
|
end
|
|
2808
2802
|
end
|
|
2809
2803
|
|
|
2804
|
+
describe "#last" do
|
|
2805
|
+
|
|
2806
|
+
let(:person) do
|
|
2807
|
+
Person.create!
|
|
2808
|
+
end
|
|
2809
|
+
|
|
2810
|
+
let!(:persisted_post) do
|
|
2811
|
+
person.posts.create!
|
|
2812
|
+
end
|
|
2813
|
+
|
|
2814
|
+
context "when a new document is added" do
|
|
2815
|
+
|
|
2816
|
+
let!(:new_post) do
|
|
2817
|
+
person.posts.new
|
|
2818
|
+
end
|
|
2819
|
+
|
|
2820
|
+
context "when the target is subsequently loaded" do
|
|
2821
|
+
|
|
2822
|
+
before do
|
|
2823
|
+
person.posts.entries
|
|
2824
|
+
end
|
|
2825
|
+
|
|
2826
|
+
it "returns the expected last document" do
|
|
2827
|
+
expect(person.posts.last).to eq(new_post)
|
|
2828
|
+
end
|
|
2829
|
+
end
|
|
2830
|
+
end
|
|
2831
|
+
end
|
|
2832
|
+
|
|
2810
2833
|
describe ".macro" do
|
|
2811
2834
|
|
|
2812
2835
|
it "returns has_many" do
|
|
@@ -3344,7 +3367,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
3344
3367
|
|
|
3345
3368
|
before do
|
|
3346
3369
|
Post.collection.find({ _id: post_one.id }).
|
|
3347
|
-
|
|
3370
|
+
update_one({ "$set" => { title: "reloaded" }})
|
|
3348
3371
|
end
|
|
3349
3372
|
|
|
3350
3373
|
let(:reloaded) do
|
|
@@ -3687,6 +3710,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
|
3687
3710
|
end
|
|
3688
3711
|
|
|
3689
3712
|
context "when accessing a relation named parent" do
|
|
3713
|
+
|
|
3690
3714
|
let!(:parent) do
|
|
3691
3715
|
Odd.create(name: "odd parent")
|
|
3692
3716
|
end
|
|
@@ -3274,7 +3274,7 @@ describe Mongoid::Relations::Referenced::ManyToMany do
|
|
|
3274
3274
|
|
|
3275
3275
|
before do
|
|
3276
3276
|
Preference.collection.find({ _id: preference_one.id }).
|
|
3277
|
-
|
|
3277
|
+
update_one({ "$set" => { name: "reloaded" }})
|
|
3278
3278
|
end
|
|
3279
3279
|
|
|
3280
3280
|
let(:reloaded) do
|
|
@@ -1178,7 +1178,7 @@ describe Mongoid::Relations::Referenced::One do
|
|
|
1178
1178
|
|
|
1179
1179
|
before do
|
|
1180
1180
|
Game.collection.find({ _id: game_one.id }).
|
|
1181
|
-
|
|
1181
|
+
update_one({ "$set" => { name: "Diablo 2" }})
|
|
1182
1182
|
end
|
|
1183
1183
|
|
|
1184
1184
|
let(:reloaded) do
|
|
@@ -122,6 +122,13 @@ describe Mongoid::Relations::Targets::Enumerable do
|
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
+
context "when compared to an enumerable class" do
|
|
126
|
+
|
|
127
|
+
it "returns true" do
|
|
128
|
+
expect(enumerable === described_class).to be true
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
125
132
|
context "when compared to a different class" do
|
|
126
133
|
|
|
127
134
|
it "returns false" do
|
|
@@ -1186,7 +1193,7 @@ describe Mongoid::Relations::Targets::Enumerable do
|
|
|
1186
1193
|
context "when the enumerable is not loaded" do
|
|
1187
1194
|
|
|
1188
1195
|
let(:criteria) do
|
|
1189
|
-
Post.where(person_id: person.id)
|
|
1196
|
+
Post.asc(:_id).where(person_id: person.id)
|
|
1190
1197
|
end
|
|
1191
1198
|
|
|
1192
1199
|
let(:enumerable) do
|
|
@@ -1272,7 +1279,7 @@ describe Mongoid::Relations::Targets::Enumerable do
|
|
|
1272
1279
|
context "when accessing from a reloaded child" do
|
|
1273
1280
|
|
|
1274
1281
|
it "returns the last document" do
|
|
1275
|
-
expect(post_one.reload.person.posts.last).to eq(post_two)
|
|
1282
|
+
expect(post_one.reload.person.posts.asc(:_id).last).to eq(post_two)
|
|
1276
1283
|
end
|
|
1277
1284
|
end
|
|
1278
1285
|
end
|
|
@@ -115,7 +115,7 @@ describe Mongoid::Reloadable do
|
|
|
115
115
|
before do
|
|
116
116
|
Person.collection.find(
|
|
117
117
|
{ "_id" => person.id }
|
|
118
|
-
).
|
|
118
|
+
).update_one({ "$set" => { "addresses.0.number" => 3 }})
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
let!(:reloaded) do
|
|
@@ -143,7 +143,7 @@ describe Mongoid::Reloadable do
|
|
|
143
143
|
|
|
144
144
|
before do
|
|
145
145
|
Person.collection.find({ "_id" => person.id }).
|
|
146
|
-
|
|
146
|
+
update_one({ "$set" => { "name.last_name" => "Vicious" }})
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
let!(:reloaded) do
|
|
@@ -176,7 +176,7 @@ describe Mongoid::Reloadable do
|
|
|
176
176
|
|
|
177
177
|
before do
|
|
178
178
|
Person.collection.find({ "_id" => person.id }).
|
|
179
|
-
|
|
179
|
+
update_one({ "$set" => { "addresses.0.locations.0.name" => "work" }})
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
let!(:reloaded) do
|
|
@@ -209,7 +209,7 @@ describe Mongoid::Reloadable do
|
|
|
209
209
|
|
|
210
210
|
before do
|
|
211
211
|
Person.collection.find({ "_id" => person.id }).
|
|
212
|
-
|
|
212
|
+
update_one({ "$set" => { "addresses" => [] }})
|
|
213
213
|
person.reload
|
|
214
214
|
end
|
|
215
215
|
|
|
@@ -232,7 +232,7 @@ describe Mongoid::Reloadable do
|
|
|
232
232
|
|
|
233
233
|
before do
|
|
234
234
|
Game.collection.find({ "_id" => game.id }).
|
|
235
|
-
|
|
235
|
+
update_one({ "$set" => { "score" => 75 }})
|
|
236
236
|
person.reload
|
|
237
237
|
end
|
|
238
238
|
|
|
@@ -251,7 +251,7 @@ describe Mongoid::Reloadable do
|
|
|
251
251
|
|
|
252
252
|
before do
|
|
253
253
|
Person.collection.find({ "_id" => person.id }).
|
|
254
|
-
|
|
254
|
+
update_one({ "$set" => { "title" => "Mam" }})
|
|
255
255
|
game.reload
|
|
256
256
|
end
|
|
257
257
|
|
|
@@ -144,11 +144,11 @@ describe Mongoid::Scopable do
|
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
before do
|
|
147
|
-
|
|
147
|
+
Mongoid::Threaded.current_scope = criteria
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
after do
|
|
151
|
-
|
|
151
|
+
Mongoid::Threaded.current_scope = nil
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it "returns the criteria on the stack" do
|
|
@@ -567,13 +567,9 @@ describe Mongoid::Scopable do
|
|
|
567
567
|
|
|
568
568
|
context "when both scopes are or queries" do
|
|
569
569
|
|
|
570
|
-
let(:time) do
|
|
571
|
-
Time.now
|
|
572
|
-
end
|
|
573
|
-
|
|
574
570
|
before do
|
|
575
571
|
Band.scope(:xxx, ->{ Band.any_of({ :aaa.gt => 0 }, { :bbb.gt => 0 }) })
|
|
576
|
-
Band.scope(:yyy, ->{ Band.any_of({ :ccc => nil }, { :ccc.gt =>
|
|
572
|
+
Band.scope(:yyy, ->{ Band.any_of({ :ccc => nil }, { :ccc.gt => 1 }) })
|
|
577
573
|
end
|
|
578
574
|
|
|
579
575
|
after do
|
|
@@ -592,7 +588,7 @@ describe Mongoid::Scopable do
|
|
|
592
588
|
expect(criteria.selector).to eq({
|
|
593
589
|
"$or" => [
|
|
594
590
|
{ "ccc" => nil },
|
|
595
|
-
{ "ccc" => { "$gt" =>
|
|
591
|
+
{ "ccc" => { "$gt" => 1.0 }},
|
|
596
592
|
{ "aaa" => { "$gt" => 0.0 }},
|
|
597
593
|
{ "bbb" => { "$gt" => 0.0 }}
|
|
598
594
|
]
|
|
@@ -644,33 +640,34 @@ describe Mongoid::Scopable do
|
|
|
644
640
|
expect(circle_scope_keys).to match_array([:located_at, :with_radius])
|
|
645
641
|
end
|
|
646
642
|
end
|
|
647
|
-
end
|
|
648
|
-
|
|
649
|
-
describe ".scope_stack" do
|
|
650
|
-
|
|
651
|
-
context "when the scope stack has not been accessed" do
|
|
652
|
-
|
|
653
|
-
it "returns an empty array" do
|
|
654
|
-
expect(Band.scope_stack).to eq([])
|
|
655
|
-
end
|
|
656
|
-
end
|
|
657
643
|
|
|
658
|
-
context "when a
|
|
659
|
-
|
|
660
|
-
let(:criteria) do
|
|
661
|
-
Band.where(active: true)
|
|
662
|
-
end
|
|
644
|
+
context "when calling a scope defined in a parent class" do
|
|
663
645
|
|
|
664
646
|
before do
|
|
665
|
-
|
|
647
|
+
Shape.class_eval do
|
|
648
|
+
scope :visible, -> { large }
|
|
649
|
+
scope :large, -> { all }
|
|
650
|
+
end
|
|
651
|
+
Circle.class_eval do
|
|
652
|
+
scope :large, -> { where(radius: 5) }
|
|
653
|
+
end
|
|
666
654
|
end
|
|
667
655
|
|
|
668
656
|
after do
|
|
669
|
-
|
|
657
|
+
class << Shape
|
|
658
|
+
undef_method :visible
|
|
659
|
+
undef_method :large
|
|
660
|
+
end
|
|
661
|
+
Shape._declared_scopes.clear
|
|
662
|
+
|
|
663
|
+
class << Circle
|
|
664
|
+
undef_method :large
|
|
665
|
+
end
|
|
666
|
+
Circle._declared_scopes.clear
|
|
670
667
|
end
|
|
671
668
|
|
|
672
|
-
it "
|
|
673
|
-
expect(
|
|
669
|
+
it "uses sublcass context for all the other used scopes" do
|
|
670
|
+
expect(Circle.visible.selector).to eq("radius" => 5)
|
|
674
671
|
end
|
|
675
672
|
end
|
|
676
673
|
end
|
|
@@ -784,6 +781,22 @@ describe Mongoid::Scopable do
|
|
|
784
781
|
expect(unscoped.selector).to be_empty
|
|
785
782
|
end
|
|
786
783
|
end
|
|
784
|
+
|
|
785
|
+
context "when default scope is in a super class" do
|
|
786
|
+
|
|
787
|
+
before do
|
|
788
|
+
Band.scope(:active, ->{ Band.where(active: true) })
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
let(:unscoped) do
|
|
792
|
+
class U2 < Band; end
|
|
793
|
+
U2.unscoped.active
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
it "clears default scope" do
|
|
797
|
+
expect(unscoped.selector).to eq({ "active" => true })
|
|
798
|
+
end
|
|
799
|
+
end
|
|
787
800
|
end
|
|
788
801
|
|
|
789
802
|
context "when used with a block" do
|
|
@@ -888,7 +901,7 @@ describe Mongoid::Scopable do
|
|
|
888
901
|
|
|
889
902
|
it "pops the criteria off the stack" do
|
|
890
903
|
Band.with_scope(criteria) {}
|
|
891
|
-
expect(
|
|
904
|
+
expect(Mongoid::Threaded.current_scope).to be_nil
|
|
892
905
|
end
|
|
893
906
|
end
|
|
894
907
|
|
|
@@ -82,10 +82,8 @@ describe Mongoid::Selectable do
|
|
|
82
82
|
person.create_name(first_name: "test", last_name: "user")
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
it "returns the hash with the selector" do
|
|
86
|
-
expect(name.atomic_selector).to eq(
|
|
87
|
-
{ "_id" => person.id, "name._id" => name.id }
|
|
88
|
-
)
|
|
85
|
+
it "returns the hash with the root selector" do
|
|
86
|
+
expect(name.atomic_selector).to eq({ "_id" => person.id })
|
|
89
87
|
end
|
|
90
88
|
end
|
|
91
89
|
|
|
@@ -95,10 +93,8 @@ describe Mongoid::Selectable do
|
|
|
95
93
|
person.addresses.create(street: "kreuzbergstr")
|
|
96
94
|
end
|
|
97
95
|
|
|
98
|
-
it "returns the hash with the selector" do
|
|
99
|
-
expect(address.atomic_selector).to eq(
|
|
100
|
-
{ "_id" => person.id, "addresses._id" => address.id }
|
|
101
|
-
)
|
|
96
|
+
it "returns the hash with the root selector" do
|
|
97
|
+
expect(address.atomic_selector).to eq({ "_id" => person.id })
|
|
102
98
|
end
|
|
103
99
|
|
|
104
100
|
context "when the document's id changes" do
|
|
@@ -118,14 +114,8 @@ describe Mongoid::Selectable do
|
|
|
118
114
|
address.locations.create
|
|
119
115
|
end
|
|
120
116
|
|
|
121
|
-
it "returns a hash with the selector" do
|
|
122
|
-
expect(location.atomic_selector).to eq(
|
|
123
|
-
{
|
|
124
|
-
"_id" => person.id,
|
|
125
|
-
"addresses._id" => address.id,
|
|
126
|
-
"addresses.0.locations._id" => location.id
|
|
127
|
-
}
|
|
128
|
-
)
|
|
117
|
+
it "returns a hash with the root selector" do
|
|
118
|
+
expect(location.atomic_selector).to eq({ "_id" => person.id })
|
|
129
119
|
end
|
|
130
120
|
end
|
|
131
121
|
end
|
|
@@ -45,7 +45,7 @@ shared_context "rails rake task" do
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
describe "db:drop" do
|
|
48
|
+
describe "db:drop", if: non_legacy_server? do
|
|
49
49
|
include_context "rake task"
|
|
50
50
|
include_context "rails rake task"
|
|
51
51
|
|
|
@@ -58,7 +58,7 @@ describe "db:drop" do
|
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
describe "db:purge" do
|
|
61
|
+
describe "db:purge", if: non_legacy_server? do
|
|
62
62
|
include_context "rake task"
|
|
63
63
|
include_context "rails rake task"
|
|
64
64
|
|
|
@@ -71,7 +71,7 @@ describe "db:purge" do
|
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
describe "db:seed" do
|
|
74
|
+
describe "db:seed", if: non_legacy_server? do
|
|
75
75
|
include_context "rake task"
|
|
76
76
|
include_context "rails rake task"
|
|
77
77
|
|
|
@@ -85,7 +85,7 @@ describe "db:seed" do
|
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
describe "db:setup" do
|
|
88
|
+
describe "db:setup", if: non_legacy_server? do
|
|
89
89
|
include_context "rake task"
|
|
90
90
|
include_context "rails rake task"
|
|
91
91
|
|
|
@@ -117,7 +117,7 @@ describe "db:setup" do
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
-
describe "db:reset" do
|
|
120
|
+
describe "db:reset", if: non_legacy_server? do
|
|
121
121
|
include_context "rake task"
|
|
122
122
|
include_context "rails rake task"
|
|
123
123
|
|
|
@@ -135,7 +135,7 @@ describe "db:reset" do
|
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
describe "db:create" do
|
|
138
|
+
describe "db:create", if: non_legacy_server? do
|
|
139
139
|
include_context "rake task"
|
|
140
140
|
include_context "rails rake task"
|
|
141
141
|
|
|
@@ -144,7 +144,7 @@ describe "db:create" do
|
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
describe "db:migrate" do
|
|
147
|
+
describe "db:migrate", if: non_legacy_server? do
|
|
148
148
|
include_context "rake task"
|
|
149
149
|
include_context "rails rake task"
|
|
150
150
|
|
|
@@ -153,7 +153,7 @@ describe "db:migrate" do
|
|
|
153
153
|
end
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
-
describe "db:test:prepare" do
|
|
156
|
+
describe "db:test:prepare", if: non_legacy_server? do
|
|
157
157
|
include_context "rake task"
|
|
158
158
|
include_context "rails rake task"
|
|
159
159
|
|
|
@@ -174,7 +174,7 @@ describe "db:test:prepare" do
|
|
|
174
174
|
end
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
describe "db:mongoid:create_indexes" do
|
|
177
|
+
describe "db:mongoid:create_indexes", if: non_legacy_server? do
|
|
178
178
|
include_context "rake task"
|
|
179
179
|
|
|
180
180
|
it_behaves_like "create_indexes"
|
|
@@ -198,7 +198,7 @@ describe "db:mongoid:create_indexes" do
|
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
describe "db:mongoid:remove_undefined_indexes" do
|
|
201
|
+
describe "db:mongoid:remove_undefined_indexes", if: non_legacy_server? do
|
|
202
202
|
include_context "rake task"
|
|
203
203
|
|
|
204
204
|
it "receives remove_undefined_indexes" do
|
|
@@ -224,7 +224,7 @@ describe "db:mongoid:remove_undefined_indexes" do
|
|
|
224
224
|
end
|
|
225
225
|
end
|
|
226
226
|
|
|
227
|
-
describe "db:mongoid:remove_indexes" do
|
|
227
|
+
describe "db:mongoid:remove_indexes", if: non_legacy_server? do
|
|
228
228
|
include_context "rake task"
|
|
229
229
|
|
|
230
230
|
it "receives remove_indexes" do
|
|
@@ -250,7 +250,7 @@ describe "db:mongoid:remove_indexes" do
|
|
|
250
250
|
end
|
|
251
251
|
end
|
|
252
252
|
|
|
253
|
-
describe "db:mongoid:drop" do
|
|
253
|
+
describe "db:mongoid:drop", if: non_legacy_server? do
|
|
254
254
|
include_context "rake task"
|
|
255
255
|
|
|
256
256
|
it "works" do
|
|
@@ -266,7 +266,7 @@ describe "db:mongoid:drop" do
|
|
|
266
266
|
end
|
|
267
267
|
end
|
|
268
268
|
|
|
269
|
-
describe "db:mongoid:purge" do
|
|
269
|
+
describe "db:mongoid:purge", if: non_legacy_server? do
|
|
270
270
|
include_context "rake task"
|
|
271
271
|
|
|
272
272
|
it "receives a purge" do
|
|
@@ -100,7 +100,7 @@ describe "Mongoid::Tasks::Database" do
|
|
|
100
100
|
context "with extra index on model collection" do
|
|
101
101
|
|
|
102
102
|
before(:each) do
|
|
103
|
-
User.collection.indexes.
|
|
103
|
+
User.collection.indexes.create_one(account_expires: 1)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
let(:names) do
|
|
@@ -121,7 +121,7 @@ describe "Mongoid::Tasks::Database" do
|
|
|
121
121
|
|
|
122
122
|
before(:each) do
|
|
123
123
|
Mongoid::Tasks::Database.create_indexes(models)
|
|
124
|
-
indexes.
|
|
124
|
+
indexes.create_one(account_expires: 1)
|
|
125
125
|
Mongoid::Tasks::Database.remove_undefined_indexes(models)
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -106,13 +106,6 @@ describe Mongoid::Threaded do
|
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
describe "#scope_stack" do
|
|
110
|
-
|
|
111
|
-
it "returns the default with the scope stack key" do
|
|
112
|
-
expect(described_class.scope_stack).to be_a(Hash)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
109
|
describe "#begin_validate" do
|
|
117
110
|
|
|
118
111
|
let(:person) do
|
|
@@ -71,14 +71,14 @@ describe Mongoid::Traversable do
|
|
|
71
71
|
context "when the document is a subclass" do
|
|
72
72
|
|
|
73
73
|
it "returns true" do
|
|
74
|
-
expect(Circle).to
|
|
74
|
+
expect(Circle.hereditary?).to be true
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
context "when the document is not a subclass" do
|
|
79
79
|
|
|
80
80
|
it "returns false" do
|
|
81
|
-
expect(Shape).
|
|
81
|
+
expect(Shape.hereditary?).to be false
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -147,6 +147,35 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
147
147
|
Dictionary.reset_callbacks(:validate)
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
+
context "when no attribute is set" do
|
|
151
|
+
|
|
152
|
+
context "when no document with no value exists in the database" do
|
|
153
|
+
|
|
154
|
+
let(:dictionary) do
|
|
155
|
+
Dictionary.new
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "returns true" do
|
|
159
|
+
expect(dictionary).to be_valid
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context "when a document with no value exists in the database" do
|
|
164
|
+
|
|
165
|
+
before do
|
|
166
|
+
Dictionary.create
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
let(:dictionary) do
|
|
170
|
+
Dictionary.new
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "returns false" do
|
|
174
|
+
expect(dictionary).to_not be_valid
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
150
179
|
context "when the attribute is unique" do
|
|
151
180
|
|
|
152
181
|
context "when single localization" do
|
|
@@ -2382,7 +2411,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2382
2411
|
Person.reset_callbacks(:validate)
|
|
2383
2412
|
end
|
|
2384
2413
|
|
|
2385
|
-
it "transfers the options to the cloned
|
|
2414
|
+
it "transfers the options to the cloned client" do
|
|
2386
2415
|
expect {
|
|
2387
2416
|
Person.create!(ssn: "132-11-1111", username: "asdfsdfA")
|
|
2388
2417
|
}.to raise_error
|
data/spec/mongoid_spec.rb
CHANGED
|
@@ -31,37 +31,35 @@ describe Mongoid do
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
describe ".
|
|
34
|
+
describe ".default_client" do
|
|
35
35
|
|
|
36
|
-
it "returns the default
|
|
37
|
-
expect(Mongoid.
|
|
36
|
+
it "returns the default client" do
|
|
37
|
+
expect(Mongoid.default_client).to eq(Mongoid::Clients.default)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
describe ".
|
|
41
|
+
describe ".disconnect_clients" do
|
|
42
42
|
|
|
43
|
-
let(:
|
|
44
|
-
Mongoid::
|
|
43
|
+
let(:clients) do
|
|
44
|
+
Mongoid::Clients.clients.values
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
before do
|
|
48
48
|
Band.all.entries
|
|
49
|
-
Mongoid.disconnect_sessions
|
|
50
49
|
end
|
|
51
50
|
|
|
52
|
-
it "disconnects from all active
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(node.send(:connected?)).to be false
|
|
56
|
-
end
|
|
51
|
+
it "disconnects from all active clients" do
|
|
52
|
+
clients.each do |client|
|
|
53
|
+
expect(client.cluster).to receive(:disconnect!).and_call_original
|
|
57
54
|
end
|
|
55
|
+
Mongoid.disconnect_clients
|
|
58
56
|
end
|
|
59
57
|
end
|
|
60
58
|
|
|
61
|
-
describe ".
|
|
59
|
+
describe ".client" do
|
|
62
60
|
|
|
63
|
-
it "returns the named
|
|
64
|
-
expect(Mongoid.
|
|
61
|
+
it "returns the named client" do
|
|
62
|
+
expect(Mongoid.client(:default)).to eq(Mongoid::Clients.default)
|
|
65
63
|
end
|
|
66
64
|
end
|
|
67
65
|
|