From 38823cb64271a7553a6d04dc042b6610b2724a95 Mon Sep 17 00:00:00 2001 From: Alec Kagebein Date: Wed, 2 Aug 2023 14:58:12 -0500 Subject: [PATCH] APPEALS-26715 more formatting --- .../deprecation_warning_subscriber.rb | 68 +++++++-------- .../deprecation_warning_subscriber_spec.rb | 83 +++++++++---------- 2 files changed, 75 insertions(+), 76 deletions(-) diff --git a/config/initializers/deprecation_warning_subscriber.rb b/config/initializers/deprecation_warning_subscriber.rb index b7ea9a515..374150dd7 100644 --- a/config/initializers/deprecation_warning_subscriber.rb +++ b/config/initializers/deprecation_warning_subscriber.rb @@ -4,38 +4,38 @@ # Whenever a “deprecation.rails” notification is published, it will dispatch the event # (ActiveSupport::Notifications::Event) to method #deprecation. class DeprecationWarningSubscriber < ActiveSupport::Subscriber - SLACK_ALERT_TITLE = "Deprecation Warning" - SLACK_ALERT_CHANNEL = "#appeals-deprecation-alerts" + SLACK_ALERT_TITLE = "Deprecation Warning" + SLACK_ALERT_CHANNEL = "#appeals-deprecation-alerts" - attach_to :rails - - def deprecation(event) - emit_warning_to_application_logs(event) - emit_warning_to_sentry(event) - emit_warning_to_slack_alerts_channel(event) - end - - private - - def emit_warning_to_application_logs(event) - Rails.logger.warn(event.payload[:message]) - end - - def emit_warning_to_sentry(event) - Raven.capture_message( - event.payload[:message], - level: "warning", - extra: { - message: event.payload[:message], - callstack: event.payload[:callstack], - environment: Rails.env - } - ) - end - - def emit_warning_to_slack_alerts_channel(event) - SlackService - .new(url: ENV["SLACK_DISPATCH_ALERT_URL"]) - .send_notification(event.payload[:message], SLACK_ALERT_TITLE, SLACK_ALERT_CHANNEL) - end - end \ No newline at end of file + attach_to :rails + + def deprecation(event) + emit_warning_to_application_logs(event) + emit_warning_to_sentry(event) + emit_warning_to_slack_alerts_channel(event) + end + + private + + def emit_warning_to_application_logs(event) + Rails.logger.warn(event.payload[:message]) + end + + def emit_warning_to_sentry(event) + Raven.capture_message( + event.payload[:message], + level: "warning", + extra: { + message: event.payload[:message], + callstack: event.payload[:callstack], + environment: Rails.env + } + ) + end + + def emit_warning_to_slack_alerts_channel(event) + SlackService + .new(url: ENV["SLACK_DISPATCH_ALERT_URL"]) + .send_notification(event.payload[:message], SLACK_ALERT_TITLE, SLACK_ALERT_CHANNEL) + end +end \ No newline at end of file diff --git a/spec/initializers/deprecation_warning_subscriber_spec.rb b/spec/initializers/deprecation_warning_subscriber_spec.rb index 423182e96..b86a816d6 100644 --- a/spec/initializers/deprecation_warning_subscriber_spec.rb +++ b/spec/initializers/deprecation_warning_subscriber_spec.rb @@ -1,47 +1,46 @@ +# frozen_string_literal: true +describe "DeprecationWarningSubscriber" do + let(:rails_logger) { Rails.logger } + let(:slack_service) { SlackService.new(url: "dummy-url") } + before do + allow(Rails).to receive(:logger).and_return(rails_logger) + allow(rails_logger).to receive(:warn) -describe "DeprecationWarningSubscriber" do - let(:rails_logger) { Rails.logger } - let(:slack_service) { SlackService.new(url: "dummy-url") } - - before do - allow(Rails).to receive(:logger).and_return(rails_logger) - allow(rails_logger).to receive(:warn) - - allow(Raven).to receive(:capture_message) - - allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service) - allow(slack_service).to receive(:send_notification) + allow(Raven).to receive(:capture_message) + + allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service) + allow(slack_service).to receive(:send_notification) + end + + context "when a 'deprecation.rails' event is instrumented" do + let(:payload) { { message: "test message", callstack: "test callstack" } } + + before { ActiveSupport::Notifications.instrument("deprecation.rails", payload) } + + it "emits a warning to the application logs" do + expect(rails_logger).to have_received(:warn).with(payload[:message]) + end + + it "emits a warning to Sentry" do + expect(Raven).to have_received(:capture_message).with( + payload[:message], + level: "warning", + extra: { + message: payload[:message], + callstack: payload[:callstack], + environment: Rails.env + } + ) end - - context "when a 'deprecation.rails' event is instrumented" do - let(:payload) { { message: "test message", callstack: "test callstack" } } - - before { ActiveSupport::Notifications.instrument("deprecation.rails", payload) } - - it "emits a warning to the application logs" do - expect(rails_logger).to have_received(:warn).with(payload[:message]) - end - - it "emits a warning to Sentry" do - expect(Raven).to have_received(:capture_message).with( - payload[:message], - level: "warning", - extra: { - message: payload[:message], - callstack: payload[:callstack], - environment: Rails.env - } - ) - end - - it "emits a warning to Slack channel" do - expect(slack_service).to have_received(:send_notification).with( - payload[:message], - "Deprecation Warning", - "#appeals-deprecation-alerts" - ) - end + + it "emits a warning to Slack channel" do + expect(slack_service).to have_received(:send_notification).with( + payload[:message], + "Deprecation Warning", + "#appeals-deprecation-alerts" + ) end - end \ No newline at end of file + end +end \ No newline at end of file