diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 18:14:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 18:14:18 +0000 |
commit | 39cb2fdf01699eb5ac000c918f469c58dc75f7e8 (patch) | |
tree | 5de21a06dfe8b97c793f892032be45949aa482db /spec/requests/abuse_reports_controller_spec.rb | |
parent | c17eb7c97062d25cdf1b44573e4c0241f52aa2fe (diff) | |
download | gitlab-ce-39cb2fdf01699eb5ac000c918f469c58dc75f7e8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/abuse_reports_controller_spec.rb')
-rw-r--r-- | spec/requests/abuse_reports_controller_spec.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/spec/requests/abuse_reports_controller_spec.rb b/spec/requests/abuse_reports_controller_spec.rb new file mode 100644 index 00000000000..94c80ccb89a --- /dev/null +++ b/spec/requests/abuse_reports_controller_spec.rb @@ -0,0 +1,75 @@ +# 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 'redirects back to root' do + attrs.delete(:user_id) + post abuse_reports_path(abuse_report: attrs) + + expect(response).to redirect_to root_path + end + end + end +end |