Merge pull request #35446 from jhawthorn/actionmailer_format_assignment

Add test and change how format set in ActionMailer
This commit is contained in:
Aaron Patterson 2019-03-01 14:35:29 -08:00 committed by GitHub
commit f4a30d2a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 2 deletions

View File

@ -974,9 +974,8 @@ module ActionMailer
each_template(Array(templates_path), templates_name).map do |template|
format = template.format || self.formats.first
self.formats = [format]
{
body: render(template: template),
body: render(template: template, formats: [format]),
content_type: Mime[format].to_s
}
end

View File

@ -307,6 +307,16 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("HTML Implicit Multipart", email.parts[1].body.encoded)
end
test "implicit multipart formats" do
email = BaseMailer.implicit_multipart_formats
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("Implicit Multipart [:text]", email.parts[0].body.encoded)
assert_equal("text/html", email.parts[1].mime_type)
assert_equal("Implicit Multipart [:html]", email.parts[1].body.encoded)
end
test "implicit multipart with sort order" do
order = ["text/html", "text/plain"]
with_default BaseMailer, parts_order: order do

View File

@ -0,0 +1 @@
Implicit Multipart <%= formats.inspect %>

View File

@ -0,0 +1 @@
Implicit Multipart <%= formats.inspect %>

View File

@ -62,6 +62,10 @@ class BaseMailer < ActionMailer::Base
mail(hash)
end
def implicit_multipart_formats(hash = {})
mail(hash)
end
def implicit_with_locale(hash = {})
mail(hash)
end