Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When an application defines mailers without any corresponding previews, requests to `GET /rails/mailers` return a page with a blank `<body>` element. This entirely empty page can be confusing, since it's difficult to distinguish the "success" state with an empty list and a "failure" state with swallowed errors. Similarly, when an `ActionMailer::Preview` subclass is defined, but doesn't declare any actions, the response contains a mostly empty page. This commit renders empty-state messaging for both scenarios, and links to the [Action Mailer Basics][] guides. To effectively cover that behavior, this commit also expands the Mailer Preview test coverage to utilize [rails-dom-testing][] assertions. [Action Mailer Basics]: https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails [rails-dom-testing]: http://github.com/rails/rails-dom-testing
- Loading branch information
1 parent
a167350
commit c4b67ec
Showing
4 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
<% @previews.each do |preview| %> | ||
<h3><%= link_to preview.preview_name.titleize, url_for(controller: "rails/mailers", action: "preview", path: preview.preview_name) %></h3> | ||
<ul> | ||
<% preview.emails.each do |email| %> | ||
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{preview.preview_name}/#{email}") %></li> | ||
<% end %> | ||
</ul> | ||
<h1><%= @page_title %></h1> | ||
|
||
<% if @previews.any? %> | ||
<% @previews.each do |preview| %> | ||
<h3><%= link_to preview.preview_name.titleize, url_for(controller: "rails/mailers", action: "preview", path: preview.preview_name) %></h3> | ||
<ul> | ||
<% preview.emails.each do |email| %> | ||
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{preview.preview_name}/#{email}") %></li> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
<% else %> | ||
<p>You have not defined any Action Mailer Previews.</p> | ||
<p>Read <%= link_to "Action Mailer Basics", "https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails" %> to learn how to define your first.</p> | ||
<% end %> |
16 changes: 11 additions & 5 deletions
16
railties/lib/rails/templates/rails/mailers/mailer.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
<h3><%= @preview.preview_name.titleize %></h3> | ||
<ul> | ||
<% @preview.emails.each do |email| %> | ||
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{@preview.preview_name}/#{email}") %></li> | ||
<h1><%= @page_title %></h1> | ||
|
||
<% if @preview.emails.any? %> | ||
<ul> | ||
<% @preview.emails.each do |email| %> | ||
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{@preview.preview_name}/#{email}") %></li> | ||
<% end %> | ||
</ul> | ||
<% else %> | ||
<p>You have not defined any actions for <%= @preview %>.</p> | ||
<p>Read <%= link_to "Action Mailer Basics", "https://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails" %> to learn how to define your first.</p> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters