add enum validation to IpBlock

This commit is contained in:
Daniel M Brasil 2024-02-20 16:51:29 -03:00
parent 90eb4a5d01
commit d13c20fabe
No known key found for this signature in database
GPG Key ID: AE1A28A226D1E692
2 changed files with 11 additions and 1 deletions

View File

@ -23,7 +23,7 @@ class IpBlock < ApplicationRecord
sign_up_requires_approval: 5000,
sign_up_block: 5500,
no_access: 9999,
}, prefix: true
}, prefix: true, validate: true
validates :ip, :severity, presence: true
validates :ip, uniqueness: true

View File

@ -166,6 +166,16 @@ RSpec.describe 'IP Blocks' do
expect(response).to have_http_status(422)
end
end
context 'when the given severity is invalid' do
let(:params) { { ip: '151.0.32.55', severity: 'invalid' } }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
end
describe 'PUT /api/v1/admin/ip_blocks/:id' do