From 964e44a63e79057b4622445afd3aebb2b960b3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guitaut?= Date: Tue, 12 Nov 2024 17:34:41 +0100 Subject: [PATCH] =?UTF-8?q?DEV:=20Don=E2=80=99t=20replace=20Rails=20logger?= =?UTF-8?q?=20in=20specs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of replacing the Rails logger in specs, we can instead use `#broadcast_to` which has been introduced in Rails 7. --- spec/lib/random_assign_utils_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/lib/random_assign_utils_spec.rb b/spec/lib/random_assign_utils_spec.rb index 6c99d168..993d326b 100644 --- a/spec/lib/random_assign_utils_spec.rb +++ b/spec/lib/random_assign_utils_spec.rb @@ -7,15 +7,14 @@ FakeAutomation = Struct.new(:id) let!(:automation) { FakeAutomation.new(1) } + let(:fake_logger) { FakeLogger.new } - around do |example| - orig_logger = Rails.logger - Rails.logger = FakeLogger.new - example.run - Rails.logger = orig_logger + before do + SiteSetting.assign_enabled = true + Rails.logger.broadcast_to(fake_logger) end - before { SiteSetting.assign_enabled = true } + after { Rails.logger.stop_broadcasting_to(fake_logger) } describe ".automation_script!" do subject(:auto_assign) { described_class.automation_script!(ctx, fields, automation) }