From b6b3db6734af8d5b42c7bdcea7c73923a5b88463 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Thu, 28 Jan 2010 00:24:30 +1100 Subject: [PATCH] Fixed bug on HTML only emails getting set to text/plain --- actionmailer/lib/action_mailer/base.rb | 2 +- actionmailer/test/base_test.rb | 18 ++++++++++++++++++ .../fixtures/base_mailer/html_only.html.erb | 1 + .../base_mailer/plain_text_only.text.erb | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 actionmailer/test/fixtures/base_mailer/html_only.html.erb create mode 100644 actionmailer/test/fixtures/base_mailer/plain_text_only.text.erb diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 2288a30691..3fbf004a0d 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -531,7 +531,7 @@ module ActionMailer #:nodoc: when m.multipart? ["multipart", "alternative", params] else - class_default + m.content_type || class_default end end diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 4a65363e3e..b7af86b622 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -17,6 +17,14 @@ class BaseTest < ActiveSupport::TestCase def simple(hash = {}) mail(hash) end + + def html_only(hash = {}) + mail(hash) + end + + def plain_text_only(hash = {}) + mail(hash) + end def simple_with_headers(hash = {}) headers hash @@ -434,6 +442,16 @@ class BaseTest < ActiveSupport::TestCase mail = BaseMailer.explicit_multipart assert_not_nil(mail.content_type_parameters[:boundary]) end + + test "should set a content type if only has an html part" do + mail = BaseMailer.html_only + assert_equal('text/html', mail.mime_type) + end + + test "should set a content type if only has an plain text part" do + mail = BaseMailer.plain_text_only + assert_equal('text/plain', mail.mime_type) + end protected diff --git a/actionmailer/test/fixtures/base_mailer/html_only.html.erb b/actionmailer/test/fixtures/base_mailer/html_only.html.erb new file mode 100644 index 0000000000..9c99a008e7 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/html_only.html.erb @@ -0,0 +1 @@ +

Testing

\ No newline at end of file diff --git a/actionmailer/test/fixtures/base_mailer/plain_text_only.text.erb b/actionmailer/test/fixtures/base_mailer/plain_text_only.text.erb new file mode 100644 index 0000000000..0a90125685 --- /dev/null +++ b/actionmailer/test/fixtures/base_mailer/plain_text_only.text.erb @@ -0,0 +1 @@ +Testing \ No newline at end of file