2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-08 11:13:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe AbuseReportsController do
|
2016-01-04 18:59:42 -05:00
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:attrs) do
|
|
|
|
attributes_for(:abuse_report) do |hash|
|
|
|
|
hash[:user_id] = user.id
|
|
|
|
end
|
|
|
|
end
|
2015-10-08 11:13:28 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(reporter)
|
|
|
|
end
|
|
|
|
|
2017-06-27 16:43:02 -04:00
|
|
|
describe 'GET new' do
|
|
|
|
context 'when the user has already been deleted' do
|
|
|
|
it 'redirects the reporter to root_path' do
|
|
|
|
user_id = user.id
|
2021-12-07 07:10:33 -05:00
|
|
|
user.destroy!
|
2017-06-27 16:43:02 -04:00
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
get new_abuse_report_path(user_id: user_id)
|
2017-06-27 16:43:02 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to root_path
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.'))
|
2017-06-27 16:43:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has already been blocked' do
|
|
|
|
it 'redirects the reporter to the user\'s profile' do
|
|
|
|
user.block
|
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
get new_abuse_report_path(user_id: user.id)
|
2017-06-27 16:43:02 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to user
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.'))
|
2017-06-27 16:43:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
describe 'POST create' do
|
|
|
|
context 'with valid attributes' do
|
|
|
|
it 'saves the abuse report' do
|
|
|
|
expect do
|
2022-01-20 13:14:18 -05:00
|
|
|
post abuse_reports_path(abuse_report: attrs)
|
2016-01-04 18:59:42 -05:00
|
|
|
end.to change { AbuseReport.count }.by(1)
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|
2015-10-08 11:13:28 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
it 'calls notify' do
|
2019-11-07 10:06:33 -05:00
|
|
|
expect_next_instance_of(AbuseReport) do |instance|
|
|
|
|
expect(instance).to receive(:notify)
|
|
|
|
end
|
2015-11-30 09:12:31 -05:00
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
post abuse_reports_path(abuse_report: attrs)
|
2015-11-30 09:12:31 -05:00
|
|
|
end
|
|
|
|
|
2021-07-12 05:09:40 -04:00
|
|
|
it 'redirects back to root' do
|
2022-01-20 13:14:18 -05:00
|
|
|
post abuse_reports_path(abuse_report: attrs)
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2021-06-12 11:09:53 -04:00
|
|
|
expect(response).to redirect_to root_path
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|
2016-01-04 18:59:42 -05:00
|
|
|
end
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
context 'with invalid attributes' do
|
2022-01-20 13:14:18 -05:00
|
|
|
it 'redirects back to root' do
|
2016-01-04 18:59:42 -05:00
|
|
|
attrs.delete(:user_id)
|
2022-01-20 13:14:18 -05:00
|
|
|
post abuse_reports_path(abuse_report: attrs)
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
expect(response).to redirect_to root_path
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|
2015-10-08 11:13:28 -04:00
|
|
|
end
|
|
|
|
end
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|