mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ensure implicit multipart templates with locale works as expected.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
require 'active_support/core_ext/class'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/core_ext/array/uniq_by'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/core_ext/string/inflections'
|
||||
require 'mail'
|
||||
require 'action_mailer/tmail_compat'
|
||||
require 'action_mailer/collector'
|
||||
@@ -455,6 +458,8 @@ module ActionMailer #:nodoc:
|
||||
def each_template(&block) #:nodoc:
|
||||
self.class.view_paths.each do |load_paths|
|
||||
templates = load_paths.find_all(action_name, {}, self.class.mailer_name)
|
||||
templates = templates.uniq_by { |t| t.details[:formats] }
|
||||
|
||||
unless templates.empty?
|
||||
templates.each(&block)
|
||||
return
|
||||
|
||||
@@ -34,6 +34,10 @@ class BaseTest < ActiveSupport::TestCase
|
||||
mail(DEFAULT_HEADERS.merge(hash))
|
||||
end
|
||||
|
||||
def implicit_with_locale(hash = {})
|
||||
mail(DEFAULT_HEADERS.merge(hash))
|
||||
end
|
||||
|
||||
def explicit_multipart(hash = {})
|
||||
attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
|
||||
mail(DEFAULT_HEADERS.merge(hash)) do |format|
|
||||
@@ -310,6 +314,29 @@ class BaseTest < ActiveSupport::TestCase
|
||||
assert_equal(1, BaseMailer.deliveries.length)
|
||||
end
|
||||
|
||||
test "implicit multipart with default locale" do
|
||||
email = BaseMailer.implicit_with_locale.deliver
|
||||
assert_equal(2, email.parts.size)
|
||||
assert_equal("multipart/alternate", email.mime_type)
|
||||
assert_equal("text/plain", email.parts[0].mime_type)
|
||||
assert_equal("Implicit with locale TEXT", email.parts[0].body.encoded)
|
||||
assert_equal("text/html", email.parts[1].mime_type)
|
||||
assert_equal("Implicit with locale EN HTML", email.parts[1].body.encoded)
|
||||
end
|
||||
|
||||
test "implicit multipart with other locale" do
|
||||
swap I18n, :locale => :pl do
|
||||
email = BaseMailer.implicit_with_locale.deliver
|
||||
assert_equal(2, email.parts.size)
|
||||
assert_equal("multipart/alternate", email.mime_type)
|
||||
assert_equal("text/plain", email.parts[0].mime_type)
|
||||
assert_equal("Implicit with locale PL TEXT", email.parts[0].body.encoded)
|
||||
assert_equal("text/html", email.parts[1].mime_type)
|
||||
assert_equal("Implicit with locale HTML", email.parts[1].body.encoded)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
# Execute the block setting the given values and restoring old values after
|
||||
|
||||
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.en.html.erb
vendored
Normal file
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.en.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Implicit with locale EN HTML
|
||||
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.html.erb
vendored
Normal file
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.html.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Implicit with locale HTML
|
||||
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.pl.text.erb
vendored
Normal file
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.pl.text.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Implicit with locale PL TEXT
|
||||
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.text.erb
vendored
Normal file
1
actionmailer/test/fixtures/base_mailer/implicit_with_locale.text.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Implicit with locale TEXT
|
||||
Reference in New Issue
Block a user