Add enum validation to DomainBlock#severity
(#29158)
This commit is contained in:
parent
f9451c5614
commit
77a44e61a8
2 changed files with 14 additions and 1 deletions
|
@ -21,7 +21,7 @@ class DomainBlock < ApplicationRecord
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
include DomainMaterializable
|
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
|
validates :domain, presence: true, uniqueness: true, domain: true
|
||||||
|
|
||||||
|
|
|
@ -217,6 +217,19 @@ RSpec.describe 'Domain Blocks' do
|
||||||
.to start_with('application/json')
|
.to start_with('application/json')
|
||||||
end
|
end
|
||||||
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(response.content_type)
|
||||||
|
.to start_with('application/json')
|
||||||
|
expect(response.parsed_body[:error]).to eq('Validation failed: Severity is not included in the list')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT /api/v1/admin/domain_blocks/:id' do
|
describe 'PUT /api/v1/admin/domain_blocks/:id' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue