Skip to content

Commit 1315de2

Browse files
authored
Use default from address of parent when default_from_address option is nil (#198)
1 parent 3b12614 commit 1315de2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

app/mailers/passwordless/mailer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Passwordless
44
# The mailer responsible for sending Passwordless' mails.
55
class Mailer < Passwordless.config.parent_mailer.constantize
6-
default from: Passwordless.config.default_from_address
6+
default(from: Passwordless.config.default_from_address) if Passwordless.config.default_from_address
77

88
# Sends a token and a magic link
99
#

test/mailers/passwordless/mailer_test.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Passwordless::MailerTest < ActionMailer::TestCase
4949
# parent class for the mailer. This means `Passwordless::Mailer` needs
5050
# to be reloaded, otherwise it will still have the old parent class.
5151
reload_mailer!
52-
52+
5353
session = Passwordless::Session.create!(authenticatable: users(:alice), token: "hello")
5454
email = Passwordless::Mailer.sign_in(session, "hello")
5555

@@ -60,4 +60,14 @@ class Passwordless::MailerTest < ActionMailer::TestCase
6060
# after the `with_config` block.
6161
reload_mailer!
6262
end
63+
64+
test("uses default from address of parent when default_from_address is nil") do
65+
with_config({parent_mailer: "ApplicationMailer", default_from_address: nil}) do
66+
reload_mailer!
67+
68+
assert_equal ApplicationMailer.default.fetch(:from), Passwordless::Mailer.default.fetch(:from)
69+
end
70+
ensure
71+
reload_mailer!
72+
end
6373
end

0 commit comments

Comments
 (0)