aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 09:34:50 +1100
committerJosé Valim and Mikel Lindsaar <pair@programming.com>2010-01-24 09:34:50 +1100
commite7e4ed48df3048f32d94e398e99d0048a66ba67e (patch)
treed85022fbbcf76853c8f95b72b4271943e745365a /actionmailer
parentc985a0ee3d9ae279fd02814ca60782e2f93215e4 (diff)
downloadrails-e7e4ed48df3048f32d94e398e99d0048a66ba67e.tar.gz
rails-e7e4ed48df3048f32d94e398e99d0048a66ba67e.tar.bz2
rails-e7e4ed48df3048f32d94e398e99d0048a66ba67e.zip
Set sort order for explicit parts from the collector's template sequence
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb12
-rw-r--r--actionmailer/test/base_test.rb19
2 files changed, 17 insertions, 14 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 4ab3761807..e95643ca44 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -415,7 +415,7 @@ module ActionMailer #:nodoc:
# Should be removed when old API is deprecated
@mail_was_called = true
- m, sort_parts = @message, true
+ m = @message
# Give preference to headers and fallback to the ones set in mail
content_type = headers[:content_type] || m.content_type
@@ -425,12 +425,16 @@ module ActionMailer #:nodoc:
headers[:subject] ||= default_subject
quote_fields(m, headers, charset)
+ sort_order = headers[:parts_order] || self.class.default_implicit_parts_order.dup
+
responses = if headers[:body]
[ { :body => headers[:body], :content_type => self.class.default_content_type.dup } ]
elsif block_given?
- sort_parts = false
collector = ActionMailer::Collector.new(self) { render(action_name) }
yield(collector)
+ # Collect the sort order of the parts from the collector as Mail will always
+ # sort parts on encode into a "sane" sequence.
+ sort_order = collector.responses.map { |r| r[:content_type] }
collector.responses
else
# TODO Ensure that we don't need to pass I18n.locale as detail
@@ -447,8 +451,8 @@ module ActionMailer #:nodoc:
m.charset = charset
m.mime_version = mime_version
- if sort_parts && m.parts.present?
- m.body.set_sort_order(headers[:parts_order] || self.class.default_implicit_parts_order.dup)
+ if m.multipart?
+ m.body.set_sort_order(sort_order)
m.body.sort_parts!
end
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 83943162d2..ad0e1d9fe2 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -304,16 +304,15 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("HTML Explicit Multipart", email.parts[1].parts[1].body.encoded)
end
- # TODO Seems Mail is sorting the templates automatically, and not on demand
- # test "explicit multipart with templates" do
- # email = BaseMailer.deliver_explicit_multipart_templates
- # assert_equal(2, email.parts.size)
- # assert_equal("multipart/alternate", email.mime_type)
- # assert_equal("text/html", email.parts[0].mime_type)
- # assert_equal("HTML Explicit Multipart Templates", email.parts[0].body.encoded)
- # assert_equal("text/plain", email.parts[1].mime_type)
- # assert_equal("TEXT Explicit Multipart Templates", email.parts[1].body.encoded)
- # end
+ test "explicit multipart with templates" do
+ email = BaseMailer.deliver_explicit_multipart_templates
+ assert_equal(2, email.parts.size)
+ assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("text/html", email.parts[0].mime_type)
+ assert_equal("HTML Explicit Multipart Templates", email.parts[0].body.encoded)
+ assert_equal("text/plain", email.parts[1].mime_type)
+ assert_equal("TEXT Explicit Multipart Templates", email.parts[1].body.encoded)
+ end
test "explicit multipart with any" do
email = BaseMailer.deliver_explicit_multipart_with_any