2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 21:27:03 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 07:12:25 +02:00
|
|
|
RSpec.describe Admin::ReportsController do
|
2017-04-28 01:21:38 +02:00
|
|
|
render_views
|
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2023-02-18 23:10:19 +01:00
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
before do
|
|
|
|
sign_in user, scope: :user
|
|
|
|
end
|
|
|
|
|
2017-04-10 21:27:03 +02:00
|
|
|
describe 'GET #index' do
|
2017-04-14 11:10:28 +02:00
|
|
|
it 'returns http success with no filters' do
|
2024-09-03 17:23:16 +02:00
|
|
|
specified = Fabricate(:report, action_taken_at: nil, comment: 'First report')
|
|
|
|
other = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'Second report')
|
2017-05-29 18:12:34 +02:00
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
get :index
|
|
|
|
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-03 17:23:16 +02:00
|
|
|
expect(response.body)
|
|
|
|
.to include(specified.comment)
|
|
|
|
.and not_include(other.comment)
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
|
2017-04-14 11:10:28 +02:00
|
|
|
it 'returns http success with resolved filter' do
|
2024-09-03 17:23:16 +02:00
|
|
|
specified = Fabricate(:report, action_taken_at: Time.now.utc, comment: 'First report')
|
|
|
|
other = Fabricate(:report, action_taken_at: nil, comment: 'Second report')
|
2017-05-29 18:12:34 +02:00
|
|
|
|
2022-01-17 09:41:33 +01:00
|
|
|
get :index, params: { resolved: '1' }
|
2017-04-14 11:10:28 +02:00
|
|
|
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-03 17:23:16 +02:00
|
|
|
expect(response.body)
|
|
|
|
.to include(specified.comment)
|
|
|
|
.and not_include(other.comment)
|
2017-04-14 11:10:28 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
2017-05-29 18:12:34 +02:00
|
|
|
it 'renders report' do
|
2024-09-03 17:23:16 +02:00
|
|
|
report = Fabricate(:report, comment: 'A big problem')
|
2017-04-14 11:10:28 +02:00
|
|
|
|
|
|
|
get :show, params: { id: report }
|
2017-05-29 18:12:34 +02:00
|
|
|
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-03 17:23:16 +02:00
|
|
|
expect(response.body)
|
|
|
|
.to include(report.comment)
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-14 11:10:28 +02:00
|
|
|
|
2020-03-21 03:08:09 +01:00
|
|
|
describe 'POST #resolve' do
|
|
|
|
it 'resolves the report' do
|
|
|
|
report = Fabricate(:report)
|
|
|
|
|
|
|
|
put :resolve, params: { id: report }
|
|
|
|
expect(response).to redirect_to(admin_reports_path)
|
|
|
|
report.reload
|
|
|
|
expect(report.action_taken_by_account).to eq user.account
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(report.action_taken?).to be true
|
2024-02-06 12:34:11 +01:00
|
|
|
expect(last_action_log.target).to eq(report)
|
2020-03-21 03:08:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
describe 'POST #reopen' do
|
|
|
|
it 'reopens the report' do
|
2024-07-18 09:49:44 +02:00
|
|
|
report = Fabricate(:report, action_taken_at: 3.days.ago)
|
2018-04-02 22:04:14 +02:00
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
put :reopen, params: { id: report }
|
|
|
|
expect(response).to redirect_to(admin_report_path(report))
|
|
|
|
report.reload
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(report.action_taken_by_account).to be_nil
|
|
|
|
expect(report.action_taken?).to be false
|
2024-02-06 12:34:11 +01:00
|
|
|
expect(last_action_log.target).to eq(report)
|
2018-04-02 22:04:14 +02:00
|
|
|
end
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
end
|
2018-04-02 22:04:14 +02:00
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
describe 'POST #assign_to_self' do
|
|
|
|
it 'reopens the report' do
|
|
|
|
report = Fabricate(:report)
|
2018-04-02 22:04:14 +02:00
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
put :assign_to_self, params: { id: report }
|
|
|
|
expect(response).to redirect_to(admin_report_path(report))
|
|
|
|
report.reload
|
|
|
|
expect(report.assigned_account).to eq user.account
|
2024-02-06 12:34:11 +01:00
|
|
|
expect(last_action_log.target).to eq(report)
|
2018-04-02 22:04:14 +02:00
|
|
|
end
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
end
|
2018-04-02 22:04:14 +02:00
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
describe 'POST #unassign' do
|
|
|
|
it 'reopens the report' do
|
2024-07-18 09:49:44 +02:00
|
|
|
report = Fabricate(:report, assigned_account_id: Account.last.id)
|
2018-04-02 22:04:14 +02:00
|
|
|
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 20:02:09 +01:00
|
|
|
put :unassign, params: { id: report }
|
|
|
|
expect(response).to redirect_to(admin_report_path(report))
|
|
|
|
report.reload
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(report.assigned_account).to be_nil
|
2024-02-06 12:34:11 +01:00
|
|
|
expect(last_action_log.target).to eq(report)
|
2018-04-02 22:04:14 +02:00
|
|
|
end
|
2017-04-14 11:10:28 +02:00
|
|
|
end
|
2024-02-06 12:34:11 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def last_action_log
|
|
|
|
Admin::ActionLog.last
|
|
|
|
end
|
2017-04-10 21:27:03 +02:00
|
|
|
end
|