Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/devise/mailers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def headers_for(action, opts)
# Give priority to the mailer's default if they exists.
headers.delete(:from) if default_params[:from]
headers.delete(:reply_to) if default_params[:reply_to]
headers.delete(:to) if default_params[:to]

headers.merge!(opts)

Expand Down
12 changes: 10 additions & 2 deletions test/mailers/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def confirmation_instructions(record, token, opts = {})
class TestMailerWithDefault < Devise::Mailer
default from: -> { computed_from }
default reply_to: ->(_) { computed_reply_to }
default to: -> { computed_to }

def confirmation_instructions(record, token, opts = {})
@token = token
Expand All @@ -37,10 +38,17 @@ def computed_from
def computed_reply_to
"reply_to@example.com"
end

def computed_to
"to@example.com"
end
end

mail = TestMailerWithDefault.confirmation_instructions(create_user, "confirmation-token")
assert mail.from, "from@example.com"
assert mail.reply_to, "reply_to@example.com"
Comment on lines -43 to -44
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.ruby-lang.org/en/2.1.0/Test/Unit/Assertions.html

These assertions will ALWAYS pass

assert mail.from - checks if mail.from is truthy (which it always is)
"from@example.com" - this second argument is completely ignored


email_headers = mail.header
assert_equal "from@example.com", email_headers[:from].to_s
assert_equal "reply_to@example.com", email_headers[:reply_to].to_s
assert_equal "to@example.com", email_headers[:to].to_s
end
end