Improve enforcement of collection item limit (#39969)
This commit is contained in:
1 parent
467c933459
commit
f8337b04fe
4 files changed
+35
-13
No files matched your search
@@ -51,20 +51,28 @@ RSpec.describe Collection do
|
||||
end
|
||||
|
||||
context 'when there are more items than allowed' do
|
||||
subject { Fabricate.build(:collection, collection_items:) }
|
||||
|
||||
let(:collection_items) { Fabricate.build_times(described_class::MAX_ITEMS + 1, :collection_item, collection: nil) }
|
||||
|
||||
it { is_expected.to_not be_valid }
|
||||
context 'when collection is local' do
|
||||
subject { Fabricate.build(:collection, collection_items:) }
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
context 'when collection is remote' do
|
||||
subject { Fabricate.build(:remote_collection, collection_items:) }
|
||||
|
||||
it { is_expected.to be_valid }
|
||||
end
|
||||
|
||||
@@ -81,6 +81,17 @@ RSpec.describe ActivityPub::ProcessFeaturedItemService do
|
||||
expect(new_item.position).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
context "when the collection's item count is already at the limit" do
|
||||
before do
|
||||
stub_const('ActivityPub::ProcessFeaturedCollectionService::ITEMS_LIMIT', 3)
|
||||
Fabricate.times(3, :collection_item, collection:)
|
||||
end
|
||||
|
||||
it 'does not create an item' do
|
||||
expect { subject.call(collection, object) }.to_not change(collection.collection_items, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when item exists' do
|
||||
|
||||
Reference in new issue
Block a user