Merge commit 'e9385e93e9b4601c87d1f5d6b8ddfd815f7aedcb' into glitch-soc/merge-upstream
This commit is contained in:
@ -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) }
|
||||
|
||||
|
78
spec/features/admin/domain_blocks_spec.rb
Normal file
78
spec/features/admin/domain_blocks_spec.rb
Normal file
@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'blocking domains through the moderation interface' do
|
||||
before do
|
||||
sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
|
||||
end
|
||||
|
||||
context 'when silencing a new domain' do
|
||||
it 'adds a new domain block' do
|
||||
visit new_admin_domain_block_path
|
||||
|
||||
fill_in 'domain_block_domain', with: 'example.com'
|
||||
select I18n.t('admin.domain_blocks.new.severity.silence'), from: 'domain_block_severity'
|
||||
click_on I18n.t('admin.domain_blocks.new.create')
|
||||
|
||||
expect(DomainBlock.exists?(domain: 'example.com', severity: 'silence')).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when suspending a new domain' do
|
||||
it 'presents a confirmation screen before suspending the domain' do
|
||||
visit new_admin_domain_block_path
|
||||
|
||||
fill_in 'domain_block_domain', with: 'example.com'
|
||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||
click_on I18n.t('admin.domain_blocks.new.create')
|
||||
|
||||
# It presents a confirmation screen
|
||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||
|
||||
# Confirming creates a block
|
||||
click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||
|
||||
expect(DomainBlock.exists?(domain: 'example.com', severity: 'suspend')).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when suspending a domain that is already silenced' do
|
||||
it 'presents a confirmation screen before suspending the domain' do
|
||||
domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
||||
|
||||
visit new_admin_domain_block_path
|
||||
|
||||
fill_in 'domain_block_domain', with: 'example.com'
|
||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||
click_on I18n.t('admin.domain_blocks.new.create')
|
||||
|
||||
# It presents a confirmation screen
|
||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||
|
||||
# Confirming updates the block
|
||||
click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||
|
||||
expect(domain_block.reload.severity).to eq 'silence'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when editing a domain block' do
|
||||
it 'presents a confirmation screen before suspending the domain' do
|
||||
domain_block = Fabricate(:domain_block, domain: 'example.com', severity: 'silence')
|
||||
|
||||
visit edit_admin_domain_block_path(domain_block)
|
||||
|
||||
select I18n.t('admin.domain_blocks.new.severity.suspend'), from: 'domain_block_severity'
|
||||
click_on I18n.t('generic.save_changes')
|
||||
|
||||
# It presents a confirmation screen
|
||||
expect(page).to have_title(I18n.t('admin.domain_blocks.confirm_suspension.title', domain: 'example.com'))
|
||||
|
||||
# Confirming updates the block
|
||||
click_on I18n.t('admin.domain_blocks.confirm_suspension.confirm')
|
||||
|
||||
expect(domain_block.reload.severity).to eq 'silence'
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceAccountsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
before do
|
||||
Fabricate(:account, domain: domain, created_at: 1.year.ago)
|
||||
Fabricate(:account, domain: domain, created_at: 1.month.ago)
|
||||
Fabricate(:account, domain: domain)
|
||||
|
||||
Fabricate(:account, domain: "foo.#{domain}", created_at: 1.year.ago)
|
||||
Fabricate(:account, domain: "foo.#{domain}")
|
||||
Fabricate(:account, domain: "bar.#{domain}")
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 3
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 6
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceFollowersMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
before do
|
||||
local_account = Fabricate(:account)
|
||||
|
||||
Fabricate(:account, domain: domain).follow!(local_account)
|
||||
Fabricate(:account, domain: domain).follow!(local_account)
|
||||
Fabricate(:account, domain: domain)
|
||||
|
||||
Fabricate(:account, domain: "foo.#{domain}").follow!(local_account)
|
||||
Fabricate(:account, domain: "foo.#{domain}").follow!(local_account)
|
||||
Fabricate(:account, domain: "bar.#{domain}")
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 4
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceFollowsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
before do
|
||||
local_account = Fabricate(:account)
|
||||
|
||||
local_account.follow!(Fabricate(:account, domain: domain))
|
||||
local_account.follow!(Fabricate(:account, domain: domain))
|
||||
Fabricate(:account, domain: domain)
|
||||
|
||||
local_account.follow!(Fabricate(:account, domain: "foo.#{domain}"))
|
||||
local_account.follow!(Fabricate(:account, domain: "foo.#{domain}"))
|
||||
Fabricate(:account, domain: "bar.#{domain}")
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 4
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
let(:remote_account) { Fabricate(:account, domain: domain) }
|
||||
let(:remote_account_on_subdomain) { Fabricate(:account, domain: "foo.#{domain}") }
|
||||
|
||||
before do
|
||||
remote_account.media_attachments.create!(file: attachment_fixture('attachment.jpg'))
|
||||
remote_account_on_subdomain.media_attachments.create!(file: attachment_fixture('attachment.jpg'))
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expected_total = remote_account.media_attachments.sum(:file_file_size) + remote_account.media_attachments.sum(:thumbnail_file_size)
|
||||
expect(measure.total).to eq expected_total
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expected_total = [remote_account, remote_account_on_subdomain].sum do |account|
|
||||
account.media_attachments.sum(:file_file_size) + account.media_attachments.sum(:thumbnail_file_size)
|
||||
end
|
||||
|
||||
expect(measure.total).to eq expected_total
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceReportsMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
before do
|
||||
Fabricate(:report, target_account: Fabricate(:account, domain: domain))
|
||||
Fabricate(:report, target_account: Fabricate(:account, domain: domain))
|
||||
|
||||
Fabricate(:report, target_account: Fabricate(:account, domain: "foo.#{domain}"))
|
||||
Fabricate(:report, target_account: Fabricate(:account, domain: "foo.#{domain}"))
|
||||
Fabricate(:report, target_account: Fabricate(:account, domain: "bar.#{domain}"))
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 5
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::Metrics::Measure::InstanceStatusesMeasure do
|
||||
subject(:measure) { described_class.new(start_at, end_at, params) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
let(:start_at) { 2.days.ago }
|
||||
let(:end_at) { Time.now.utc }
|
||||
|
||||
let(:params) { ActionController::Parameters.new(domain: domain) }
|
||||
|
||||
before do
|
||||
Fabricate(:status, account: Fabricate(:account, domain: domain))
|
||||
Fabricate(:status, account: Fabricate(:account, domain: domain))
|
||||
|
||||
Fabricate(:status, account: Fabricate(:account, domain: "foo.#{domain}"))
|
||||
Fabricate(:status, account: Fabricate(:account, domain: "foo.#{domain}"))
|
||||
Fabricate(:status, account: Fabricate(:account, domain: "bar.#{domain}"))
|
||||
end
|
||||
|
||||
describe 'total' do
|
||||
context 'without include_subdomains' do
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 2
|
||||
end
|
||||
end
|
||||
|
||||
context 'with include_subdomains' do
|
||||
let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
|
||||
|
||||
it 'returns the expected number of accounts' do
|
||||
expect(measure.total).to eq 5
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user