From 49957cf55114d75dc2c1e62c71a98aad98866960 Mon Sep 17 00:00:00 2001 From: Horacio Bertorello Date: Tue, 27 Jun 2017 17:43:02 -0300 Subject: Fix errors caused by attempts to report already blocked or deleted users --- spec/controllers/abuse_reports_controller_spec.rb | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/abuse_reports_controller_spec.rb b/spec/controllers/abuse_reports_controller_spec.rb index 80a418feb3e..ada011e7595 100644 --- a/spec/controllers/abuse_reports_controller_spec.rb +++ b/spec/controllers/abuse_reports_controller_spec.rb @@ -13,6 +13,31 @@ describe AbuseReportsController 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, { 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, { 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 -- cgit v1.2.1