Skip to content

Commit

Permalink
APPEALS-26715 more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AKeyframe committed Aug 2, 2023
1 parent 812571f commit 38823cb
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 76 deletions.
68 changes: 34 additions & 34 deletions config/initializers/deprecation_warning_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
83 changes: 41 additions & 42 deletions spec/initializers/deprecation_warning_subscriber_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 22 in spec/initializers/deprecation_warning_subscriber_spec.rb

View workflow job for this annotation

GitHub Actions / rake

DeprecationWarningSubscriber when a 'deprecation.rails' event is instrumented emits a warning to the application logs Failure/Error: allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service) NameError: uninitialized constant SlackService
expect(rails_logger).to have_received(:warn).with(payload[:message])
end

it "emits a warning to Sentry" do

Check failure on line 26 in spec/initializers/deprecation_warning_subscriber_spec.rb

View workflow job for this annotation

GitHub Actions / rake

DeprecationWarningSubscriber when a 'deprecation.rails' event is instrumented emits a warning to Sentry Failure/Error: allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service) NameError: uninitialized constant SlackService
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

Check failure on line 38 in spec/initializers/deprecation_warning_subscriber_spec.rb

View workflow job for this annotation

GitHub Actions / rake

DeprecationWarningSubscriber when a 'deprecation.rails' event is instrumented emits a warning to Slack channel Failure/Error: allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service) NameError: uninitialized constant SlackService
expect(slack_service).to have_received(:send_notification).with(
payload[:message],
"Deprecation Warning",
"#appeals-deprecation-alerts"
)
end
end
end
end

0 comments on commit 38823cb

Please sign in to comment.