Skip to content

Commit

Permalink
Able to save all elements of maildeliveryfailure
Browse files Browse the repository at this point in the history
  • Loading branch information
syed87 committed Sep 3, 2024
1 parent 55f0780 commit 0e8c245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class ApplicationMailer < Mail::Notify::Mailer
#
# @see https://github.com/rails/rails/issues/39018
if respond_to?(:headers)
recipient_email = headers["To"].value
MailDeliveryFailure.create!(recipient_email:)
email_address = headers["To"].value
mailer_action_method = action_name
mailer_class = mailer_name
MailDeliveryFailure.create!(email_address:, mailer_action_method:, mailer_class:)
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
6 changes: 5 additions & 1 deletion spec/mailers/application_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def test_notify_error
Notifications::Client::NotFoundError,
)

expect(Email.last.delivery_status).to eql("notify_error")
failure = MailDeliveryFailure.last
expect(failure).not_to be_nil
expect(failure.email_address).to eq("[email protected]")
expect(failure.mailer_action_method).to eq("test_notify_error")
expect(failure.mailer_class).to eq("anonymous")
end
end
end

0 comments on commit 0e8c245

Please sign in to comment.