Reinforce coverage for DomainBlock model (#32473)

This commit is contained in:
Matt Jankowski 2024-10-14 08:51:01 -04:00 committed by GitHub
parent 2404d6d1a1
commit d8eab3d81f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 7 deletions

View file

@ -40,7 +40,9 @@ class DomainBlock < ApplicationRecord
if suspend?
[:suspend]
else
[severity.to_sym, reject_media? ? :reject_media : nil, reject_reports? ? :reject_reports : nil].reject { |policy| policy == :noop || policy.nil? }
[severity.to_sym, reject_media? ? :reject_media : nil, reject_reports? ? :reject_reports : nil]
.reject { |policy| policy == :noop }
.compact
end
end

View file

@ -3,14 +3,13 @@
require 'rails_helper'
RSpec.describe DomainBlock do
describe 'validations' do
describe 'Validations' do
it { is_expected.to validate_presence_of(:domain) }
it 'is invalid if the same normalized domain already exists' do
_domain_block = Fabricate(:domain_block, domain: 'にゃん')
domain_block_with_normalized_value = Fabricate.build(:domain_block, domain: 'xn--r9j5b5b')
domain_block_with_normalized_value.valid?
expect(domain_block_with_normalized_value).to model_have_error_on_field(:domain)
context 'when a normalized domain exists' do
before { Fabricate(:domain_block, domain: 'にゃん') }
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
end
end
@ -105,4 +104,26 @@ RSpec.describe DomainBlock do
end
end
end
describe '#policies' do
subject { domain_block.policies }
context 'when severity is suspend' do
let(:domain_block) { Fabricate.build :domain_block, severity: :suspend }
it { is_expected.to eq(%i(suspend)) }
end
context 'when severity is noop' do
let(:domain_block) { Fabricate.build :domain_block, severity: :noop, reject_media: true }
it { is_expected.to eq(%i(reject_media)) }
end
context 'when severity is silence' do
let(:domain_block) { Fabricate.build :domain_block, severity: :silence, reject_reports: true }
it { is_expected.to eq(%i(silence reject_reports)) }
end
end
end