mongoid 7.0.6 → 7.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +1 -1
  5. data/Rakefile +14 -5
  6. data/lib/mongoid.rb +1 -1
  7. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  8. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  9. data/lib/mongoid/association/proxy.rb +1 -1
  10. data/lib/mongoid/atomic.rb +13 -3
  11. data/lib/mongoid/clients/sessions.rb +20 -4
  12. data/lib/mongoid/criteria.rb +7 -1
  13. data/lib/mongoid/criteria/modifiable.rb +2 -1
  14. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  15. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  16. data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
  17. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  18. data/lib/mongoid/document.rb +3 -2
  19. data/lib/mongoid/extensions/hash.rb +4 -2
  20. data/lib/mongoid/extensions/regexp.rb +1 -1
  21. data/lib/mongoid/fields.rb +2 -1
  22. data/lib/mongoid/interceptable.rb +3 -1
  23. data/lib/mongoid/matchable/regexp.rb +2 -2
  24. data/lib/mongoid/persistable/pushable.rb +11 -2
  25. data/lib/mongoid/persistence_context.rb +6 -6
  26. data/lib/mongoid/query_cache.rb +61 -18
  27. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  28. data/lib/mongoid/version.rb +1 -1
  29. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  30. data/spec/app/models/customer.rb +11 -0
  31. data/spec/app/models/customer_address.rb +12 -0
  32. data/spec/app/models/delegating_patient.rb +16 -0
  33. data/spec/integration/app_spec.rb +192 -0
  34. data/spec/integration/associations/embedded_spec.rb +62 -0
  35. data/spec/integration/callbacks_models.rb +49 -0
  36. data/spec/integration/callbacks_spec.rb +216 -0
  37. data/spec/integration/criteria/date_field_spec.rb +41 -0
  38. data/spec/integration/document_spec.rb +22 -0
  39. data/spec/lite_spec_helper.rb +12 -4
  40. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  41. data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
  42. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  43. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  44. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
  45. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  46. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  47. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  48. data/spec/mongoid/clients/options_spec.rb +4 -4
  49. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  50. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  51. data/spec/mongoid/clients_spec.rb +2 -2
  52. data/spec/mongoid/contextual/atomic_spec.rb +20 -10
  53. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  54. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  55. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  56. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  57. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  58. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  59. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  60. data/spec/mongoid/criteria_spec.rb +4 -2
  61. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  62. data/spec/mongoid/indexable_spec.rb +6 -4
  63. data/spec/mongoid/matchable/default_spec.rb +1 -1
  64. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  65. data/spec/mongoid/matchable_spec.rb +2 -2
  66. data/spec/mongoid/persistable/pushable_spec.rb +55 -1
  67. data/spec/mongoid/query_cache_spec.rb +77 -9
  68. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  69. data/spec/mongoid/scopable_spec.rb +2 -1
  70. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  71. data/spec/mongoid/tasks/database_spec.rb +1 -1
  72. data/spec/shared/LICENSE +20 -0
  73. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  74. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  75. data/spec/shared/lib/mrss/constraints.rb +330 -0
  76. data/spec/shared/lib/mrss/docker_runner.rb +262 -0
  77. data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
  78. data/spec/shared/lib/mrss/server_version_registry.rb +69 -0
  79. data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
  80. data/spec/shared/share/Dockerfile.erb +229 -0
  81. data/spec/shared/shlib/distro.sh +73 -0
  82. data/spec/shared/shlib/server.sh +270 -0
  83. data/spec/shared/shlib/set_env.sh +128 -0
  84. data/spec/spec_helper.rb +0 -31
  85. data/spec/support/child_process_helper.rb +76 -0
  86. data/spec/support/cluster_config.rb +3 -3
  87. data/spec/support/constraints.rb +201 -30
  88. data/spec/support/session_registry.rb +50 -0
  89. data/spec/support/spec_config.rb +12 -4
  90. metadata +510 -461
  91. metadata.gz.sig +2 -2
@@ -8,7 +8,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
8
8
  context "when provided a regexp" do
9
9
 
10
10
  let(:regexp) do
11
- /^[123]/
11
+ /\A[123]/
12
12
  end
13
13
 
14
14
  let(:evolved) do
@@ -23,7 +23,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
23
23
  context "when provided a string" do
24
24
 
25
25
  let(:regexp) do
26
- "^[123]"
26
+ "\\A[123]"
27
27
  end
28
28
 
29
29
  let(:evolved) do
@@ -31,7 +31,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
31
31
  end
