diff --git a/app/controllers/admin/account_actions_controller.rb b/app/controllers/admin/account_actions_controller.rb index 91849811e36..3cfd1e17617 100644 --- a/app/controllers/admin/account_actions_controller.rb +++ b/app/controllers/admin/account_actions_controller.rb @@ -14,16 +14,20 @@ module Admin def create authorize @account, :show? - account_action = Admin::AccountAction.new(resource_params) - account_action.target_account = @account - account_action.current_account = current_account + @account_action = Admin::AccountAction.new(resource_params) + @account_action.target_account = @account + @account_action.current_account = current_account - account_action.save! - - if account_action.with_report? - redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: resource_params[:report_id]) + if @account_action.save + if @account_action.with_report? + redirect_to admin_reports_path, notice: I18n.t('admin.reports.processed_msg', id: resource_params[:report_id]) + else + redirect_to admin_account_path(@account.id) + end else - redirect_to admin_account_path(@account.id) + @warning_presets = AccountWarningPreset.all + + render :new end end diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index e43a50ae634..3cde3c7f8e4 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -32,8 +32,8 @@ class Admin::AccountAction validates :type, :target_account, :current_account, presence: true validates :type, inclusion: { in: TYPES } - def save! - raise ActiveRecord::RecordInvalid, self unless valid? + def save + return false unless valid? ApplicationRecord.transaction do process_action! @@ -43,6 +43,12 @@ class Admin::AccountAction process_notification! process_queue! + + true + end + + def save! + raise ActiveRecord::RecordInvalid, self unless save end def report diff --git a/spec/system/admin/account_actions_spec.rb b/spec/system/admin/account_actions_spec.rb index 787b988a0dc..abfd33dc272 100644 --- a/spec/system/admin/account_actions_spec.rb +++ b/spec/system/admin/account_actions_spec.rb @@ -15,6 +15,13 @@ RSpec.describe 'Admin Account Actions' do expect(page) .to have_title(I18n.t('admin.account_actions.title', acct: account.pretty_acct)) + # Invalid submission + expect { submit_form } + .to_not(change { account.strikes.count }) + expect(page) + .to have_content(/can't be blank/) + + # Valid submission choose(option: 'silence') expect { submit_form } .to change { account.strikes.count }.by(1)