From 4c1a7941ff5ad4a9829267fea3c24fa2ccbd9cc9 Mon Sep 17 00:00:00 2001 From: Shujat Khalid Date: Thu, 15 Aug 2024 15:25:55 +0100 Subject: [PATCH] linting fix --- app/mailers/application_mailer.rb | 33 +++++++++---------- spec/mailers/application_mailer_spec.rb | 43 +++++++++++++------------ 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 56881fd96..83e7530d5 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -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 diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index d38b120d3..a786e60c7 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -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: 'test@example.com', - subject: 'Some subject', - ) + def test_notify_error + notify_email(to: "test@example.com", 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