mongoid 8.0.9 → 8.0.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: 49662a14c4c7135e3403cab365f7e46928baf2efca9ede4e673269d39c5a7292
4
- data.tar.gz: a69c22af01dbba7be588e2b4a9a63a1f58323ddd3395771969652323b2d7ecaf
3
+ metadata.gz: 5d5d57d80bf503ada4f229db360fee76b689f1224292a05ce8b9e2e1f2768f17
4
+ data.tar.gz: 409bfdfa5c3f91cfc75429569148cbff7bc19716193ac2af3d101f91647b7ea8
5
5
  SHA512:
6
- metadata.gz: cdde64cee0c2f085b6f250aae4e0f31340a9b79d04177e69f9c287170d8bb2eaba435873d680f77181587624244c1ba5885eff2d3964f3ebbe5f0924a70b1347
7
- data.tar.gz: 2d065d480c992dc3a2e772b7c33a0b50805d981c4f150f06b93f0ad9c89fd6b9c138c64354f8353c1a9849d9ddef45eae382bfc3ca1e4bb6aead94e60c5e6324
6
+ metadata.gz: 2aa57a75a92f7a03d872f28a0be8cfdd800d2917a9893b2cb4101cedcc1196c02c2e9591e3de67580b00b06626ea16bdf8aa742cc5752a806581e88a186410de
7
+ data.tar.gz: 725b89395a8d8126c196bd3ed42f02dc44c9e019247364f4fcc2d5587cf742a2ba3e9c27cafface3ea13712e2f17ea0fab081a8177b52299ed36b74b35a49347
@@ -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.0.9"
4
+ VERSION = "8.0.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'
@@ -1757,43 +1757,6 @@ 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
-
1797
1760
  context "when documents have been persisted" do
1798
1761
 
1799
1762
  let!(:preference) do
@@ -3063,6 +3026,34 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
3063
3026
  end
3064
3027
  end
3065
3028
 
3029
+ # MONGOID-5844
3030
+ #
3031
+ # Specifically, this tests the case where the association is
3032
+ # initialized with a single element (so that Proxy#push does not take
3033
+ # the `concat` route), which causes `reset_unloaded` to be called, which
3034
+ # sets the `_unloaded` Criteria object to match only the specific element
3035
+ # that was given.
3036
+ #
3037
+ # The issue now is that when the events list is updated to be both events,
3038
+ # _unloaded matches one of them already, and the other has previously been
3039
+ # persisted so `new_record?` won't match it. We need to make sure the
3040
+ # `#size` logic properly accounts for this case.
3041
+ context 'when documents have been previously persisted' do
3042
+ let(:person1) { Person.create! }
3043
+ let(:person2) { Person.create! }
3044
+ let(:event1) { Event.create!(administrators: [ person1 ]) }
3045
+ let(:event2) { Event.create!(administrators: [ person2 ]) }
3046
+
3047
+ before do
3048
+ person1.administrated_events = [ event1, event2 ]
3049
+ end
3050
+
3051
+ it 'returns the number of associated documents [MONGOID-5844]' do
3052
+ expect(person1.administrated_events.to_a.size).to eq(2)
3053
+ expect(person1.administrated_events.size).to eq(2)
3054
+ end
3055
+ end
3056
+
3066
3057
  context "when documents have not been persisted" do
3067
3058
 
3068
3059
  before do
@@ -15,4 +15,5 @@ class Book
15
15
  end
16
16
 
17
17
  embeds_many :pages, cascade_callbacks: true
18
+ embeds_many :covers, cascade_callbacks: true
18
19
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Cover
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+
7
+ field :title, type: String
8
+
9
+ embedded_in :book
10
+ end
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.0.9
4
+ version: 8.0.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-29 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
@@ -899,6 +899,7 @@ files:
899
899
  - spec/support/models/cookie.rb
900
900
  - spec/support/models/country_code.rb
901
901
  - spec/support/models/courier_job.rb
902
+ - spec/support/models/cover.rb
902
903
  - spec/support/models/crate.rb
903
904
  - spec/support/models/customer.rb
904
905
  - spec/support/models/customer_address.rb
@@ -1126,7 +1127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1126
1127
  - !ruby/object:Gem::Version
1127
1128
  version: 1.3.6
1128
1129
  requirements: []
1129
- rubygems_version: 3.6.3
1130
+ rubygems_version: 3.6.5
1130
1131
  specification_version: 4
1131
1132
  summary: Elegant Persistence in Ruby for MongoDB.
1132
1133
  test_files:
@@ -1589,6 +1590,7 @@ test_files:
1589
1590
  - spec/support/models/cookie.rb
1590
1591
  - spec/support/models/country_code.rb
1591
1592
  - spec/support/models/courier_job.rb
1593
+ - spec/support/models/cover.rb
1592
1594
  - spec/support/models/crate.rb
1593
1595
  - spec/support/models/customer.rb
1594
1596
  - spec/support/models/customer_address.rb