Avoid repeated factory creation in media_attachments_vacuum_spec (#31000)
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.1) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / Libvips tests (.ruby-version) (push) Has been cancelled
Ruby Testing / Libvips tests (3.1) (push) Has been cancelled
Ruby Testing / Libvips tests (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.1) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled

This commit is contained in:
Matt Jankowski 2024-07-12 10:09:16 -04:00 committed by GitHub
parent c953dca1de
commit 00cb4a0313
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,32 +17,21 @@ RSpec.describe Vacuum::MediaAttachmentsVacuum do
let!(:old_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) }
let!(:new_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) }
before do
subject.perform
end
before { subject.perform }
it 'deletes cache of remote media attachments past the retention period' do
expect(old_remote_media.reload.file).to be_blank
end
it 'does not touch local media attachments past the retention period' do
expect(old_local_media.reload.file).to_not be_blank
end
it 'does not delete cache of remote media attachments within the retention period' do
expect(new_remote_media.reload.file).to_not be_blank
end
it 'does not touch local media attachments within the retention period' do
expect(new_local_media.reload.file).to_not be_blank
end
it 'deletes unattached media attachments past TTL' do
expect { old_unattached_media.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
it 'does not delete unattached media attachments within TTL' do
expect(new_unattached_media.reload).to be_persisted
it 'handles attachments based on metadata details' do
expect(old_remote_media.reload.file) # Remote and past retention period
.to be_blank
expect(old_local_media.reload.file) # Local and past retention
.to_not be_blank
expect(new_remote_media.reload.file) # Remote and within retention
.to_not be_blank
expect(new_local_media.reload.file) # Local and within retention
.to_not be_blank
expect { old_unattached_media.reload } # Unattached and past TTL
.to raise_error(ActiveRecord::RecordNotFound)
expect(new_unattached_media.reload) # Unattached and within TTL
.to be_persisted
end
end
end