2023-05-24 18:55:40 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/preview_cards'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe Mastodon::CLI::PreviewCards do
|
2023-12-07 22:49:14 +09:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-10-17 20:06:16 +09:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-10-17 20:06:16 +09:00
|
|
|
|
2023-12-01 21:00:34 +09:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-10-17 20:06:16 +09:00
|
|
|
|
|
|
|
describe '#remove' do
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:action) { :remove }
|
|
|
|
|
2023-10-17 20:06:16 +09:00
|
|
|
context 'with relevant preview cards' do
|
|
|
|
before do
|
|
|
|
Fabricate(:preview_card, updated_at: 10.years.ago, type: :link)
|
|
|
|
Fabricate(:preview_card, updated_at: 10.months.ago, type: :photo)
|
|
|
|
Fabricate(:preview_card, updated_at: 10.days.ago, type: :photo)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no arguments' do
|
|
|
|
it 'deletes thumbnails for local preview cards' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results(
|
|
|
|
'Removed 2 preview cards',
|
|
|
|
'approx. 119 KB'
|
|
|
|
)
|
2023-10-17 20:06:16 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the --link option' do
|
|
|
|
let(:options) { { link: true } }
|
|
|
|
|
|
|
|
it 'deletes thumbnails for local preview cards' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results(
|
|
|
|
'Removed 1 link-type preview cards',
|
|
|
|
'approx. 59.6 KB'
|
|
|
|
)
|
2023-10-17 20:06:16 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the --days option' do
|
|
|
|
let(:options) { { days: 365 } }
|
|
|
|
|
|
|
|
it 'deletes thumbnails for local preview cards' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results(
|
|
|
|
'Removed 1 preview cards',
|
|
|
|
'approx. 59.6 KB'
|
|
|
|
)
|
2023-10-17 20:06:16 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 18:55:40 +09:00
|
|
|
end
|