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

pull/62/head
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 alias include_statuses? include_statuses
validates :type, :target_account, :current_account, presence: true validates :type, :target_account, :current_account, presence: true
validates :type, inclusion: { in: TYPES }
def initialize(attributes = {}) def initialize(attributes = {})
@send_email_notification = true @send_email_notification = true
@ -71,6 +72,10 @@ class Admin::AccountAction
TYPES - %w(none disable) TYPES - %w(none disable)
end end
end end
def i18n_scope
:activerecord
end
end end
private private

View File

@ -55,6 +55,22 @@ RSpec.describe Admin::AccountAction do
end end
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 it 'creates Admin::ActionLog' do
expect do expect do
subject subject