1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Default values are not evaluated when overridden

This commit is contained in:
Alexandre Ruban 2021-01-18 19:59:39 +01:00
parent ed3612e6d4
commit bcd1333e3f
2 changed files with 9 additions and 1 deletions

View file

@ -901,7 +901,7 @@ module ActionMailer
end
def apply_defaults(headers)
default_values = self.class.default.transform_values do |value|
default_values = self.class.default.except(*headers.keys).transform_values do |value|
compute_default(value)
end

View file

@ -833,6 +833,14 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("Thanks for signing up this afternoon", mail.subject)
end
test "proc default values are not evaluated when overridden" do
with_default BaseMailer, from: -> { flunk }, to: -> { flunk } do
email = BaseMailer.welcome(from: "overridden-from@example.com", to: "overridden-to@example.com")
assert_equal ["overridden-from@example.com"], email.from
assert_equal ["overridden-to@example.com"], email.to
end
end
test "modifying the mail message with a before_action" do
class BeforeActionMailer < ActionMailer::Base
before_action :add_special_header!