Commit df3cecdc authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'request-spec-abuse-reports-controller' into 'master'

Transition abuse_reports_controller spec to request spec

See merge request gitlab-org/gitlab!76922
parents 5cb1b84e 50d9c79a
...@@ -20,8 +20,10 @@ class AbuseReportsController < ApplicationController ...@@ -20,8 +20,10 @@ class AbuseReportsController < ApplicationController
message = _("Thank you for your report. A GitLab administrator will look into it shortly.") message = _("Thank you for your report. A GitLab administrator will look into it shortly.")
redirect_to root_path, notice: message redirect_to root_path, notice: message
else elsif report_params[:user_id].present?
render :new render :new
else
redirect_to root_path, alert: _("Cannot create the abuse report. The reported user was invalid. Please try again or contact support.")
end end
end end
......
...@@ -6533,6 +6533,9 @@ msgstr "" ...@@ -6533,6 +6533,9 @@ msgstr ""
msgid "Cannot be merged automatically" msgid "Cannot be merged automatically"
msgstr "" msgstr ""
msgid "Cannot create the abuse report. The reported user was invalid. Please try again or contact support."
msgstr ""
msgid "Cannot create the abuse report. The user has been deleted." msgid "Cannot create the abuse report. The user has been deleted."
msgstr "" msgstr ""
......
...@@ -21,7 +21,7 @@ RSpec.describe AbuseReportsController do ...@@ -21,7 +21,7 @@ RSpec.describe AbuseReportsController do
user_id = user.id user_id = user.id
user.destroy! user.destroy!
get :new, params: { user_id: user_id } get new_abuse_report_path(user_id: user_id)
expect(response).to redirect_to root_path expect(response).to redirect_to root_path
expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.')) expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.'))
...@@ -32,7 +32,7 @@ RSpec.describe AbuseReportsController do ...@@ -32,7 +32,7 @@ RSpec.describe AbuseReportsController do
it 'redirects the reporter to the user\'s profile' do it 'redirects the reporter to the user\'s profile' do
user.block user.block
get :new, params: { user_id: user.id } get new_abuse_report_path(user_id: user.id)
expect(response).to redirect_to user expect(response).to redirect_to user
expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.')) expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.'))
...@@ -44,7 +44,7 @@ RSpec.describe AbuseReportsController do ...@@ -44,7 +44,7 @@ RSpec.describe AbuseReportsController do
context 'with valid attributes' do context 'with valid attributes' do
it 'saves the abuse report' do it 'saves the abuse report' do
expect do expect do
post :create, params: { abuse_report: attrs } post abuse_reports_path(abuse_report: attrs)
end.to change { AbuseReport.count }.by(1) end.to change { AbuseReport.count }.by(1)
end end
...@@ -53,22 +53,22 @@ RSpec.describe AbuseReportsController do ...@@ -53,22 +53,22 @@ RSpec.describe AbuseReportsController do
expect(instance).to receive(:notify) expect(instance).to receive(:notify)
end end
post :create, params: { abuse_report: attrs } post abuse_reports_path(abuse_report: attrs)
end end
it 'redirects back to root' do it 'redirects back to root' do
post :create, params: { abuse_report: attrs } post abuse_reports_path(abuse_report: attrs)
expect(response).to redirect_to root_path expect(response).to redirect_to root_path
end end
end end
context 'with invalid attributes' do context 'with invalid attributes' do
it 'renders new' do it 'redirects back to root' do
attrs.delete(:user_id) attrs.delete(:user_id)
post :create, params: { abuse_report: attrs } post abuse_reports_path(abuse_report: attrs)
expect(response).to render_template(:new) expect(response).to redirect_to root_path
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment