Skip to content

Commit a7320e6

Browse files
authored
Merge pull request rails#43646 from Shopify/fix-action-mailer-execution-context
Set the execution context from AC::Metal rather than AbstractController
2 parents 7e424a5 + e974c58 commit a7320e6

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

actionmailer/test/base_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class BaseTest < ActiveSupport::TestCase
7070
assert_equal("Welcome", email.body.encoded)
7171
end
7272

73+
test "mail() doesn't set the mailer as a controller in the execution context" do
74+
ActiveSupport::ExecutionContext.clear
75+
assert_nil ActiveSupport::ExecutionContext.to_h[:controller]
76+
BaseMailer.welcome(from: "[email protected]", to: "[email protected]").to
77+
assert_nil ActiveSupport::ExecutionContext.to_h[:controller]
78+
end
79+
7380
test "can pass in :body to the mail method hash" do
7481
email = BaseMailer.welcome(body: "Hello there")
7582
assert_equal("text/plain", email.mime_type)

actionpack/lib/abstract_controller/base.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ def process(action, *args)
148148

149149
@_response_body = nil
150150

151-
ActiveSupport::ExecutionContext[:controller] = self
152151
process_action(action_name, *args)
153152
end
154153

actionpack/lib/action_controller/metal/instrumentation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def redirect_to(*)
4848

4949
private
5050
def process_action(*)
51+
ActiveSupport::ExecutionContext[:controller] = self
52+
5153
raw_payload = {
5254
controller: self.class.name,
5355
action: action_name,

0 commit comments

Comments
 (0)