From 38433ccd0bb9a47c9882e64d4644f7c5b47858b3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 22 Jun 2023 08:53:13 -0400 Subject: [PATCH] Reduce `Admin::Reports::Actions` spec db activity (#25465) --- .../admin/reports/actions_controller_spec.rb | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/spec/controllers/admin/reports/actions_controller_spec.rb b/spec/controllers/admin/reports/actions_controller_spec.rb index 701855f92..1f3951516 100644 --- a/spec/controllers/admin/reports/actions_controller_spec.rb +++ b/spec/controllers/admin/reports/actions_controller_spec.rb @@ -62,17 +62,10 @@ describe Admin::Reports::ActionsController do end shared_examples 'common behavior' do - it 'closes the report' do - expect { subject }.to change { report.reload.action_taken? }.from(false).to(true) - end + it 'closes the report and redirects' do + expect { subject }.to mark_report_action_taken.and create_target_account_strike - it 'creates a strike with the expected text' do - expect { subject }.to change { report.target_account.strikes.count }.by(1) expect(report.target_account.strikes.last.text).to eq text - end - - it 'redirects' do - subject expect(response).to redirect_to(admin_reports_path) end @@ -81,20 +74,21 @@ describe Admin::Reports::ActionsController do { report_id: report.id } end - it 'closes the report' do - expect { subject }.to change { report.reload.action_taken? }.from(false).to(true) - end + it 'closes the report and redirects' do + expect { subject }.to mark_report_action_taken.and create_target_account_strike - it 'creates a strike with the expected text' do - expect { subject }.to change { report.target_account.strikes.count }.by(1) expect(report.target_account.strikes.last.text).to eq '' - end - - it 'redirects' do - subject expect(response).to redirect_to(admin_reports_path) end end + + def mark_report_action_taken + change { report.reload.action_taken? }.from(false).to(true) + end + + def create_target_account_strike + change { report.target_account.strikes.count }.by(1) + end end shared_examples 'all action types' do