From c9210af3ee17c6997173354eebd1d9bcdd3e6a0d Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Thu, 4 May 2023 15:37:42 -0300 Subject: [PATCH] Add test coverage for `Mastodon::SettingsCLI` (#24856) --- spec/lib/mastodon/settings_cli_spec.rb | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 spec/lib/mastodon/settings_cli_spec.rb diff --git a/spec/lib/mastodon/settings_cli_spec.rb b/spec/lib/mastodon/settings_cli_spec.rb new file mode 100644 index 0000000000..713cb7e437 --- /dev/null +++ b/spec/lib/mastodon/settings_cli_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'rails_helper' +require 'mastodon/settings_cli' + +RSpec.describe Mastodon::SettingsCLI do + describe 'subcommand "registrations"' do + let(:cli) { Mastodon::RegistrationsCLI.new } + + before do + Setting.registrations_mode = nil + end + + describe '#open' do + it 'changes "registrations_mode" to "open"' do + expect { cli.open }.to change(Setting, :registrations_mode).from(nil).to('open') + end + + it 'displays success message' do + expect { cli.open }.to output( + a_string_including('OK') + ).to_stdout + end + end + + describe '#approved' do + it 'changes "registrations_mode" to "approved"' do + expect { cli.approved }.to change(Setting, :registrations_mode).from(nil).to('approved') + end + + it 'displays success message' do + expect { cli.approved }.to output( + a_string_including('OK') + ).to_stdout + end + + context 'with --require-reason' do + before do + cli.options = { require_reason: true } + end + + it 'changes "registrations_mode" to "approved"' do + expect { cli.approved }.to change(Setting, :registrations_mode).from(nil).to('approved') + end + + it 'sets "require_invite_text" to "true"' do + expect { cli.approved }.to change(Setting, :require_invite_text).from(false).to(true) + end + end + end + + describe '#close' do + it 'changes "registrations_mode" to "none"' do + expect { cli.close }.to change(Setting, :registrations_mode).from(nil).to('none') + end + + it 'displays success message' do + expect { cli.close }.to output( + a_string_including('OK') + ).to_stdout + end + end + end +end