Fix ArgumentError in /api/v1/admin/accounts/:id/action (#25386)

This commit is contained in:
Daniel M Brasil 2023-06-14 10:21:36 -03:00 committed by GitHub
parent b9e8d2b352
commit d9c6f70cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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