Add some more tests and clean up domain block controller (#27469)
parent
e5b7ae9576
commit
d649bbf28f
|
@ -33,7 +33,7 @@ module Admin
|
||||||
|
|
||||||
# Disallow accidentally downgrading a domain block
|
# Disallow accidentally downgrading a domain block
|
||||||
if existing_domain_block.present? && !@domain_block.stricter_than?(existing_domain_block)
|
if existing_domain_block.present? && !@domain_block.stricter_than?(existing_domain_block)
|
||||||
@domain_block.save
|
@domain_block.validate
|
||||||
flash.now[:alert] = I18n.t('admin.domain_blocks.existing_domain_block_html', name: existing_domain_block.domain, unblock_url: admin_domain_block_path(existing_domain_block)).html_safe
|
flash.now[:alert] = I18n.t('admin.domain_blocks.existing_domain_block_html', name: existing_domain_block.domain, unblock_url: admin_domain_block_path(existing_domain_block)).html_safe
|
||||||
@domain_block.errors.delete(:domain)
|
@domain_block.errors.delete(:domain)
|
||||||
return render :new
|
return render :new
|
||||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe 'blocking domains through the moderation interface' do
|
describe 'blocking domains through the moderation interface' do
|
||||||
before do
|
before do
|
||||||
|
allow(DomainBlockWorker).to receive(:perform_async).and_return(true)
|
||||||
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ describe 'blocking domains through the moderation interface' do
|
||||||
click_button I18n.t('admin.domain_blocks.new.create')
|
click_button I18n.t('admin.domain_blocks.new.create')
|
||||||
|
|
||||||
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
|
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
|
||||||
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,13 +29,15 @@ describe 'blocking domains through the moderation interface' do
|
||||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||||
click_button I18n.t('admin.domain_blocks.new.create')
|
click_button I18n.t('admin.domain_blocks.new.create')
|
||||||
|
|
||||||
# It presents a confirmation screen
|
# It doesn't immediately block but presents a confirmation screen
|
||||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||||
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
||||||
|
|
||||||
# Confirming creates a block
|
# Confirming creates a block
|
||||||
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||||
|
|
||||||
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
|
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
|
||||||
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,13 +51,15 @@ describe 'blocking domains through the moderation interface' do
|
||||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||||
click_button I18n.t('admin.domain_blocks.new.create')
|
click_button I18n.t('admin.domain_blocks.new.create')
|
||||||
|
|
||||||
# It presents a confirmation screen
|
# It doesn't immediately block but presents a confirmation screen
|
||||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||||
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
||||||
|
|
||||||
# Confirming updates the block
|
# Confirming updates the block
|
||||||
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||||
|
|
||||||
expect(domain_block.reload.severity).to eq 'suspend'
|
expect(domain_block.reload.severity).to eq 'suspend'
|
||||||
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,13 +73,15 @@ describe 'blocking domains through the moderation interface' do
|
||||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||||
click_button I18n.t('admin.domain_blocks.new.create')
|
click_button I18n.t('admin.domain_blocks.new.create')
|
||||||
|
|
||||||
# It presents a confirmation screen
|
# It doesn't immediately block but presents a confirmation screen
|
||||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com'))
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'subdomain.example.com'))
|
||||||
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
||||||
|
|
||||||
# Confirming creates the block
|
# Confirming creates the block
|
||||||
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||||
|
|
||||||
expect(DomainBlock.where(domain: 'subdomain.example.com', severity: 'suspend')).to exist
|
expect(DomainBlock.where(domain: 'subdomain.example.com', severity: 'suspend')).to exist
|
||||||
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||||
|
|
||||||
# And leaves the previous block alone
|
# And leaves the previous block alone
|
||||||
expect(domain_block.reload.severity).to eq 'silence'
|
expect(domain_block.reload.severity).to eq 'silence'
|
||||||
|
@ -90,11 +98,13 @@ describe 'blocking domains through the moderation interface' do
|
||||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||||
click_button I18n.t('generic.save_changes')
|
click_button I18n.t('generic.save_changes')
|
||||||
|
|
||||||
# It presents a confirmation screen
|
# It doesn't immediately block but presents a confirmation screen
|
||||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||||
|
expect(DomainBlockWorker).to_not have_received(:perform_async)
|
||||||
|
|
||||||
# Confirming updates the block
|
# Confirming updates the block
|
||||||
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
click_button I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||||
|
expect(DomainBlockWorker).to have_received(:perform_async)
|
||||||
|
|
||||||
expect(domain_block.reload.severity).to eq 'suspend'
|
expect(domain_block.reload.severity).to eq 'suspend'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue