mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 02:24:03 -05:00
Reinforce coverage for DomainBlock
model (#32473)
This commit is contained in:
parent
2404d6d1a1
commit
d8eab3d81f
@ -40,7 +40,9 @@ class DomainBlock < ApplicationRecord
|
|||||||
if suspend?
|
if suspend?
|
||||||
[:suspend]
|
[:suspend]
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,14 +3,13 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe DomainBlock do
|
RSpec.describe DomainBlock do
|
||||||
describe 'validations' do
|
describe 'Validations' do
|
||||||
it { is_expected.to validate_presence_of(:domain) }
|
it { is_expected.to validate_presence_of(:domain) }
|
||||||
|
|
||||||
it 'is invalid if the same normalized domain already exists' do
|
context 'when a normalized domain exists' do
|
||||||
_domain_block = Fabricate(:domain_block, domain: 'にゃん')
|
before { Fabricate(:domain_block, domain: 'にゃん') }
|
||||||
domain_block_with_normalized_value = Fabricate.build(:domain_block, domain: 'xn--r9j5b5b')
|
|
||||||
domain_block_with_normalized_value.valid?
|
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
|
||||||
expect(domain_block_with_normalized_value).to model_have_error_on_field(:domain)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -105,4 +104,26 @@ RSpec.describe DomainBlock do
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user