Add spec coverage for CLI::Media#remove_orphans
command (#28267)
This commit is contained in:
parent
51d2b80ff7
commit
5c769de096
@ -4,6 +4,7 @@ require_relative '../../../config/boot'
|
||||
require_relative '../../../config/environment'
|
||||
|
||||
require 'thor'
|
||||
require 'pastel'
|
||||
require_relative 'progress_helper'
|
||||
|
||||
module Mastodon
|
||||
|
@ -184,4 +184,58 @@ describe Mastodon::CLI::Media do
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user