Skip to content
Snippets Groups Projects
Commit 1a29ce03 authored by Lee Tickett's avatar Lee Tickett
Browse files

Transition abuse_reports_controller spec

Changelog: fixed
parent bba17e2d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -20,8 +20,10 @@ def create
 
message = _("Thank you for your report. A GitLab administrator will look into it shortly.")
redirect_to root_path, notice: message
else
elsif report_params[:user_id].present?
render :new
else
redirect_to root_path, alert: _("Cannot create the abuse report. The user has been deleted.")
end
end
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
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
before do
sign_in(reporter)
end
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
user.destroy!
get new_abuse_report_path(user_id: user_id)
expect(response).to redirect_to root_path
expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.'))
end
end
context 'when the user has already been blocked' do
it 'redirects the reporter to the user\'s profile' do
user.block
get new_abuse_report_path(user_id: user.id)
expect(response).to redirect_to user
expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.'))
end
end
end
describe 'POST create' do
context 'with valid attributes' do
it 'saves the abuse report' do
expect do
post abuse_reports_path(abuse_report: attrs)
end.to change { AbuseReport.count }.by(1)
end
it 'calls notify' do
expect_next_instance_of(AbuseReport) do |instance|
expect(instance).to receive(:notify)
end
post abuse_reports_path(abuse_report: attrs)
end
it 'redirects back to root' do
post abuse_reports_path(abuse_report: attrs)
expect(response).to redirect_to root_path
end
end
context 'with invalid attributes' do
it 'renders new' do
attrs.delete(:user_id)
post abuse_reports_path(abuse_report: attrs)
expect(response).to redirect_to root_path
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment