diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-04-26 20:15:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-26 20:15:30 -0700 |
commit | f680664d4e2f81216ee73c047b836d49a796234c (patch) | |
tree | 985f28bfde95728cc010bbe553270ccfb8973c47 /actionmailer | |
parent | 971ceeb844b70a510d2e52c34108894248522797 (diff) | |
parent | 8e6c6d854cdedad4bc082cf45a01d411ea26fb68 (diff) | |
download | rails-f680664d4e2f81216ee73c047b836d49a796234c.tar.gz rails-f680664d4e2f81216ee73c047b836d49a796234c.tar.bz2 rails-f680664d4e2f81216ee73c047b836d49a796234c.zip |
Merge pull request #28244 from ixti/improve/action-mailer-preview-params
Pass request params to ActionMailer::Preview
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/preview.rb | 10 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 16 |
2 files changed, 24 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/preview.rb b/actionmailer/lib/action_mailer/preview.rb index b0152aff03..87ba743f3d 100644 --- a/actionmailer/lib/action_mailer/preview.rb +++ b/actionmailer/lib/action_mailer/preview.rb @@ -52,6 +52,12 @@ module ActionMailer class Preview extend ActiveSupport::DescendantsTracker + attr_reader :params + + def initialize(params = {}) + @params = params + end + class << self # Returns all mailer preview classes. def all @@ -62,8 +68,8 @@ module ActionMailer # Returns the mail object for the given email name. The registered preview # interceptors will be informed so that they can transform the message # as they would if the mail was actually being delivered. - def call(email) - preview = new + def call(email, params = {}) + preview = new(params) message = preview.public_send(email) inform_preview_interceptors(message) message diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 61960d411d..ebb97078e6 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -968,3 +968,19 @@ class BasePreviewInterceptorsTest < ActiveSupport::TestCase end end end + +class BasePreviewTest < ActiveSupport::TestCase + class BaseMailerPreview < ActionMailer::Preview + def welcome + BaseMailer.welcome(params) + end + end + + test "has access to params" do + params = { name: "World" } + + assert_called_with(BaseMailer, :welcome, [params]) do + BaseMailerPreview.call(:welcome, params) + end + end +end |