mongoid 8.1.9 → 8.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3a2e1b9f4abdd261c6d18c42a1c107089ae415a57c9dcb0978c14891e78330b
4
- data.tar.gz: 9c09793f70f1dd4ad367e2abcac271245c86f8d6414f262e7643d09538b3bce4
3
+ metadata.gz: '0937a2d421f6fde901ea6cf6b84f44f3e0881203d907467bb4be6d29af0294be'
4
+ data.tar.gz: 603cbd46675272938b68ffa596d5cc49f0c2e60b1fe8d09f79100a67b1d06364
5
5
  SHA512:
6
- metadata.gz: b0b89ea745ddafadbe1d1cf17c467ee7413eaf94d341bbb209df4db0eeb7cdff6e1fd8b01bc2a85016c47bb830e93ccbcdb0317578c32ee8bbb3dc06eb7db54e
7
- data.tar.gz: 51627fd03388cbaeef60014b77e2a15202f06f2dffebd69d7ff0cdf5840885a5cdbacb2bc34794eb04c72595c675d5edb55e42b9aa4079dbb5de7d24f454eb8a
6
+ metadata.gz: 1a82445002bf56d4751a0b808a8aa5ff196ff92d057d6fa4230db17819b365df7e0c3fe9abd46ec063c7575e761cdef921d3682c3e37e7105b9e5bd04310e8fa
7
+ data.tar.gz: 443a3ce79311113369b4adf96302fc457ef6ae69643ab42845b0ee448f61c946820828137b3d6fbfb121386347cfd15ba129c7ded504f43c7ba3a980f7caf3aa
@@ -422,11 +422,28 @@ module Mongoid
422
422
  #
423
423
  # @return [ Integer ] The size of the enumerable.
424
424
  def size
425
- count = (_unloaded ? _unloaded.count : _loaded.count)
426
- if count.zero?
427
- count + _added.count
425
+ # If _unloaded is present, then it will match the set of documents
426
+ # that belong to this association, which have already been persisted
427
+ # to the database. This set of documents must be considered when
428
+ # computing the size of the association, along with anything that has
429
+ # since been added.
430
+ if _unloaded
431
+ if _added.any?
432
+ # Note that _added may include records that _unloaded already
433
+ # matches. This is the case if the association is assigned an array
434
+ # of items and some of them were already elements of the association.
435
+ #
436
+ # we need to thus make sure _unloaded.count excludes any elements
437
+ # that already exist in _added.
438
+
439
+ count = _unloaded.not(:_id.in => _added.values.map(&:id)).count
440
+ count + _added.values.count
441
+ else
442
+ _unloaded.count
443
+ end
444
+
428
445
  else
429
- count + _added.values.count { |d| d.new_record? }
446
+ _loaded.count + _added.count
430
447
  end
431
448
  end
432
449
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongoid
4
- VERSION = "8.1.9"
4
+ VERSION = "8.1.10"
5
5
  end
@@ -16,6 +16,10 @@ describe 'Mongoid application tests' do
16
16
  skip 'Set APP_TESTS=1 in environment to run application tests'
17
17
  end
18
18
 
19
+ if SpecConfig.instance.rails_version < '7.1'
20
+ skip 'App tests require Rails > 7.0 (see https://stackoverflow.com/questions/79360526)'
21
+ end
22
+
19
23
  require 'fileutils'
20
24
  require 'mrss/child_process_helper'
21
25
  require 'open-uri'
@@ -1755,43 +1755,6 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
1755
1755
  end
1756
1756
  end
1757
1757
 
1758
- describe "#any?" do
1759
-
1760
- let(:person) do
1761
- Person.create!
1762
- end
1763
-
1764
- context "when nothing exists on the relation" do
1765
-
1766
- context "when no document is added" do
1767
-
1768
- let!(:sandwich) do
1769
- Sandwich.create!
1770
- end
1771
-
1772
- it "returns false" do
1773
- expect(sandwich.meats.any?).to be false
1774
- end
1775
- end
1776
-
1777
- context "when the document is destroyed" do
1778
-
1779
- before do
1780
- Meat.create!
1781
- end
1782
-
1783
- let!(:sandwich) do
1784
- Sandwich.create!
1785
- end
1786
-
1787
- it "returns false" do
1788
- sandwich.destroy
1789
- expect(sandwich.meats.any?).to be false
1790
- end
1791
- end
1792
- end
1793
- end
1794
-
1795
1758
  context "when documents have been persisted" do
1796
1759
 
1797
1760
  let!(:preference) do
@@ -3041,6 +3004,34 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
3041
3004
  end
3042
3005
  end
3043
3006
 
3007
+ # MONGOID-5844
3008
+ #
3009
+ # Specifically, this tests the case where the association is
3010
+ # initialized with a single element (so that Proxy#push does not take
3011
+ # the `concat` route), which causes `reset_unloaded` to be called, which
3012
+ # sets the `_unloaded` Criteria object to match only the specific element
3013
+ # that was given.
3014
+ #
3015
+ # The issue now is that when the events list is updated to be both events,
3016
+ # _unloaded matches one of them already, and the other has previously been
3017
+ # persisted so `new_record?` won't match it. We need to make sure the
3018
+ # `#size` logic properly accounts for this case.
3019
+ context 'when documents have been previously persisted' do
3020
+ let(:person1) { Person.create! }
3021
+ let(:person2) { Person.create! }
3022
+ let(:event1) { Event.create!(administrators: [ person1 ]) }
3023
+ let(:event2) { Event.create!(administrators: [ person2 ]) }
3024
+
3025
+ before do
3026
+ person1.administrated_events = [ event1, event2 ]
3027
+ end
3028
+
3029
+ it 'returns the number of associated documents [MONGOID-5844]' do
3030
+ expect(person1.administrated_events.to_a.size).to eq(2)
3031
+ expect(person1.administrated_events.size).to eq(2)
3032
+ end
3033
+ end
3034
+
3044
3035
  context "when documents have not been persisted" do
3045
3036
 
3046
3037
  before do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.9
4
+ version: 8.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - The MongoDB Ruby Team
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-30 00:00:00.000000000 Z
10
+ date: 2025-02-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activemodel
@@ -1159,7 +1159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1159
1159
  - !ruby/object:Gem::Version
1160
1160
  version: 1.3.6
1161
1161
  requirements: []
1162
- rubygems_version: 3.6.3
1162
+ rubygems_version: 3.6.5
1163
1163
  specification_version: 4
1164
1164
  summary: Elegant Persistence in Ruby for MongoDB.
1165
1165
  test_files: