From c0b1fbe0a9914ce0e37580c56304b8c963b665cd Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Mon, 20 Apr 2026 12:17:12 +0200 Subject: [PATCH] Fix item limit on collections (#38749) --- app/models/collection.rb | 6 +++++- spec/models/collection_spec.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/collection.rb b/app/models/collection.rb index 8d372eb8f4..39680721d2 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -98,7 +98,11 @@ class Collection < ApplicationRecord errors.add(:tag_name, :unusable) unless tag.usable? end + def pending_or_accepted_items + collection_items.select { |i| i.accepted? || i.pending? } + end + def items_do_not_exceed_limit - errors.add(:collection_items, :too_many, count: MAX_ITEMS) if collection_items.size > MAX_ITEMS + errors.add(:collection_items, :too_many, count: MAX_ITEMS) if pending_or_accepted_items.size > MAX_ITEMS end end diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index 619359a19d..df3a5eca41 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -58,6 +58,18 @@ RSpec.describe Collection do let(:collection_items) { Fabricate.build_times(described_class::MAX_ITEMS + 1, :collection_item, collection: nil) } it { is_expected.to_not be_valid } + + context 'when the limit is only exceeded due to `rejected` and `revoked` items' do + let(:collection_items) do + items = Fabricate.build_times(described_class::MAX_ITEMS - 2, :collection_item, collection: nil, state: :accepted) + items << Fabricate.build(:collection_item, collection: nil, state: :pending) + items << Fabricate.build(:collection_item, collection: nil, state: :rejected) + items << Fabricate.build(:collection_item, collection: nil, state: :revoked) + items + end + + it { is_expected.to be_valid } + end end end