32
32
 
33
33
  it "returns the converted regexp" do
34
- expect(evolved).to eq(/^[123]/)
34
+ expect(evolved).to eq(/\A[123]/)
35
35
  end
36
36
  end
37
37
 
@@ -40,7 +40,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
40
40
  context "when the elements are regexps" do
41
41
 
42
42
  let(:regexp) do
43
- /^[123]/
43
+ /\A[123]/
44
44
  end
45
45
 
46
46
  let(:array) do
@@ -63,7 +63,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
63
63
  context "when the elements are strings" do
64
64
 
65
65
  let(:regexp) do
66
- "^[123]"
66
+ "\\A[123]"
67
67
  end
68
68
 
69
69
  let(:evolved) do
@@ -71,7 +71,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
71
71
  end
72
72
 
73
73
  it "returns the regexps" do
74
- expect(evolved).to eq([ /^[123]/ ])
74
+ expect(evolved).to eq([ /\A[123]/ ])
75
75
  end
76
76
  end
77
77
  end
@@ -80,7 +80,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
80
80
  describe "#regexp?" do
81
81
 
82
82
  let(:regexp) do
83
- /^[123]/
83
+ /\A[123]/
84
84
  end
85
85
 
86
86
  it "returns true" do
@@ -315,7 +315,7 @@ describe String do
315
315
  context "when provided a regex" do
316
316
 
317
317
  let(:regex) do
318
- /^[123]/
318
+ /\A[123]/.freeze
319
319
  end
320
320
 
321
321
  let(:evolved) do
@@ -346,23 +346,35 @@ describe Time do
346
346
 
347
347
  describe "#__evolve_date__" do
348
348
 
349
- let(:time) do
350
- Time.new(2010, 1, 1, 12, 0, 0)
351
- end
352
-
353
349
  let(:evolved) do
354
350
  time.__evolve_date__
355
351
  end
356
352
 
357
- it "returns midnight utc" do
358
- expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
353
+ context 'beginning of day' do
354
+ let(:time) do
355
+ Time.new(2010, 1, 1, 0, 0, 1).freeze
356
+ end
357
+
358
+ it "returns midnight utc" do
359
+ expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
360
+ end
361
+ end
362
+
363
+ context 'end of day' do
364
+ let(:time) do
365
+ Time.new(2010, 1, 1, 23, 59, 59).freeze
366
+ end
367
+
368
+ it "returns midnight utc" do
369
+ expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
370
+ end
359
371
  end
360
372
  end
361
373
 
362
374
  describe "#__evolve_time__" do
363
375
 
364
376
  let(:time) do
365
- Time.new(2010, 1, 1, 12, 0, 0)
377
+ Time.new(2010, 1, 1, 12, 0, 0).freeze
366
378
  end
367
379
 
368
380
  let(:evolved) do
@@ -322,10 +322,37 @@ describe ActiveSupport::TimeWithZone do
322
322
  end
323
323
  end
324
324
 
325
+ describe "#__evolve_date__" do
326
+
327
+ let(:evolved) do
328
+ time.__evolve_date__
329
+ end
330
+
331
+ context 'beginning of day' do
332
+ let(:time) do
333
+ time_zone.local(2010, 1, 1, 0, 0, 1).freeze
334
+ end
335
+
336
+ it "returns midnight utc" do
337
+ expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
338
+ end
339
+ end
340
+
341
+ context 'end of day' do
342
+ let(:time) do
343
+ time_zone.local(2010, 1, 1, 23, 59, 59).freeze
344
+ end
345
+
346
+ it "returns midnight utc" do
347
+ expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
348
+ end
349
+ end
350
+ end
351
+
325
352
  describe "#__evolve_time__" do
326
353
 
327
354
  let(:date) do
328
- time_zone.local(2010, 1, 1, 12, 0, 0)
355
+ time_zone.local(2010, 1, 1, 12, 0, 0).freeze
329
356
  end
330
357
 
331
358
  let(:evolved) do
@@ -2334,7 +2334,7 @@ describe Mongoid::Criteria do
2334
2334
  end
2335
2335
 
2336
2336
  it "returns the map/reduce results" do
