Skip to content

Commit

Permalink
linting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
syed87 committed Aug 15, 2024
1 parent ddc005c commit 4c1a794
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
33 changes: 16 additions & 17 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ class ApplicationMailer < Mail::Notify::Mailer
"95adafaf-0920-4623-bddc-340853c047af",
)

rescue_from Notifications::Client::RequestError do
# WARNING: this needs to be a block, otherwise the exception will not be
# re-raised and we will not be notified via Sentry, and the job will not retry.
#
# @see https://github.com/rails/rails/issues/39018
if respond_to?(:headers)
recipient_email = headers['To'].value
MailDeliveryFailure.create!(
recipient_email: recipient_email
)
end

raise
rescue_from Notifications::Client::RequestError do
# WARNING: this needs to be a block, otherwise the exception will not be
# re-raised and we will not be notified via Sentry, and the job will not retry.
#
# @see https://github.com/rails/rails/issues/39018
if respond_to?(:headers)
recipient_email = headers["To"].value
MailDeliveryFailure.create!(recipient_email:)
end

def notify_email(headers)
headers = headers.merge(rails_mailer: mailer_name, rails_mail_template: action_name)
view_mail(GOVUK_NOTIFY_TEMPLATE_ID, headers)
end
raise
end

def notify_email(headers)
headers =
headers.merge(rails_mailer: mailer_name, rails_mail_template: action_name)
view_mail(GOVUK_NOTIFY_TEMPLATE_ID, headers)
end
end
43 changes: 23 additions & 20 deletions spec/mailers/application_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
require 'rails_helper'
# frozen_string_literal: true

require "rails_helper"

RSpec.describe ApplicationMailer, :sidekiq do
describe '.rescue_from' do
fake_mailer = Class.new(ApplicationMailer) do
self.delivery_method = :notify
self.notify_settings = {
api_key: 'not-real-e1f4c969-b675-4a0d-a14d-623e7c2d3fd8-24fea27b-824e-4259-b5ce-1badafe98150',
}
describe ".rescue_from" do
fake_mailer =
Class.new(ApplicationMailer) do
self.delivery_method = :notify
self.notify_settings = {
api_key:
"not-real-e1f4c969-b675-4a0d-a14d-623e7c2d3fd8-24fea27b-824e-4259-b5ce-1badafe98150",
}

def test_notify_error
notify_email(
to: '[email protected]',
subject: 'Some subject',
)
def test_notify_error
notify_email(to: "[email protected]", subject: "Some subject")
end
end
end

it 'marks errors as failed and re-raises the error' do
stub_request(:post, 'https://api.notifications.service.gov.uk/v2/notifications/email')
.to_return(status: 404)
it "marks errors as failed and re-raises the error" do
stub_request(
:post,
"https://api.notifications.service.gov.uk/v2/notifications/email",
).to_return(status: 404)

expect {
fake_mailer.test_notify_error.deliver_now
}.to raise_error(Notifications::Client::NotFoundError)
expect { fake_mailer.test_notify_error.deliver_now }.to raise_error(
Notifications::Client::NotFoundError,
)

expect(Email.last.delivery_status).to eql('notify_error')
expect(Email.last.delivery_status).to eql("notify_error")
end
end
end

0 comments on commit 4c1a794

Please sign in to comment.