mongoid 7.1.0 → 7.1.6

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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +6 -6
  5. data/README.md +1 -1
  6. data/Rakefile +14 -5
  7. data/lib/config/locales/en.yml +5 -5
  8. data/lib/mongoid/association/accessors.rb +37 -2
  9. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  10. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  11. data/lib/mongoid/association/proxy.rb +1 -1
  12. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -1
  13. data/lib/mongoid/association/referenced/belongs_to/eager.rb +38 -2
  14. data/lib/mongoid/association/referenced/eager.rb +29 -9
  15. data/lib/mongoid/association/referenced/has_one/proxy.rb +6 -1
  16. data/lib/mongoid/atomic.rb +13 -3
  17. data/lib/mongoid/clients/factory.rb +2 -2
  18. data/lib/mongoid/clients/options.rb +8 -8
  19. data/lib/mongoid/clients/sessions.rb +20 -4
  20. data/lib/mongoid/clients/storage_options.rb +5 -5
  21. data/lib/mongoid/config.rb +39 -9
  22. data/lib/mongoid/criteria.rb +23 -4
  23. data/lib/mongoid/criteria/modifiable.rb +2 -1
  24. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  25. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +6 -6
  26. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  27. data/lib/mongoid/criteria/queryable/mergeable.rb +75 -8
  28. data/lib/mongoid/criteria/queryable/pipeline.rb +3 -2
  29. data/lib/mongoid/criteria/queryable/selectable.rb +120 -13
  30. data/lib/mongoid/criteria/queryable/storable.rb +104 -99
  31. data/lib/mongoid/errors/eager_load.rb +2 -0
  32. data/lib/mongoid/errors/no_client_config.rb +2 -2
  33. data/lib/mongoid/errors/no_default_client.rb +1 -1
  34. data/lib/mongoid/extensions/hash.rb +4 -2
  35. data/lib/mongoid/extensions/regexp.rb +1 -1
  36. data/lib/mongoid/fields.rb +2 -1
  37. data/lib/mongoid/fields/validators/macro.rb +4 -1
  38. data/lib/mongoid/matchable/regexp.rb +2 -2
  39. data/lib/mongoid/persistable/pushable.rb +11 -2
  40. data/lib/mongoid/persistence_context.rb +6 -6
  41. data/lib/mongoid/query_cache.rb +61 -18
  42. data/lib/mongoid/serializable.rb +9 -3
  43. data/lib/mongoid/tasks/database.rb +38 -3
  44. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  45. data/lib/mongoid/version.rb +1 -1
  46. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +32 -23
  47. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  48. data/spec/app/models/coding.rb +4 -0
  49. data/spec/app/models/coding/pull_request.rb +12 -0
  50. data/spec/app/models/delegating_patient.rb +16 -0
  51. data/spec/app/models/passport.rb +1 -0
  52. data/spec/app/models/person.rb +2 -0
  53. data/spec/app/models/phone.rb +1 -0
  54. data/spec/app/models/publication.rb +5 -0
  55. data/spec/app/models/publication/encyclopedia.rb +12 -0
  56. data/spec/app/models/publication/review.rb +14 -0
  57. data/spec/app/models/series.rb +1 -0
  58. data/spec/app/models/wiki_page.rb +1 -0
  59. data/spec/integration/app_spec.rb +254 -0
  60. data/spec/integration/associations/embedded_spec.rb +54 -0
  61. data/spec/integration/associations/embeds_many_spec.rb +24 -0
  62. data/spec/integration/associations/embeds_one_spec.rb +24 -0
  63. data/spec/integration/associations/has_many_spec.rb +76 -0
  64. data/spec/integration/associations/has_one_spec.rb +76 -0
  65. data/spec/integration/bson_regexp_raw_spec.rb +20 -0
  66. data/spec/integration/criteria/date_field_spec.rb +41 -0
  67. data/spec/integration/criteria/logical_spec.rb +13 -0
  68. data/spec/integration/document_spec.rb +22 -0
  69. data/spec/integration/shardable_spec.rb +20 -4
  70. data/spec/lite_spec_helper.rb +12 -4
  71. data/spec/mongoid/association/accessors_spec.rb +238 -63
  72. data/spec/mongoid/association/embedded/embeds_many_models.rb +19 -0
  73. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  74. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  75. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +193 -10
  76. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
  77. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  78. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  79. data/spec/mongoid/clients/factory_spec.rb +8 -8
  80. data/spec/mongoid/clients/options_spec.rb +11 -11
  81. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  82. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  83. data/spec/mongoid/clients_spec.rb +2 -2
  84. data/spec/mongoid/contextual/atomic_spec.rb +22 -11
  85. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  86. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  87. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  88. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +1 -1
  89. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  90. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  91. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  92. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  93. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +45 -12
  94. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1051 -392
  95. data/spec/mongoid/criteria/queryable/selectable_spec.rb +52 -0
  96. data/spec/mongoid/criteria/queryable/storable_spec.rb +80 -2
  97. data/spec/mongoid/criteria_spec.rb +36 -2
  98. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  99. data/spec/mongoid/errors/no_client_config_spec.rb +2 -2
  100. data/spec/mongoid/errors/no_client_database_spec.rb +3 -3
  101. data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -3
  102. data/spec/mongoid/fields_spec.rb +24 -1
  103. data/spec/mongoid/indexable_spec.rb +6 -4
  104. data/spec/mongoid/matchable/default_spec.rb +1 -1
  105. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  106. data/spec/mongoid/matchable_spec.rb +2 -2
  107. data/spec/mongoid/persistable/pushable_spec.rb +55 -1
  108. data/spec/mongoid/query_cache_spec.rb +77 -9
  109. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  110. data/spec/mongoid/scopable_spec.rb +2 -1
  111. data/spec/mongoid/serializable_spec.rb +129 -18
  112. data/spec/mongoid/shardable_models.rb +1 -1
  113. data/spec/mongoid/shardable_spec.rb +2 -2
  114. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  115. data/spec/mongoid/tasks/database_spec.rb +1 -1
  116. data/spec/shared/LICENSE +20 -0
  117. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  118. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  119. data/spec/shared/lib/mrss/constraints.rb +312 -0
  120. data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
  121. data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
  122. data/spec/spec_helper.rb +2 -31
  123. data/spec/support/child_process_helper.rb +76 -0
  124. data/spec/support/cluster_config.rb +3 -3
  125. data/spec/support/constraints.rb +26 -10
  126. data/spec/support/expectations.rb +3 -1
  127. data/spec/support/helpers.rb +11 -0
  128. data/spec/support/session_registry.rb +50 -0
  129. data/spec/support/spec_config.rb +12 -4
  130. metadata +520 -473
  131. metadata.gz.sig +0 -0
