Skip to content

Commit

Permalink
Merge pull request #45935 from the-spectator/add_bcc_to_mailer_preview
Browse files Browse the repository at this point in the history
Show BCC field in mailer preview
  • Loading branch information
jonathanhefner committed Sep 8, 2022
2 parents 29992a7 + f44362b commit bee6167
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Show BCC recipients when present in Action Mailer previews.

*Akshay Birajdar*

* Extend `routes --grep` to also filter routes by matching against path.

Example:
Expand Down
5 changes: 5 additions & 0 deletions railties/lib/rails/templates/rails/mailers/email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<dd id="cc"><%= @email.header['cc'] %></dd>
<% end %>
<% if @email.bcc %>
<dt>BCC:</dt>
<dd id="bcc"><%= @email.header['bcc'] %></dd>
<% end %>

<dt>Date:</dt>
<dd id="date"><%= Time.current.rfc2822 %></dd>

Expand Down
30 changes: 30 additions & 0 deletions railties/test/application/mailer_previews_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,36 @@ def foo
assert_match "<title>Mailer Preview for notifier#foo</title>", last_response.body
end

test "mailer preview sender tags" do
mailer "notifier", <<-RUBY
class Notifier < ActionMailer::Base
default from: "from@example.com"
def foo
mail to: "to@example.org", cc: "cc@example.com", bcc: "bcc@example.com"
end
end
RUBY

text_template "notifier/foo", <<-RUBY
Hello, World!
RUBY

mailer_preview "notifier", <<-RUBY
class NotifierPreview < ActionMailer::Preview
def foo
Notifier.foo
end
end
RUBY

app("development")

get "/rails/mailers/notifier/foo"
assert_match "<dd id=\"to\">to@example.org</dd>", last_response.body
assert_match "<dd id=\"cc\">cc@example.com</dd>", last_response.body
assert_match "<dd id=\"bcc\">bcc@example.com</dd>", last_response.body
end

private
def build_app
super
Expand Down

0 comments on commit bee6167

Please sign in to comment.