Fix item limit on collections (#38749)
This commit is contained in:
parent
d9149bfed9
commit
c0b1fbe0a9
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user