diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-11-19 19:23:44 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-11-19 19:23:44 -0500 |
commit | 72062c8c9d32237d1eb7d3eb3318f65042383408 (patch) | |
tree | 7168d4225215f2a2df61e31b45e92258fc11f8db /actionmailer | |
parent | 4aad2e2228b2127680e6b5aaba5c0cf0e09b1467 (diff) | |
parent | 5c54db290f4e7cdd69b461d4c0b020a9cd364537 (diff) | |
download | rails-72062c8c9d32237d1eb7d3eb3318f65042383408.tar.gz rails-72062c8c9d32237d1eb7d3eb3318f65042383408.tar.bz2 rails-72062c8c9d32237d1eb7d3eb3318f65042383408.zip |
Merge pull request #22534 from evopark/master
ActionMailer: support overriding template name in multipart
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 11 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 6 | ||||
-rw-r--r-- | actionmailer/test/mailers/base_mailer.rb | 7 |
4 files changed, 26 insertions, 3 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index db6fc7ee9c..35574a2c73 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,8 @@ +* Mails with multipart `format` blocks with implicit render now also check for + a template name in options hash instead of only using the action name. + + *Marcus Ilgner* + * Allow ActionMailer classes to configure the parameterized delivery job Example: ``` diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 509d859ac3..2bb1078bb8 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -942,9 +942,7 @@ module ActionMailer def collect_responses(headers) if block_given? - collector = ActionMailer::Collector.new(lookup_context) { render(action_name) } - yield(collector) - collector.responses + collect_responses_from_block(headers, &Proc.new) elsif headers[:body] collect_responses_from_text(headers) else @@ -952,6 +950,13 @@ module ActionMailer end end + def collect_responses_from_block(headers) + templates_name = headers[:template_name] || action_name + collector = ActionMailer::Collector.new(lookup_context) { render(templates_name) } + yield(collector) + collector.responses + end + def collect_responses_from_text(headers) [{ body: headers.delete(:body), diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index cbbee9fae8..86c0172772 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -544,6 +544,12 @@ class BaseTest < ActiveSupport::TestCase assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded) end + test "you can specify a different template for multipart render" do + mail = BaseMailer.implicit_different_template_with_block("explicit_multipart_templates").deliver + assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded) + assert_equal("TEXT Explicit Multipart Templates", mail.text_part.body.decoded) + end + test "should raise if missing template in implicit render" do assert_raises ActionView::MissingTemplate do BaseMailer.implicit_different_template("missing_template").deliver_now diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index a3101207dc..c1bb48cc96 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -111,6 +111,13 @@ class BaseMailer < ActionMailer::Base mail(template_name: template_name) end + def implicit_different_template_with_block(template_name = "") + mail(template_name: template_name) do |format| + format.text + format.html + end + end + def explicit_different_template(template_name = "") mail do |format| format.text { render template: "#{mailer_name}/#{template_name}" } |