1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
This commit is contained in:
Wolfgang Fournès 2024-07-31 14:05:05 +00:00 committed by GitHub
commit 0e104d04cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View file

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

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
class FixInvalidDomainBlockSeverities < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
safety_assured do
execute <<~SQL.squish
UPDATE domain_blocks
SET severity = CASE WHEN severity > 2 THEN 2 WHEN severity < 0 THEN 0 END
WHERE severity > 2 OR severity < 0 RETURNING id;
SQL
end
end
def down; end
end

View file

@ -205,6 +205,17 @@ RSpec.describe 'Domain Blocks' do
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
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(body_as_json[: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