From 4a994e5b50a2eacbabb8db848ff6defd5829ea14 Mon Sep 17 00:00:00 2001 From: Daniel M Brasil Date: Wed, 14 Jun 2023 10:21:36 -0300 Subject: [PATCH] Fix `ArgumentError` in `/api/v1/admin/accounts/:id/action` (#25386) --- app/models/admin/account_action.rb | 5 +++++ spec/models/admin/account_action_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index 1ce28f5c82..2b5560e2eb 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -26,6 +26,7 @@ class Admin::AccountAction alias include_statuses? include_statuses validates :type, :target_account, :current_account, presence: true + validates :type, inclusion: { in: TYPES } def initialize(attributes = {}) @send_email_notification = true @@ -71,6 +72,10 @@ class Admin::AccountAction TYPES - %w(none disable) end end + + def i18n_scope + :activerecord + end end private diff --git a/spec/models/admin/account_action_spec.rb b/spec/models/admin/account_action_spec.rb index df79d9f287..b47561dd48 100644 --- a/spec/models/admin/account_action_spec.rb +++ b/spec/models/admin/account_action_spec.rb @@ -55,6 +55,22 @@ RSpec.describe Admin::AccountAction do end end + context 'when type is invalid' do + let(:type) { 'whatever' } + + it 'raises an invalid record error' do + expect { subject }.to raise_error(ActiveRecord::RecordInvalid) + end + end + + context 'when type is not given' do + let(:type) { '' } + + it 'raises an invalid record error' do + expect { subject }.to raise_error(ActiveRecord::RecordInvalid) + end + end + it 'creates Admin::ActionLog' do expect do subject