diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb index 2853f6457a..8e7d7b6afc 100644 --- a/app/models/domain_block.rb +++ b/app/models/domain_block.rb @@ -21,7 +21,7 @@ class DomainBlock < ApplicationRecord include DomainNormalizable include DomainMaterializable - enum :severity, { silence: 0, suspend: 1, noop: 2 } + enum :severity, { silence: 0, suspend: 1, noop: 2 }, validate: true validates :domain, presence: true, uniqueness: true, domain: true diff --git a/spec/requests/api/v1/admin/domain_blocks_spec.rb b/spec/requests/api/v1/admin/domain_blocks_spec.rb index 029de72fd7..d0a94b5d0c 100644 --- a/spec/requests/api/v1/admin/domain_blocks_spec.rb +++ b/spec/requests/api/v1/admin/domain_blocks_spec.rb @@ -217,6 +217,17 @@ RSpec.describe 'Domain Blocks' do .to start_with('application/json') end end + + context 'when severity is invalid' do + let(:params) { { domain: 'bar.com', severity: :bar } } + + it 'returns http unprocessable entity' do + subject + + expect(response).to have_http_status(422) + expect(body_as_json[:error]).to eq('Validation failed: Severity is not included in the list') + end + end end describe 'PUT /api/v1/admin/domain_blocks/:id' do