debian-mirror-gitlab/spec/requests/abuse_reports_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2015-10-24 18:46:33 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe AbuseReportsController do
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-24 18:46:33 +05:30
before do
sign_in(reporter)
end
2017-09-10 17:25:29 +05:30
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
2022-01-26 12:08:38 +05:30
user.destroy!
2017-09-10 17:25:29 +05:30
2022-04-04 11:22:00 +05:30
get new_abuse_report_path(user_id: user_id)
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to root_path
2020-01-01 13:55:28 +05:30
expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.'))
2017-09-10 17:25:29 +05:30
end
end
context 'when the user has already been blocked' do
it 'redirects the reporter to the user\'s profile' do
user.block
2022-04-04 11:22:00 +05:30
get new_abuse_report_path(user_id: user.id)
2017-09-10 17:25:29 +05:30
expect(response).to redirect_to user
2020-01-01 13:55:28 +05:30
expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.'))
2017-09-10 17:25:29 +05:30
end
end
end
describe 'POST create' do
context 'with valid attributes' do
it 'saves the abuse report' do
expect do
2022-04-04 11:22:00 +05:30
post abuse_reports_path(abuse_report: attrs)
end.to change { AbuseReport.count }.by(1)
2015-10-24 18:46:33 +05:30
end
it 'calls notify' do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(AbuseReport) do |instance|
expect(instance).to receive(:notify)
end
2015-12-23 02:04:40 +05:30
2022-04-04 11:22:00 +05:30
post abuse_reports_path(abuse_report: attrs)
2015-12-23 02:04:40 +05:30
end
2021-09-30 23:02:18 +05:30
it 'redirects back to root' do
2022-04-04 11:22:00 +05:30
post abuse_reports_path(abuse_report: attrs)
2015-10-24 18:46:33 +05:30
2021-09-04 01:27:46 +05:30
expect(response).to redirect_to root_path
2015-10-24 18:46:33 +05:30
end
end
2015-10-24 18:46:33 +05:30
context 'with invalid attributes' do
2022-04-04 11:22:00 +05:30
it 'redirects back to root' do
attrs.delete(:user_id)
2022-04-04 11:22:00 +05:30
post abuse_reports_path(abuse_report: attrs)
2015-10-24 18:46:33 +05:30
2022-04-04 11:22:00 +05:30
expect(response).to redirect_to root_path
2015-10-24 18:46:33 +05:30
end
end
end
end