2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-09-27 03:08:19 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Vacuum::MediaAttachmentsVacuum do
|
2023-02-20 05:24:14 +01:00
|
|
|
subject { described_class.new(retention_period) }
|
|
|
|
|
2022-09-27 03:08:19 +02:00
|
|
|
let(:retention_period) { 7.days }
|
|
|
|
let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
|
|
|
|
let(:local_status) { Fabricate(:status) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
|
|
|
let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) }
|
|
|
|
let!(:new_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status) }
|
|
|
|
let!(:new_local_media) { Fabricate(:media_attachment, status: local_status) }
|
|
|
|
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) }
|
|
|
|
|
2024-07-12 16:09:16 +02:00
|
|
|
before { subject.perform }
|
|
|
|
|
|
|
|
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
|
2022-09-27 03:08:19 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|