2337
- expect(map_reduce).to eq([
2337
+ expect(map_reduce.sort_by { |doc| doc['_id'] }).to eq([
2338
2338
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
2339
2339
  { "_id" => "Tool", "value" => { "likes" => 100 }}
2340
2340
  ])
@@ -3499,7 +3499,8 @@ describe Mongoid::Criteria do
3499
3499
  end
3500
3500
  end
3501
3501
 
3502
- context "when querying on a BSON::Decimal128", if: decimal128_supported? do
3502
+ context "when querying on a BSON::Decimal128" do
3503
+ min_server_version '3.4'
3503
3504
 
3504
3505
  let(:decimal) do
3505
3506
  BSON::Decimal128.new("0.0005")
@@ -3553,6 +3554,7 @@ describe Mongoid::Criteria do
3553
3554
  end
3554
3555
 
3555
3556
  context "when the code has scope" do
3557
+ max_server_version '4.2'
3556
3558
 
3557
3559
  let(:criteria) do
3558
3560
  Band.for_js("this.name == param", param: "Depeche Mode")
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require "spec_helper"
5
+
6
+ describe Mongoid::Document do
7
+
8
+ let(:klass) do
9
+ Person
10
+ end
11
+
12
+ let(:person) do
13
+ Person.new
14
+ end
15
+
16
+ describe '.client_name' do
17
+ it 'returns client name' do
18
+ Person.client_name.should == :default
19
+ end
20
+ end
21
+
22
+ describe '.database_name' do
23
+ it 'returns database name' do
24
+ Person.database_name.should == 'mongoid_test'
25
+ end
26
+ end
27
+
28
+ describe '.collection_name' do
29
+ it 'returns collection name' do
30
+ Person.collection_name.should == :people
31
+ end
32
+ end
33
+ end
@@ -45,7 +45,7 @@ describe Mongoid::Indexable do
45
45
  end
46
46
  end
47
47
 
48
- context "when database specific options exist", if: non_legacy_server? do
48
+ context "when database specific options exist" do
49
49
 
50
50
  let(:klass) do
51
51
  Class.new do
@@ -95,7 +95,7 @@ describe Mongoid::Indexable do
95
95
  end
96
96
  end
97
97
 
98
- context "when database options are specified", if: non_legacy_server? do
98
+ context "when database options are specified" do
99
99
 
100
100
  let(:klass) do
101
101
  Class.new do
@@ -133,7 +133,8 @@ describe Mongoid::Indexable do
133
133
  end
134
134
  end
135
135
 
136
- context "when a collation option is specified", if: collation_supported? do
136
+ context "when a collation option is specified" do
137
+ min_server_version '3.4'
137
138
 
138
139
  let(:klass) do
139
140
  Class.new do
@@ -308,7 +309,8 @@ describe Mongoid::Indexable do
308
309
  end
309
310
  end
310
311
 
311
- context "when providing a collation option", if: collation_supported? do
312
+ context "when providing a collation option" do
313
+ min_server_version '3.4'
312
314
 
313
315
  before do
314
316
  klass.index({ name: 1 }, collation: { locale: 'en_US', strength: 2 })
@@ -68,7 +68,7 @@ describe Mongoid::Matchable::Default do
68
68
  context "when the value is a regexp" do
69
69
 
70
70
  it "returns true" do
71
- expect(matcher._matches?(/^Test[3-5]$/)).to be true
71
+ expect(matcher._matches?(/\ATest[3-5]\z/)).to be true
72
72
  end
73
73
  end
74
74
  end
@@ -15,7 +15,7 @@ describe Mongoid::Matchable::Regexp do
15
15
  context 'when a BSON::Regexp::Raw object is passed' do
16
16
 
17
17
  let(:regexp) do
18
- BSON::Regexp::Raw.new('^Em')
18
+ BSON::Regexp::Raw.new("\\AEm")
19
19
  end
20
20
 
21
21
  it 'compiles the regexp object to a native regexp for the matching' do
@@ -37,7 +37,7 @@ describe Mongoid::Matchable::Regexp do
37
37
  context 'when a native Regexp object is passed' do
38
38
 
39
39
  let(:regexp) do
40
- /^Em/
40
+ /\AEm/
41
41
  end
42
42
 
43
43
  it 'calls super with the native regexp' do
@@ -293,7 +293,7 @@ describe Mongoid::Matchable do
293
293
  context 'when a BSON::Regexp::Raw object is used' do
294
294
 
295
295
  let(:selector) do
296
- { street: BSON::Regexp::Raw.new("^Clarkenwell") }
296
+ { street: BSON::Regexp::Raw.new("\\AClarkenwell") }
297
297
  end
298
298
 
299
299
  it "returns true" do
@@ -304,7 +304,7 @@ describe Mongoid::Matchable do
304
304
  context 'when a native Regexp object is used' do
305
305
 
306
306
  let(:selector) do
307
- { street: /^Clarkenwell/ }
307
+ { street: /\AClarkenwell/ }
308
308
  end
309
309
 
310
310
  it "returns true" do
@@ -4,7 +4,7 @@ describe Mongoid::Persistable::Pushable do
4
4
 
5
5
  describe "#add_to_set" do
6
6
 
7
- context "when the document is a root document" do
7
+ context "when the document is a top level document" do
8
8
 
9
9
  shared_examples_for "a unique pushable root document" do
10
10
 
@@ -62,6 +62,60 @@ describe Mongoid::Persistable::Pushable do
62
62
 
63
63
  it_behaves_like "a unique pushable root document"
64
64
  end
65
+
66
+ context 'when the host model is not saved' do
67
+ context 'when attribute exists' do
68
+ let(:person) do
69
+ Person.new(aliases: [2])
70
+ end
71
+
72
+ it 'records the change' do
73
+ person.add_to_set({aliases: 1})
74
+
75
+ expect(person.aliases).to eq([2, 1])
76
+ end
77
+ end
78
+
79
+ context 'when attribute does not exist' do
80
+ let(:person) do
81
+ Person.new
82
+ end
83
+
84
+ it 'records the change' do
85
+ person.add_to_set({aliases: 1})
86
+
87
+ expect(person.aliases).to eq([1])
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'when the host model is loaded from database' do
93
+ context 'when attribute exists' do
94
+ let(:person) do
95
+ Person.create!(aliases: [2])
96
+ person = Person.last
97
+ end
98
+
99
+ it 'records the change' do
100
+ person.add_to_set({aliases: 1})
101
+
102
+ expect(person.aliases).to eq([2, 1])
103
+ end
104
+ end
105
+
106
+ context 'when attribute does not exist' do
107
+ let(:person) do
108
+ Person.create!
109
+ person = Person.last
110
+ end
111
+
112
+ it 'records the change' do
113
+ person.add_to_set({aliases: 1})
114
+
115
+ expect(person.aliases).to eq([1])
116
+ end
117
+ end
118
+ end
65
119
  end
66
120
 
67
121
  context "when the document is embedded" do
@@ -7,6 +7,20 @@ describe Mongoid::QueryCache do
7
7
  Mongoid::QueryCache.cache { spec.run }
8
8
  end
9
9
 
10
+ before(:all) do
11
+ # It is likely that there are other session leaks in the driver
12
+ # and/or Mongoid that are unrelated to the query cache. Clear the
13
+ # SessionRegistry at the start of these tests in order to detect leaks that
14
+ # occur only within the scope of these tests.
15
+ #
16
+ # Other session leaks will be detected and addressed as part of RUBY-2391.
17
+ SessionRegistry.instance.clear_registry
18
+ end
19
+
20
+ after do
21
+ SessionRegistry.instance.verify_sessions_ended!
22
+ end
23
+
10
24
  context 'when iterating over objects sharing the same base' do
11
25
 
12
26
  let(:server) do
@@ -180,7 +194,8 @@ describe Mongoid::QueryCache do
180
194
  end
181
195
  end
182
196
 
183
- context 'when the first query has a collation', if: collation_supported? do
197
+ context 'when the first query has a collation' do
198
+ min_server_version '3.4'
184
199
 
185
200
  before do
186
201
  Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
@@ -221,6 +236,10 @@ describe Mongoid::QueryCache do
221
236
  end
222
237
 
223
238
  before do
239
+ 10.times do |i|
240
+ game.ratings << Rating.create!(value: i+1)
241
+ end
242
+
224
243
  game.ratings.where(:value.gt => 5).asc(:id).all.to_a
225
244
  end
226
245
 
@@ -228,7 +247,9 @@ describe Mongoid::QueryCache do
228
247
 
229
248
  it "uses the cache" do
230
249
  expect_no_queries do
231
- game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
250
+ result = game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
251
+ expect(result.length).to eq(2)
252
+ expect(result.map { |r| r['value'] }).to eq([6, 7])
232
253
  end
233
254
  end
234
255
  end
@@ -241,14 +262,23 @@ describe Mongoid::QueryCache do
241
262
  end
242
263
 
243
264
  before do
265
+ 10.times do |i|
266
+ game.ratings << Rating.create!(value: i+1)
267
+ end
268
+
244
269
  game.ratings.where(:value.gt => 5).limit(3).asc(:id).all.to_a
245
270
  end
246
271
 
247
272
  context "when the next query has a limit" do
273
+ # Server versions older than 3.2 also perform a killCursors operation,
274
+ # which causes this test to fail.
275
+ min_server_version '3.2'
248
276
 
249
277
  it "queries again" do
250
278
  expect_query(1) do
251
- game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
279
+ result = game.ratings.where(:value.gt => 5).limit(2).asc(:id).to_a
280
+ expect(result.length).to eq(2)
281
+ expect(result.map { |r| r['value'] }).to eq([6, 7])
252
282
  end
253
283
  end
254
284
  end
@@ -257,7 +287,9 @@ describe Mongoid::QueryCache do
257
287
 
258
288
  it "queries again" do
259
289
  expect_query(1) do
260
- game.ratings.where(:value.gt => 5).asc(:id).to_a
290
+ result = game.ratings.where(:value.gt => 5).asc(:id).to_a
291
+ expect(result.length).to eq(5)
292
+ expect(result.map { |r| r['value'] }).to eq([6, 7, 8, 9, 10])
261
293
  end
262
294
  end
263
295
  end
@@ -270,21 +302,34 @@ describe Mongoid::QueryCache do
270
302
  end
271
303
 
272
304
  before do
305
+ 10.times do |i|
306
+ game.ratings << Rating.create!(value: i+1)
307
+ end
308
+
273
309
  game.ratings.where(:value.gt => 5).asc(:id).all.to_a
274
310
  end
275
311
 
276
312
  it "does not query again" do
277
313
  expect_no_queries do
278
- game.ratings.where(:value.gt => 5).asc(:id).first
314
+ result = game.ratings.where(:value.gt => 5).asc(:id).first
315
+ expect(result['value']).to eq(6)
279
316
  end
280
317
  end
281
318
  end
282
319
 
283
320
  context "when limiting the result" do
321
+ before do
322
+ Band.destroy_all
323
+
324
+ 5.times { |i| Band.create!(name: "Band #{i}") }
325
+ Band.all.to_a
326
+ end
284
327
 
285
328
  it "does not query again" do
286
329
  expect_query(0) do
287
- Band.limit(2).all.to_a
330
+ result = Band.limit(2).all.to_a
331
+ expect(result.length).to eq(2)
332
+ expect(result.map { |r| r["name"] }).to eq(["Band 0", "Band 1"])
288
333
  end
289
334
  end
290
335
  end
@@ -292,12 +337,16 @@ describe Mongoid::QueryCache do
292
337
  context "when specifying a different skip value" do
293
338
 
294
339
  before do
295
- Band.limit(2).skip(1).all.to_a
340
+ Band.destroy_all
341
+
342
+ 5.times { |i| Band.create!(name: "Band #{i}") }
296
343
  end
297
344
 
298
345
  it "queries again" do
299
346
  expect_query(1) do
300
- Band.limit(2).skip(3).all.to_a
347
+ result = Band.limit(2).skip(3).all.to_a
348
+ expect(result.length).to eq(2)
349
+ expect(result.map { |r| r["name"] }).to eq(["Band 3", "Band 4"])
301
350
  end
302
351
  end
303
352
  end
@@ -333,6 +382,25 @@ describe Mongoid::QueryCache do
333
382
  end
334
383
  end
335
384
 
385
+ context 'when querying colleciton larger than the batch size' do
386
+ before do
387
+ Band.destroy_all
388
+ 101.times { |i| Band.create!(_id: i) }
389
+ end
390
+
391
+ it 'does not raise an exception when querying multiple times' do
392
+ expect do
393
+ results1 = Band.all.to_a
394
+ expect(results1.length).to eq(101)
395
+ expect(results1.map { |band| band["_id"] }).to eq([*0..100])
396
+
397
+ results2 = Band.all.to_a
398
+ expect(results2.length).to eq(101)
399
+ expect(results2.map { |band| band["_id"] }).to eq([*0..100])
400
+ end.not_to raise_error
401
+ end
402
+ end
403
+
336
404
  context "when query caching is enabled and the batch_size is set" do
337
405
 
338
406
  around(:each) do |example|
@@ -486,7 +554,7 @@ describe Mongoid::QueryCache do
486
554
  Mongoid::QueryCache.enabled = true
487
555
  10.times { Band.create! }
488
556
 
489
- Band.batch_size(4).all.any?
557
+ Band.batch_size(4).all.to_a
490
558
  end
491
559
 
492
560
  it 'does not cache the result' do