From 00e92b40386e9ced25e5a6cad58f80dc78aca636 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Oct 2023 09:37:22 -0400 Subject: [PATCH] Add coverage for `CLI::Statuses` command (#25321) --- spec/lib/mastodon/cli/statuses_spec.rb | 22 ++++++++++++++++++++++ spec/rails_helper.rb | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/spec/lib/mastodon/cli/statuses_spec.rb b/spec/lib/mastodon/cli/statuses_spec.rb index 2430a8841..38ebcd993 100644 --- a/spec/lib/mastodon/cli/statuses_spec.rb +++ b/spec/lib/mastodon/cli/statuses_spec.rb @@ -4,9 +4,31 @@ require 'rails_helper' require 'mastodon/cli/statuses' describe Mastodon::CLI::Statuses do + let(:cli) { described_class.new } + describe '.exit_on_failure?' do it 'returns true' do expect(described_class.exit_on_failure?).to be true end end + + describe '#remove', use_transactional_tests: false do + context 'with small batch size' do + let(:options) { { batch_size: 0 } } + + it 'exits with error message' do + expect { cli.invoke :remove, [], options }.to output( + a_string_including('Cannot run') + ).to_stdout.and raise_error(SystemExit) + end + end + + context 'with default batch size' do + it 'removes unreferenced statuses' do + expect { cli.invoke :remove }.to output( + a_string_including('Done after') + ).to_stdout + end + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 06e8418a0..0bbf8fc52 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -85,6 +85,12 @@ RSpec.configure do |config| config.include Redisable config.include SignedRequestHelpers, type: :request + config.around(:each, use_transactional_tests: false) do |example| + self.use_transactional_tests = false + example.run + self.use_transactional_tests = true + end + config.before :each, type: :cli do stub_stdout stub_reset_connection_pools