From d704f8f808210171964d1822d5ffd6b227b702b2 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 27 Apr 2015 09:38:14 +0200 Subject: mailer previews, make sure labels and values line up. While this was true before when every `dd` had a value, this patch makes sure that everything keeps lining up even when the `dd` node is blank. --- actionmailer/CHANGELOG.md | 4 ++++ railties/lib/rails/templates/rails/mailers/email.html.erb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 86ecb3ee88..12867c7c9e 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,7 @@ +* Make sure labels and values line up in mailer previews. + + *Yves Senn* + * Add `assert_enqueued_emails` and `assert_no_enqueued_emails`. Example: diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb index 0b08a01896..cce818d103 100644 --- a/railties/lib/rails/templates/rails/mailers/email.html.erb +++ b/railties/lib/rails/templates/rails/mailers/email.html.erb @@ -39,6 +39,10 @@ padding: 1px; } + dd:empty:before { + content: "\00a0"; //   + } + iframe { border: 0; width: 100%; -- cgit v1.2.3 From 767d60156b89382326ce42f3ddca0cb860d38149 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 27 Apr 2015 10:15:52 +0200 Subject: mailer previews for `NullMail` instances. Closes #19849. --- actionmailer/CHANGELOG.md | 7 ++++++ actionmailer/lib/action_mailer/base.rb | 1 + railties/lib/rails/mailers_controller.rb | 10 ++++----- .../rails/templates/rails/mailers/email.html.erb | 9 +++++++- railties/test/application/mailer_previews_test.rb | 26 ++++++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 12867c7c9e..0d47ce855a 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,10 @@ +* Mailer previews no longer crash when the `mail` method wasn't called + (`NullMail`). + + Fixes #19849. + + *Yves Senn* + * Make sure labels and values line up in mailer previews. *Yves Senn* diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 754f698e48..218b7a735a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -596,6 +596,7 @@ module ActionMailer class NullMail #:nodoc: def body; '' end + def header; {} end def respond_to?(string, include_all=false) true diff --git a/railties/lib/rails/mailers_controller.rb b/railties/lib/rails/mailers_controller.rb index 32740d66da..cd1c097eb6 100644 --- a/railties/lib/rails/mailers_controller.rb +++ b/railties/lib/rails/mailers_controller.rb @@ -16,10 +16,10 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: @page_title = "Mailer Previews for #{@preview.preview_name}" render action: 'mailer' else - email = File.basename(params[:path]) + @email_action = File.basename(params[:path]) - if @preview.email_exists?(email) - @email = @preview.call(email) + if @preview.email_exists?(@email_action) + @email = @preview.call(@email_action) if params[:part] part_type = Mime::Type.lookup(params[:part]) @@ -28,14 +28,14 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc: response.content_type = part_type render text: part.respond_to?(:decoded) ? part.decoded : part else - raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{email}" + raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{@email_action}" end else @part = find_preferred_part(request.format, Mime::HTML, Mime::TEXT) render action: 'email', layout: false, formats: %w[html] end else - raise AbstractController::ActionNotFound, "Email '#{email}' not found in #{@preview.name}" + raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}" end end end diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb index cce818d103..afca6368d5 100644 --- a/railties/lib/rails/templates/rails/mailers/email.html.erb +++ b/railties/lib/rails/templates/rails/mailers/email.html.erb @@ -103,7 +103,14 @@ - +<% if @part.mime_type %> + +<% else %> +

+ You are trying to preview an email that does not have any content. + This is probably because the mail method has not been called in <%= @preview.preview_name %>#<%= @email_action %>. +

+<% end %> diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb index 1752a9f3c6..83501a7f11 100644 --- a/railties/test/application/mailer_previews_test.rb +++ b/railties/test/application/mailer_previews_test.rb @@ -327,6 +327,32 @@ module ApplicationTests assert_match "Email 'bar' not found in NotifierPreview", last_response.body end + test "mailer preview NullMail" do + mailer 'notifier', <<-RUBY + class Notifier < ActionMailer::Base + default from: "from@example.com" + + def foo + # does not call +mail+ + end + end + 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 "You are trying to preview an email that does not have any content.", last_response.body + assert_match "notifier#foo", last_response.body + end + test "mailer preview email part not found" do mailer 'notifier', <<-RUBY class Notifier < ActionMailer::Base -- cgit v1.2.3