2016-10-09 15:48:43 +03:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe DomainBlock, type: :model do
|
2017-04-05 01:29:56 +03:00
|
|
|
describe 'validations' do
|
|
|
|
it 'has a valid fabricator' do
|
|
|
|
domain_block = Fabricate.build(:domain_block)
|
|
|
|
expect(domain_block).to be_valid
|
|
|
|
end
|
2016-11-16 00:56:03 +02:00
|
|
|
|
2017-04-05 01:29:56 +03:00
|
|
|
it 'is invalid without a domain' do
|
|
|
|
domain_block = Fabricate.build(:domain_block, domain: nil)
|
|
|
|
domain_block.valid?
|
|
|
|
expect(domain_block).to model_have_error_on_field(:domain)
|
|
|
|
end
|
|
|
|
|
2017-06-19 12:31:27 +03:00
|
|
|
it 'is invalid if the same normalized domain already exists' do
|
|
|
|
domain_block_1 = Fabricate(:domain_block, domain: 'にゃん')
|
|
|
|
domain_block_2 = Fabricate.build(:domain_block, domain: 'xn--r9j5b5b')
|
2017-04-05 01:29:56 +03:00
|
|
|
domain_block_2.valid?
|
|
|
|
expect(domain_block_2).to model_have_error_on_field(:domain)
|
|
|
|
end
|
|
|
|
end
|
2017-06-19 12:31:27 +03:00
|
|
|
|
|
|
|
describe 'blocked?' do
|
|
|
|
it 'returns true if the domain is suspended' do
|
|
|
|
Fabricate(:domain_block, domain: 'domain', severity: :suspend)
|
|
|
|
expect(DomainBlock.blocked?('domain')).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false even if the domain is silenced' do
|
|
|
|
Fabricate(:domain_block, domain: 'domain', severity: :silence)
|
|
|
|
expect(DomainBlock.blocked?('domain')).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the domain is not suspended nor silenced' do
|
|
|
|
expect(DomainBlock.blocked?('domain')).to eq false
|
|
|
|
end
|
|
|
|
end
|
2019-05-03 21:36:36 +03:00
|
|
|
|
|
|
|
describe 'stricter_than?' do
|
|
|
|
it 'returns true if the new block has suspend severity while the old has lower severity' do
|
|
|
|
suspend = DomainBlock.new(domain: 'domain', severity: :suspend)
|
|
|
|
silence = DomainBlock.new(domain: 'domain', severity: :silence)
|
|
|
|
noop = DomainBlock.new(domain: 'domain', severity: :noop)
|
|
|
|
expect(suspend.stricter_than?(silence)).to be true
|
|
|
|
expect(suspend.stricter_than?(noop)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the new block has lower severity than the old one' do
|
|
|
|
suspend = DomainBlock.new(domain: 'domain', severity: :suspend)
|
|
|
|
silence = DomainBlock.new(domain: 'domain', severity: :silence)
|
|
|
|
noop = DomainBlock.new(domain: 'domain', severity: :noop)
|
|
|
|
expect(silence.stricter_than?(suspend)).to be false
|
|
|
|
expect(noop.stricter_than?(suspend)).to be false
|
|
|
|
expect(noop.stricter_than?(silence)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the new block does is less strict regarding reports' do
|
|
|
|
older = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: true)
|
|
|
|
newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_reports: false)
|
|
|
|
expect(newer.stricter_than?(older)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the new block does is less strict regarding media' do
|
|
|
|
older = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: true)
|
|
|
|
newer = DomainBlock.new(domain: 'domain', severity: :silence, reject_media: false)
|
|
|
|
expect(newer.stricter_than?(older)).to be false
|
|
|
|
end
|
|
|
|
end
|
2016-10-09 15:48:43 +03:00
|
|
|
end
|