Add spec coverage for CLI::Media#remove_orphans command (#28267)

This commit is contained in:
Matt Jankowski 2024-01-03 09:12:56 -05:00 committed by GitHub
parent 51d2b80ff7
commit 5c769de096
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 0 deletions

View file

@ -4,6 +4,7 @@ require_relative '../../../config/boot'
require_relative '../../../config/environment' require_relative '../../../config/environment'
require 'thor' require 'thor'
require 'pastel'
require_relative 'progress_helper' require_relative 'progress_helper'
module Mastodon module Mastodon

View file

@ -184,4 +184,58 @@ describe Mastodon::CLI::Media do
end end
end end
end end
describe '#remove_orphans' do
let(:action) { :remove_orphans }
before do
FileUtils.mkdir_p Rails.public_path.join('system')
end
context 'without any options' do
it 'runs without error' do
expect { subject }
.to output_results('Removed', 'orphans (approx')
end
end
context 'when in azure mode' do
before do
allow(Paperclip::Attachment).to receive(:default_options).and_return(storage: :azure)
end
it 'warns about usage and exits' do
expect { subject }
.to output_results('azure storage driver is not supported')
.and raise_error(SystemExit)
end
end
context 'when in fog mode' do
before do
allow(Paperclip::Attachment).to receive(:default_options).and_return(storage: :fog)
end
it 'warns about usage and exits' do
expect { subject }
.to output_results('fog storage driver is not supported')
.and raise_error(SystemExit)
end
end
context 'when in filesystem mode' do
before do
allow(File).to receive(:delete).and_return(true)
media_attachment.delete
end
let(:media_attachment) { Fabricate(:media_attachment) }
it 'removes the unlinked files' do
expect { subject }
.to output_results('Removed', 'orphans (approx')
expect(File).to have_received(:delete).with(media_attachment.file.path)
end
end
end
end end