@@ -18,6 +18,25 @@ class EmmLegislator
18
18
  field :b, type: Integer, default: 0
19
19
  end
20
20
 
21
+ # Models with associations with :class_name as a :: prefixed string
22
+
23
+ class EmmCcCongress
24
+ include Mongoid::Document
25
+
26
+ embeds_many :legislators, class_name: '::EmmCcLegislator'
27
+
28
+ field :name, type: String
29
+ end
30
+
31
+ class EmmCcLegislator
32
+ include Mongoid::Document
33
+
34
+ embedded_in :congress, class_name: '::EmmCcCongress'
35
+
36
+ field :a, type: Integer, default: 0
37
+ field :b, type: Integer, default: 0
38
+ end
39
+
21
40
  class EmmManufactory
22
41
  include Mongoid::Document
23
42
 
@@ -649,6 +649,16 @@ describe Mongoid::Association::Embedded::EmbedsMany do
649
649
  it 'returns the class name option' do
650
650
  expect(association.klass).to eq(_class)
651
651
  end
652
+
653
+ context 'when the class name is prefixed with ::' do
654
+ let(:options) do
655
+ { class_name: '::OtherEmbeddedObject' }
656
+ end
657
+
658
+ it 'returns the class name option' do
659
+ expect(association.klass).to eq(_class)
660
+ end
661
+ end
652
662
  end
653
663
 
654
664
  context 'when the class_name option is not specified' do
@@ -456,8 +456,6 @@ describe Mongoid::Association::Embedded::EmbedsOne do
456
456
  end
457
457
 
458
458
  it 'returns the inverse in an array' do
459
- pending 'MONGOID-4751'
460
-
461
459
  inverses = association.inverses
462
460
  expect(inverses).to eq([:parent])
463
461
  end
@@ -114,13 +114,13 @@ describe Mongoid::Association::Referenced::BelongsTo::Eager do
114
114
  end
115
115
 
116
116
  it "does not query when touching the association" do
117
- expect_query(0) do
117
+ expect_no_queries do
118
118
  expect(eager.person).to eq(person)
119
119
  end
120
120
  end
121
121
 
122
122
  it "does not query when updating the association" do
123
- expect_query(0) do
123
+ expect_no_queries do
124
124
  eager.person.username = "arthurnn"
125
125
  end
126
126
  end
@@ -146,18 +146,201 @@ describe Mongoid::Association::Referenced::BelongsTo::Eager do
146
146
 
147
147
  context "when the association is polymorphic" do
148
148
 
149
- let!(:movie) do
150
- Movie.create(name: "Bladerunner")
149
+ context "without namespaces" do
150
+
151
+ let!(:stand_alone_rating) do
152
+ Rating.create(value: 7)
153
+ end
154
+
155
+ let!(:bar) do
156
+ Bar.create(name: "FooBar")
157
+ end
158
+
159
+ let(:bar_rating) do
160
+ bar.create_rating(value: 5)
161
+ end
162
+
163
+ let!(:movie) do
164
+ Movie.create(name: "Bladerunner")
165
+ end
166
+
167
+ let(:movie_rating) do
168
+ movie.ratings.create(value: 10)
169
+ end
170
+
171
+ let(:eager) do
172
+ Rating.includes(:ratable).entries
173
+ end
174
+
175
+ context "when the eager load has returned documents" do
176
+
177
+ before do
178
+ bar_rating
179
+ movie_rating
180
+ eager
181
+ end
182
+
183
+ it "puts the documents in the parent document" do
184
+ expect(eager.map { |e| e.ivar(:ratable) }).to eq([nil, bar, movie])
185
+ end
186
+
187
+ it "does not query when touching the association" do
188
+ expect_no_queries do
189
+ expect(eager.map(&:ratable)).to eq([nil, bar, movie])
190
+ end
191
+ end
192
+
193
+ it "does not query when updating the association" do
194
+ expect_no_queries do
195
+ eager.last.ratable.name = "Easy rider"
196
+ end
197
+ end
198
+ end
199
+
200
+ context "when the eager load has not returned documents" do
201
+
202
+ before { eager }
203
+
204
+ it "does not set anything on the parent" do
205
+ expect(eager.map { |e| e.ivar(:ratable) }).to all(be nil)
206
+ end
207
+
208
+ it "has a nil association" do
209
+ expect(eager.map(&:ratable)).to all(be nil)
210
+ end
211
+ end
212
+ end
213
+
214
+ context "with namespaces" do
215
+
216
+ let!(:stand_alone_review) do
217
+ Publication::Review.create(summary: "awful")
218
+ end
219
+
220
+ let!(:encyclopedia) do
221
+ Publication::Encyclopedia.create(title: "Encyclopedia Britannica")
222
+ end
223
+
224
+ let(:encyclopedia_review) do
225
+ encyclopedia.reviews.create(summary: "inspiring")
226
+ end
227
+
228
+ let!(:pull_request) do
229
+ Coding::PullRequest.create(title: "Add eager loading for polymorphic belongs_to associations")
230
+ end
231
+
232
+ let(:pull_request_review) do
233
+ pull_request.reviews.create(summary: "Looks good to me")
234
+ end
235
+
236
+ let(:eager) do
237
+ Publication::Review.includes(:reviewable).entries
238
+ end
239
+
240
+ context "when the eager load has returned documents" do
241
+
242
+ before do
243
+ encyclopedia_review
244
+ pull_request_review
245
+ eager
246
+ end
247
+
248
+ it "puts the documents in the parent document" do
249
+ expect(eager.map { |e| e.ivar(:reviewable) }).to eq([nil, encyclopedia, pull_request])
250
+ end
251
+
252
+ it "does not query when touching the association" do
253
+ expect_no_queries do
254
+ expect(eager.map(&:reviewable)).to eq([nil, encyclopedia, pull_request])
255
+ end
256
+ end
257
+
258
+ it "does not query when updating the association" do
259
+ expect_no_queries do
260
+ eager.last.reviewable.title = "Load stuff eagerly"
261
+ end
262
+ end
263
+ end
264
+
265
+ context "when the eager load has not returned documents" do
266
+
267
+ before { eager }
268
+
269
+ it "does not set anything on the parent" do
270
+ expect(eager.map { |e| e.ivar(:reviewable) }).to all(be nil)
271
+ end
272
+
273
+ it "has a nil association" do
274
+ expect(eager.map(&:reviewable)).to all(be nil)
275
+ end
276
+ end
151
277
  end
152
278
 
153
- let!(:rating) do
154
- movie.ratings.create(value: 10)
279
+ context 'when eager loading multiple associations' do
280
+ let(:reviewable) do
281
+ Publication::Encyclopedia.create!(title: "Encyclopedia Britannica")
282
+ end
283
+
284
+ let!(:reviewable_review) do
285
+ Publication::Review.create!(summary: "awful",
286
+ reviewable: reviewable)
287
+ end
288
+
289
+ let(:reviewer) do
290
+ Dog.create!
291
+ end
292
+
293
+ let!(:reviewer_review) do
294
+ Publication::Review.create(summary: "okay",
295
+ reviewer: reviewer)
296
+ end
297
+
298
+ let(:template) do
299
+ Template.create!
300
+ end
301
+
302
+ let!(:template_review) do
303
+ Publication::Review.create(summary: "Looks good to me",
304
+ template: template)
305
+ end
306
+
307
+ let(:eager) do
308
+ Publication::Review.includes(:reviewable, :reviewer, :template).entries
309
+ end
310
+
311
+ it 'loads all associations eagerly' do
312
+ loaded = expect_query(4) do
313
+ eager
314
+ end
315
+
316
+ expect_no_queries do
317
+ eager.map(&:reviewable).compact.should == [reviewable]
318
+ end
319
+
320
+ expect_no_queries do
321
+ eager.map(&:reviewer).compact.should == [reviewer]
322
+ end
323
+
324
+ expect_no_queries do
325
+ eager.map(&:template).compact.should == [template]
326
+ end
327
+ end
155
328
  end
156
329
 
157
- it "raises an error" do
158
- expect {
159
- Rating.includes(:ratable).last
160
- }.to raise_error(Mongoid::Errors::EagerLoad)
330
+ context 'when eager loading an association that has type but not value set' do
331
+
332
+ let!(:reviewer_review) do
333
+ Publication::Review.create(summary: "okay",
334
+ reviewer_type: 'Dog')
335
+ end
336
+
337
+ let(:eager) do
338
+ Publication::Review.includes(:reviewable, :reviewer, :template).entries
339
+ end
340
+
341
+ it 'does not error' do
342
+ eager.map(&:reviewer).should == [nil]
343
+ end
161
344
  end
162
345
  end
163
346
 
