mongoid 8.1.3 → 8.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 561c6173b8a11bb858b0df7dc72cec9e96767e7780572ecbc1233c11de84fb6a
4
- data.tar.gz: 1bc15420d04291843d26e52d1d04f2689d3e28b25db115d5a5f2c765b872fd30
3
+ metadata.gz: '059cd4652349083d2098577aa1c6f1f90233ab91474ef0a3f97db4bef4843f9f'
4
+ data.tar.gz: ca14035b9902221fe082862ea061f83beb2abc41a9a3eeb10dd0f781a34e697e
5
5
  SHA512:
6
- metadata.gz: 112499f5ac9998aa952c851ac4e6d64014bf35fcfeeed0b29bdb5fac5519866657b8f7fe087a001033cee7adcf1f07a7eb4b4c68dcef2611cbf36a1aef22d31c
7
- data.tar.gz: 43f784a2d2d5782f464f064d35bd384a6711a2355f6a1cd3f9529372184928ecac9d2e74e4cf90092857733945a10c08452ede7e1a4cbba903d3617d5ccbf601
6
+ metadata.gz: 358e801040678c844022e9e41bcdd3a5d482cbafbe608b623340c834d4b72545df547afa83d861d64431703d198c4347f6d9bada41c2960d38b46fdc1a243855
7
+ data.tar.gz: 8a2981f0a6d4bb4b2c24b6a636079ad3e3cbd1586791104deca7c118d0a08f8753a9a2ce564b416293ce337154c965f26a9ce34f44f087dd0fa8c981d58684da
checksums.yaml.gz.sig CHANGED
Binary file
@@ -227,9 +227,24 @@ module Mongoid
227
227
  # @example Are there persisted documents?
228
228
  # person.posts.exists?
229
229
  #
230
- # @return [ true | false ] True is persisted documents exist, false if not.
231
- def exists?
232
- _target.any? { |doc| doc.persisted? }
230
+ # @param [ :none | nil | false | Hash | Object ] id_or_conditions
231
+ # When :none (the default), returns true if any persisted
232
+ # documents exist in the association. When nil or false, this
233
+ # will always return false. When a Hash is given, this queries
234
+ # the documents in the association for those that match the given
235
+ # conditions, and returns true if any match which have been
236
+ # persisted. Any other argument is interpreted as an id, and
237
+ # queries for the existence of persisted documents in the
238
+ # association with a matching _id.
239
+ #
240
+ # @return [ true | false ] True if persisted documents exist, false if not.
241
+ def exists?(id_or_conditions = :none)
242
+ case id_or_conditions
243
+ when :none then _target.any?(&:persisted?)
244
+ when nil, false then false
245
+ when Hash then where(id_or_conditions).any?(&:persisted?)
246
+ else where(_id: id_or_conditions).any?(&:persisted?)
247
+ end
233
248
  end
234
249
 
235
250
  # Finds a document in this association through several different
@@ -172,9 +172,18 @@ module Mongoid
172
172
  # @example Are there persisted documents?
173
173
  # person.posts.exists?
174
174
  #
175
+ # @param [ :none | nil | false | Hash | Object ] id_or_conditions
176
+ # When :none (the default), returns true if any persisted
177
+ # documents exist in the association. When nil or false, this
178
+ # will always return false. When a Hash is given, this queries
179
+ # the documents in the association for those that match the given
180
+ # conditions, and returns true if any match. Any other argument is
181
+ # interpreted as an id, and queries for the existence of documents
182
+ # in the association with a matching _id.
183
+ #
175
184
  # @return [ true | false ] True is persisted documents exist, false if not.
176
- def exists?
177
- criteria.exists?
185
+ def exists?(id_or_conditions = :none)
186
+ criteria.exists?(id_or_conditions)
178
187
  end
179
188
 
180
189
  # Find the matching document on the association, either based on id or
@@ -43,8 +43,6 @@ module Mongoid
43
43
  # @api private
44
44
  define_model_callbacks :persist_parent
45
45
 
46
- define_model_callbacks :commit, :rollback, only: :after
47
-
48
46
  attr_accessor :before_callback_halted
49
47
  end
50
48
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongoid
4
- VERSION = "8.1.3"
4
+ VERSION = "8.1.4"
5
5
  end
@@ -2310,9 +2310,37 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
2310
2310
  person.addresses.create!(street: "Bond St")
2311
2311
  end
2312
2312
 
2313
+ let(:address) { person.addresses.first }
2314
+
2313
2315
  it "returns true" do
2314
2316
  expect(person.addresses.exists?).to be true
2315
2317
  end
2318
+
2319
+ context 'when given specifying conditions' do
2320
+ context 'when the record exists in the association' do
2321
+ it 'returns true by condition' do
2322
+ expect(person.addresses.exists?(street: 'Bond St')).to be true
2323
+ end
2324
+
2325
+ it 'returns true by id' do
2326
+ expect(person.addresses.exists?(address._id)).to be true
2327
+ end
2328
+
2329
+ it 'returns false when given false' do
2330
+ expect(person.addresses.exists?(false)).to be false
2331
+ end
2332
+
2333
+ it 'returns false when given nil' do
2334
+ expect(person.addresses.exists?(nil)).to be false
2335
+ end
2336
+ end
2337
+
2338
+ context 'when the record does not exist in the association' do
2339
+ it 'returns false' do
2340
+ expect(person.addresses.exists?(street: 'Garfield Ave')).to be false
2341
+ end
2342
+ end
2343
+ end
2316
2344
  end
2317
2345
 
2318
2346
  context "when no documents exist in the database" do
@@ -2324,6 +2352,13 @@ describe Mongoid::Association::Embedded::EmbedsMany::Proxy do
2324
2352
  it "returns false" do
2325
2353
  expect(person.addresses.exists?).to be false
2326
2354
  end
2355
+
2356
+ context 'when given specifying conditions' do
2357
+ it 'returns false' do
2358
+ expect(person.addresses.exists?(street: 'Hyde Park Dr')).to be false
2359
+ expect(person.addresses.exists?(street: 'Garfield Ave')).to be false
2360
+ end
2361
+ end
2327
2362
  end
2328
2363
  end
2329
2364
 
@@ -2395,6 +2395,42 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2395
2395
  end
2396
2396
  end
2397
2397
  end
2398
+
2399
+ context 'when invoked with specifying conditions' do
2400
+ let(:other_person) { Person.create! }
2401
+ let(:post) { person.posts.first }
2402
+
2403
+ before do
2404
+ person.posts.create title: 'bumfuzzle'
2405
+ other_person.posts.create title: 'bumbershoot'
2406
+ end
2407
+
2408
+ context 'when the conditions match an associated record' do
2409
+ it 'detects its existence by condition' do
2410
+ expect(person.posts.exists?(title: 'bumfuzzle')).to be true
2411
+ expect(other_person.posts.exists?(title: 'bumbershoot')).to be true
2412
+ end
2413
+
2414
+ it 'detects its existence by id' do
2415
+ expect(person.posts.exists?(post._id)).to be true
2416
+ end
2417
+
2418
+ it 'returns false when given false' do
2419
+ expect(person.posts.exists?(false)).to be false
2420
+ end
2421
+
2422
+ it 'returns false when given nil' do
2423
+ expect(person.posts.exists?(nil)).to be false
2424
+ end
2425
+ end
2426
+
2427
+ context 'when the conditions match an unassociated record' do
2428
+ it 'does not detect its existence' do
2429
+ expect(person.posts.exists?(title: 'bumbershoot')).to be false
2430
+ expect(other_person.posts.exists?(title: 'bumfuzzle')).to be false
2431
+ end
2432
+ end
2433
+ end
2398
2434
  end
2399
2435
 
2400
2436
  context "when documents exist in application but not in database" do
@@ -2465,6 +2501,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2465
2501
  end
2466
2502
  end
2467
2503
  end
2504
+
2505
+ context 'when invoked with specifying conditions' do
2506
+ it 'returns false' do
2507
+ expect(person.posts.exists?(title: 'hullaballoo')).to be false
2508
+ end
2509
+ end
2468
2510
  end
2469
2511
  end
2470
2512
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.3
4
+ version: 8.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,7 +35,7 @@ cert_chain:
35
35
  wkeAWhd5b+5JS0zgDL4SvGB8/W2IY+y0zELkojBMgJPyrpAWHL/WSsSBMuhyI2Pv
36
36
  xxaBVLklnJJ/qCCOZ3lG2MyVc/Nb0Mmq8ygWNsfwHmKKYuuWcviit0D0Tek=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-10-23 00:00:00.000000000 Z
38
+ date: 2023-11-22 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: activemodel
@@ -1196,7 +1196,7 @@ metadata:
1196
1196
  documentation_uri: https://www.mongodb.com/docs/mongoid/
1197
1197
  homepage_uri: https://mongoid.org/
1198
1198
  source_code_uri: https://github.com/mongodb/mongoid
1199
- post_install_message:
1199
+ post_install_message:
1200
1200
  rdoc_options: []
1201
1201
  require_paths:
1202
1202
  - lib
@@ -1212,7 +1212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1212
1212
  version: 1.3.6
1213
1213
  requirements: []
1214
1214
  rubygems_version: 3.4.21
1215
- signing_key:
1215
+ signing_key:
1216
1216
  specification_version: 4
1217
1217
  summary: Elegant Persistence in Ruby for MongoDB.
1218
1218
  test_files:
metadata.gz.sig CHANGED
Binary file