2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-18 16:38:22 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Admin::StatusesController do
|
|
|
|
render_views
|
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2017-07-18 16:38:22 +02:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let!(:status) { Fabricate(:status, account: account) }
|
|
|
|
let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
|
2021-11-26 22:12:27 +01:00
|
|
|
let(:last_media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
|
2017-07-18 16:38:22 +02:00
|
|
|
let(:sensitive) { true }
|
|
|
|
|
|
|
|
before do
|
2023-10-31 09:22:19 +01:00
|
|
|
_last_media_attachment = Fabricate(:media_attachment, account: account, status: last_media_attached_status)
|
|
|
|
_last_status = Fabricate(:status, account: account)
|
|
|
|
_media_attachment = Fabricate(:media_attachment, account: account, status: media_attached_status)
|
|
|
|
|
2017-07-18 16:38:22 +02:00
|
|
|
sign_in user, scope: :user
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
2023-06-06 15:51:42 +02:00
|
|
|
context 'with a valid account' do
|
2022-01-17 09:41:33 +01:00
|
|
|
before do
|
|
|
|
get :index, params: { account_id: account.id }
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
|
2023-05-04 05:49:08 +02:00
|
|
|
context 'when filtering by media' do
|
2022-01-17 09:41:33 +01:00
|
|
|
before do
|
2024-06-25 09:46:53 +02:00
|
|
|
get :index, params: { account_id: account.id, media: true }
|
2022-01-17 09:41:33 +01:00
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-06 13:57:00 +02:00
|
|
|
describe 'GET #show' do
|
|
|
|
before do
|
2024-06-24 15:11:10 +02:00
|
|
|
status.media_attachments << Fabricate(:media_attachment, type: :image, account: status.account)
|
|
|
|
status.save!
|
|
|
|
status.snapshot!(at_time: status.created_at, rate_limit: false)
|
|
|
|
status.update!(text: 'Hello, this is an edited post')
|
|
|
|
status.snapshot!(rate_limit: false)
|
2023-06-06 13:57:00 +02:00
|
|
|
get :show, params: { account_id: account.id, id: status.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
describe 'POST #batch' do
|
2023-09-06 16:40:19 +02:00
|
|
|
subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }
|
2017-07-18 16:38:22 +02:00
|
|
|
|
|
|
|
let(:status_ids) { [media_attached_status.id] }
|
|
|
|
|
2023-09-06 16:40:19 +02:00
|
|
|
shared_examples 'when action is report' do
|
2022-01-17 09:41:33 +01:00
|
|
|
let(:action) { 'report' }
|
2017-07-18 16:38:22 +02:00
|
|
|
|
2024-01-26 17:30:30 +01:00
|
|
|
it 'creates a report and redirects to report page' do
|
2023-09-06 16:40:19 +02:00
|
|
|
subject
|
|
|
|
|
2024-01-26 17:30:30 +01:00
|
|
|
expect(Report.last)
|
|
|
|
.to have_attributes(
|
|
|
|
target_account_id: eq(account.id),
|
|
|
|
status_ids: eq(status_ids)
|
|
|
|
)
|
2023-09-06 16:40:19 +02:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
expect(response).to redirect_to(admin_report_path(Report.last.id))
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
end
|
2023-09-06 16:40:19 +02:00
|
|
|
|
|
|
|
it_behaves_like 'when action is report'
|
|
|
|
|
|
|
|
context 'when the moderator is blocked by the author' do
|
|
|
|
before do
|
|
|
|
account.block!(user.account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'when action is report'
|
|
|
|
end
|
2017-07-18 16:38:22 +02:00
|
|
|
end
|
|
|
|
end
|