@@ -1757,6 +1757,43 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
1757
1757
  end
1758
1758
  end
1759
1759
 
1760
+ describe "#any?" do
1761
+
1762
+ let(:person) do
1763
+ Person.create
1764
+ end
1765
+
1766
+ context "when nothing exists on the relation" do
1767
+
1768
+ context "when no document is added" do
1769
+
1770
+ let!(:sandwich) do
1771
+ Sandwich.create!
1772
+ end
1773
+
1774
+ it "returns false" do
1775
+ expect(sandwich.meats.any?).to be false
1776
+ end
1777
+ end
1778
+
1779
+ context "when the document is destroyed" do
1780
+
1781
+ before do
1782
+ Meat.create!
1783
+ end
1784
+
1785
+ let!(:sandwich) do
1786
+ Sandwich.create!
1787
+ end
1788
+
1789
+ it "returns false" do
1790
+ sandwich.destroy
1791
+ expect(sandwich.meats.any?).to be false
1792
+ end
1793
+ end
1794
+ end
1795
+ end
1796
+
1760
1797
  context "when documents have been persisted" do
1761
1798
 
1762
1799
  let!(:preference) do
@@ -1846,6 +1883,107 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
1846
1883
  end
1847
1884
  end
1848
1885
 
1886
+ describe "#any?" do
1887
+
1888
+ let(:sandwich) do
1889
+ Sandwich.create
1890
+ end
1891
+
1892
+ context "when nothing exists on the relation" do
1893
+
1894
+ context "when no document is added" do
1895
+
1896
+ let!(:sandwich) do
1897
+ Sandwich.create!
1898
+ end
1899
+
1900
+ it "returns false" do
1901
+ expect(sandwich.meats.any?).to be false
1902
+ end
1903
+ end
1904
+
1905
+ context "when the document is destroyed" do
1906
+
1907
+ before do
1908
+ Meat.create!
1909
+ end
1910
+
1911
+ let!(:sandwich) do
1912
+ Sandwich.create!
1913
+ end
1914
+
1915
+ it "returns false" do
1916
+ sandwich.destroy
1917
+ expect(sandwich.meats.any?).to be false
1918
+ end
1919
+ end
1920
+ end
1921
+
1922
+ context "when appending to a relation and _loaded/_unloaded are empty" do
1923
+
1924
+ let!(:sandwich) do
1925
+ Sandwich.create!
1926
+ end
1927
+
1928
+ before do
1929
+ sandwich.meats << Meat.new
1930
+ end
1931
+
1932
+ it "returns true" do
1933
+ expect(sandwich.meats.any?).to be true
1934
+ end
1935
+ end
1936
+
1937
+ context "when appending to a relation in a transaction" do
1938
+ require_transaction_support
1939
+
1940
+ let!(:sandwich) do
1941
+ Sandwich.create!
1942
+ end
1943
+
1944
+ it "returns true" do
1945
+ sandwich.with_session do |session|
1946
+ session.with_transaction do
1947
+ expect{ sandwich.meats << Meat.new }.to_not raise_error
1948
+ expect(sandwich.meats.any?).to be true
1949
+ end
1950
+ end
1951
+ end
1952
+ end
1953
+
1954
+ context "when documents have been persisted" do
1955
+
1956
+ let!(:meat) do
1957
+ sandwich.meats.create
1958
+ end
1959
+
1960
+ it "returns true" do
1961
+ expect(sandwich.meats.any?).to be true
1962
+ end
1963
+ end
1964
+
1965
+ context "when documents have not been persisted" do
1966
+
1967
+ let!(:meat) do
1968
+ sandwich.meats.build
1969
+ end
1970
+
1971
+ it "returns false" do
1972
+ expect(sandwich.meats.any?).to be true
1973
+ end
1974
+ end
1975
+
1976
+ context "when new documents exist in the database" do
1977
+ before do
1978
+ Meat.create(sandwiches: [sandwich])
1979
+ end
1980
+
1981
+ it "returns true" do
1982
+ expect(sandwich.meats.any?).to be true
1983
+ end
1984
+ end
1985
+ end
1986
+
1849
1987
  [ :create, :create! ].each do |method|
1850
1988
 
1851
1989
  describe "##{method}" do
@@ -2689,7 +2827,8 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
2689
2827
  expect(preferences).to eq([ preference_one ])
2690
2828
  end
2691
2829
 
2692
- context 'when providing a collation', if: collation_supported? do
2830
+ context 'when providing a collation' do
2831
+ min_server_version '3.4'
2693
2832
 
2694
2833
  let(:preferences) do
2695
2834
  person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
@@ -256,6 +256,111 @@ describe Mongoid::Association::Referenced::HasMany::Targets::Enumerable do
256
256
  end
257
257
  end
258
258
  end
259
+
260
+ context "when the documents have been loaded" do
261
+ let(:criteria) do
262
+ Post.where(person_id: person.id)
263
+ end
264
+
265
+ let!(:enumerable) do
266
+ described_class.new(criteria)
267
+ end
268
+
269
+ before do
270
+ enumerable.load_all!
271
+ end
272
+
273
+ it "is _loaded" do
274
+ expect(enumerable._loaded?).to be true
275
+ end
276
+
277
+ context "when a block is given" do
278
+ it "returns true when the predicate is true" do
279
+ expect(
280
+ enumerable.any? { |doc| true }
281
+ ).to be true
282
+ end
283
+
284
+ it "returns false when the predicate is false" do
285
+ expect(
286
+ enumerable.any? { |doc| false }
287
+ ).to be false
288
+ end
289
+ end
290
+
291
+ context "when an argument is given" do
292
+ ruby_version_gte '2.5'
293
+
294
+ it "returns true when the argument is true" do
295
+ expect(enumerable.any?(Post)).to be true
296
+ end
297
+
298
+ it "returns false when the argument is false" do
299
+ expect(enumerable.any?(Sandwich)).to be false
300
+ end
301
+ end
302
+
303
+ context "when both an argument and a block are given" do
304
+ ruby_version_gte '2.5'
305
+
306
+ it "gives precedence to the pattern" do
307
+ expect(
308
+ enumerable.any?(Post) { |doc| false }
309
+ ).to be true
310
+ end
311
+ end
312
+ end
313
+
314
+ context "when the documents are not loaded" do
315
+
316
+ let(:criteria) do
317
+ Post.where(person_id: person.id)
318
+ end
319
+
320
+ let!(:enumerable) do
321
+ described_class.new(criteria)
322
+ end
323
+
324
+ it "is not _loaded" do
325
+ expect(enumerable._loaded?).to be false
326
+ end
327
+
328
+ context "when a block is given" do
329
+ it "returns true when the predicate is true" do
330
+ expect(
331
+ enumerable.any? { |doc| true }
332
+ ).to be true
333
+ end
334
+
335
+ it "returns false when the predicate is false" do
336
+ expect(
337
+ enumerable.any? { |doc| false }
338
+ ).to be false
339
+ end
340
+ end
341
+
342
+ context "when an argument is given" do
343
+ ruby_version_gte '2.5'
344
+
345
+ it "returns true when the argument is true" do
346
+ expect(enumerable.any?(Post)).to be true
347
+ end
348
+
349
+ it "returns false when the argument is false" do
350
+ expect(enumerable.any?(Sandwich)).to be false
351
+ end
352
+ end
353
+
354
+ context "when both an argument and a block are given" do
355
+ ruby_version_gte '2.5'
356
+
357
+ it "gives precedence to the pattern" do
358
+ expect(
359
+ enumerable.any?(Post) { |doc| false }
360
+ ).to be true
361
+ end
362
+ end
363
+ end
259
364
  end
260
365
 
261
366
  describe "#clear" do