mirror of https://github.com/rails/rails
Merge pull request #35446 from jhawthorn/actionmailer_format_assignment
Add test and change how format set in ActionMailer
This commit is contained in:
commit
f4a30d2a07
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Implicit Multipart <%= formats.inspect %>
|
|
@ -0,0 +1 @@
|
|||
Implicit Multipart <%= formats.inspect %>
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue