Skip to content

Commit 3055041

Browse files
committed
fix action_mailer/error_handling_spec.rb
1 parent 8516eed commit 3055041

3 files changed

Lines changed: 17 additions & 45 deletions

File tree

lib/rails_structured_logging/action_mailer/error_handling.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ def log_and_reraise_error(ex)
6464
# Log when email delivery fails
6565
sig { params(error: StandardError, notify: T::Boolean, report: T::Boolean, reraise: T::Boolean).void }
6666
def log_email_delivery_error(error, notify: false, report: true, reraise: true)
67-
# Skip logging for AbortDeliveryError as it's an expected case
68-
# when emails are intentionally not sent
69-
return if defined?(ApplicationMailer) &&
70-
defined?(ApplicationMailer::AbortDeliveryError) &&
71-
error.is_a?(ApplicationMailer::AbortDeliveryError)
72-
7367
# Generate appropriate error message
7468
message = error_message_for(error, reraise)
7569

spec/rails_structured_logging/action_mailer/error_handling_spec.rb

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,6 @@ def message
3838
end
3939
end
4040

41-
# Define a custom error class for testing
42-
before(:all) do
43-
module Postmark
44-
class Error < StandardError; end
45-
46-
class InactiveRecipientError < Error
47-
attr_reader :recipients
48-
49-
def initialize(message, recipients = [])
50-
super(message)
51-
@recipients = recipients
52-
end
53-
end
54-
55-
class InvalidEmailRequestError < Error; end
56-
end
57-
58-
class ApplicationMailer
59-
class AbortDeliveryError < StandardError; end
60-
end
61-
end
62-
63-
after(:all) do
64-
# Clean up
65-
Object.send(:remove_const, :Postmark) if defined?(Postmark)
66-
Object.send(:remove_const, :ApplicationMailer) if defined?(ApplicationMailer)
67-
end
68-
6941
let(:mailer) { test_mailer_class.new.welcome_email }
7042
let(:standard_error) { StandardError.new("Standard error message") }
7143
let(:postmark_error) { Postmark::Error.new("Postmark error") }
@@ -133,17 +105,6 @@ class AbortDeliveryError < StandardError; end
133105
end
134106

135107
describe "#log_email_delivery_error" do
136-
context "with AbortDeliveryError" do
137-
let(:abort_error) { ApplicationMailer::AbortDeliveryError.new("Aborted") }
138-
139-
it "returns early without logging" do
140-
expect(RailsStructuredLogging::ActionMailer::Logger).not_to receive(:log_structured_error)
141-
expect(mailer).not_to receive(:handle_error_notifications)
142-
143-
mailer.send(:log_email_delivery_error, abort_error)
144-
end
145-
end
146-
147108
context "with standard error" do
148109
it "logs the error and handles notifications" do
149110
expect(mailer).to receive(:error_message_for).with(standard_error, true).and_call_original

spec/support/postmark_mocks.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# Mock Postmark error classes for testing
4+
module Postmark
5+
class Error < StandardError; end
6+
7+
class InactiveRecipientError < Error
8+
attr_reader :recipients
9+
10+
def initialize(message, recipients = [])
11+
super(message)
12+
@recipients = recipients
13+
end
14+
end
15+
16+
class InvalidEmailRequestError < Error; end
17+
end

0 commit comments

Comments
 (0)