2023-05-24 18:55:40 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
require 'mastodon/cli/cache'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe Mastodon::CLI::Cache do
|
2023-12-07 22:49:14 +09:00
|
|
|
subject { cli.invoke(action, arguments, options) }
|
|
|
|
|
2023-06-11 01:36:09 +09:00
|
|
|
let(:cli) { described_class.new }
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:arguments) { [] }
|
|
|
|
let(:options) { {} }
|
2023-06-11 01:36:09 +09:00
|
|
|
|
2023-12-01 21:00:34 +09:00
|
|
|
it_behaves_like 'CLI Command'
|
2023-06-11 01:36:09 +09:00
|
|
|
|
|
|
|
describe '#clear' do
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:action) { :clear }
|
|
|
|
|
2023-06-11 01:36:09 +09:00
|
|
|
before { allow(Rails.cache).to receive(:clear) }
|
|
|
|
|
|
|
|
it 'clears the Rails cache' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('OK')
|
2023-06-11 01:36:09 +09:00
|
|
|
expect(Rails.cache).to have_received(:clear)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#recount' do
|
2023-12-07 22:49:14 +09:00
|
|
|
let(:action) { :recount }
|
|
|
|
|
2023-06-11 01:36:09 +09:00
|
|
|
context 'with the `accounts` argument' do
|
|
|
|
let(:arguments) { ['accounts'] }
|
|
|
|
let(:account_stat) { Fabricate(:account_stat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
account_stat.update(statuses_count: 123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 're-calculates account records in the cache' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('OK')
|
2023-06-11 01:36:09 +09:00
|
|
|
|
|
|
|
expect(account_stat.reload.statuses_count).to be_zero
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with the `statuses` argument' do
|
|
|
|
let(:arguments) { ['statuses'] }
|
|
|
|
let(:status_stat) { Fabricate(:status_stat) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
status_stat.update(replies_count: 123)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 're-calculates account records in the cache' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
|
|
|
.to output_results('OK')
|
2023-06-11 01:36:09 +09:00
|
|
|
|
|
|
|
expect(status_stat.reload.replies_count).to be_zero
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unknown type' do
|
|
|
|
let(:arguments) { ['other-type'] }
|
|
|
|
|
|
|
|
it 'Exits with an error message' do
|
2023-12-07 22:49:14 +09:00
|
|
|
expect { subject }
|
2024-01-26 17:53:44 +09:00
|
|
|
.to raise_error(Thor::Error, /Unknown/)
|
2023-06-11 01:36:09 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 18:55:40 +09:00
|
|
|
end
|