From 19ad51253d255c26ba71b0754c8b21197fcd0113 Mon Sep 17 00:00:00 2001
From: Matt Jankowski <matt@jankowski.online>
Date: Mon, 4 Dec 2023 04:02:40 -0500
Subject: [PATCH] Prevent triple-subject run in admin/domain_blocks spec
 (#28195)

---
 .../admin/domain_blocks_controller_spec.rb    | 40 ++++++++++---------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb
index 13826be36..22960f531 100644
--- a/spec/controllers/admin/domain_blocks_controller_spec.rb
+++ b/spec/controllers/admin/domain_blocks_controller_spec.rb
@@ -192,16 +192,11 @@ RSpec.describe Admin::DomainBlocksController do
       let(:original_severity) { 'suspend' }
       let(:new_severity)      { 'silence' }
 
-      it 'changes the block severity' do
-        expect { subject }.to change { domain_block.reload.severity }.from('suspend').to('silence')
-      end
-
-      it 'undoes individual suspensions' do
-        expect { subject }.to change { remote_account.reload.suspended? }.from(true).to(false)
-      end
-
-      it 'performs individual silences' do
-        expect { subject }.to change { remote_account.reload.silenced? }.from(false).to(true)
+      it 'changes the block severity, suspensions, and silences' do
+        expect { subject }
+          .to change_severity('suspend', 'silence')
+          .and change_suspended(true, false)
+          .and change_silenced(false, true)
       end
     end
 
@@ -209,17 +204,26 @@ RSpec.describe Admin::DomainBlocksController do
       let(:original_severity) { 'silence' }
       let(:new_severity)      { 'suspend' }
 
-      it 'changes the block severity' do
-        expect { subject }.to change { domain_block.reload.severity }.from('silence').to('suspend')
+      it 'changes the block severity, silences, and suspensions' do
+        expect { subject }
+          .to change_severity('silence', 'suspend')
+          .and change_silenced(true, false)
+          .and change_suspended(false, true)
       end
+    end
 
-      it 'undoes individual silences' do
-        expect { subject }.to change { remote_account.reload.silenced? }.from(true).to(false)
-      end
+    private
 
-      it 'performs individual suspends' do
-        expect { subject }.to change { remote_account.reload.suspended? }.from(false).to(true)
-      end
+    def change_severity(from, to)
+      change { domain_block.reload.severity }.from(from).to(to)
+    end
+
+    def change_silenced(from, to)
+      change { remote_account.reload.silenced? }.from(from).to(to)
+    end
+
+    def change_suspended(from, to)
+      change { remote_account.reload.suspended? }.from(from).to(to)
     end
   end