0
0
Fork 0

Add a confirmation screen when suspending a domain (#25144)

This commit is contained in:
Claire 2023-06-01 09:37:38 +02:00 committed by GitHub
parent b922ad7a1b
commit e9385e93e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 681 additions and 53 deletions

View file

@ -40,42 +40,135 @@ RSpec.describe Admin::DomainBlocksController do
end
describe 'POST #create' do
it 'blocks the domain when succeeded to save' do
before do
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
expect(DomainBlockWorker).to have_received(:perform_async)
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end
it 'renders new when failed to save' do
Fabricate(:domain_block, domain: 'example.com', severity: 'suspend')
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
context 'with "silence" severity and no conflict' do
before do
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
end
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
it 'records a block' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
end
expect(DomainBlockWorker).to_not have_received(:perform_async)
expect(response).to render_template :new
it 'calls DomainBlockWorker' do
expect(DomainBlockWorker).to have_received(:perform_async)
end
it 'redirects with a success message' do
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end
end
it 'allows upgrading a block' do
Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
context 'when the new domain block conflicts with an existing one' do
before do
Fabricate(:domain_block, domain: 'example.com', severity: 'suspend')
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
end
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence', reject_media: true, reject_reports: true } }
it 'does not record a block' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be false
end
expect(DomainBlockWorker).to have_received(:perform_async)
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
it 'does not call DomainBlockWorker' do
expect(DomainBlockWorker).to_not have_received(:perform_async)
end
it 'renders new' do
expect(response).to render_template :new
end
end
context 'with "suspend" severity and no conflict' do
context 'without a confirmation' do
before do
post :create, params: { domain_block: { domain: 'example.com', severity: 'suspend', reject_media: true, reject_reports: true } }
end
it 'does not record a block' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be false
end
it 'does not call DomainBlockWorker' do
expect(DomainBlockWorker).to_not have_received(:perform_async)
end
it 'renders confirm_suspension' do
expect(response).to render_template :confirm_suspension
end
end
context 'with a confirmation' do
before do
post :create, params: { :domain_block => { domain: 'example.com', severity: 'suspend', reject_media: true, reject_reports: true }, 'confirm' => '' }
end
it 'records a block' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
end
it 'calls DomainBlockWorker' do
expect(DomainBlockWorker).to have_received(:perform_async)
end
it 'redirects with a success message' do
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end
end
end
context 'when upgrading an existing block' do
before do
Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
end
context 'without a confirmation' do
before do
post :create, params: { domain_block: { domain: 'example.com', severity: 'suspend', reject_media: true, reject_reports: true } }
end
it 'does not record a block' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be false
end
it 'does not call DomainBlockWorker' do
expect(DomainBlockWorker).to_not have_received(:perform_async)
end
it 'renders confirm_suspension' do
expect(response).to render_template :confirm_suspension
end
end
context 'with a confirmation' do
before do
post :create, params: { :domain_block => { domain: 'example.com', severity: 'suspend', reject_media: true, reject_reports: true }, 'confirm' => '' }
end
it 'updates the record' do
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
end
it 'calls DomainBlockWorker' do
expect(DomainBlockWorker).to have_received(:perform_async)
end
it 'redirects with a success message' do
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end
end
end
end
describe 'PUT #update' do
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
let(:subject) do
post :update, params: { id: domain_block.id, domain_block: { domain: 'example.com', severity: new_severity } }
post :update, params: { :id => domain_block.id, :domain_block => { domain: 'example.com', severity: new_severity }, 'confirm' => '' }
end
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }