diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index db4589ee8f4a322ccf8ac595ab669ecb0b6ccedc..b77409b64bd424ea140e7cdca03c92e76870a7a9 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -479,7 +479,7 @@ def create!(method_name, *parameters) #:nodoc: ) end unless @parts.empty? - @content_type = "multipart/alternative" + @content_type = "multipart/alternative" if @content_type !~ /^multipart/ @parts = sort_parts(@parts, @implicit_parts_order) end end diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb index c185bd5acdb3cdc6db49844e88e47d09ece97f96..50901f52ece63c177b6b4035fd111cc883751f62 100644 --- a/actionmailer/test/mail_layout_test.rb +++ b/actionmailer/test/mail_layout_test.rb @@ -21,10 +21,12 @@ def nolayout(recipient) body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" }) end - def multipart(recipient) + def multipart(recipient, type = nil) recipients recipient subject "You have a mail" from "tester@example.com" + + content_type(type) if type end end @@ -64,6 +66,19 @@ def test_should_pickup_default_layout def test_should_pickup_multipart_layout mail = AutoLayoutMailer.create_multipart(@recipient) + assert_equal "multipart/alternative", mail.content_type + assert_equal 2, mail.parts.size + + assert_equal 'text/plain', mail.parts.first.content_type + assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body + + assert_equal 'text/html', mail.parts.last.content_type + assert_equal "Hello from layout text/html multipart", mail.parts.last.body + end + + def test_should_pickup_multipartmixed_layout + mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed") + assert_equal "multipart/mixed", mail.content_type assert_equal 2, mail.parts.size assert_equal 'text/plain', mail.parts.first.content_type @@ -73,6 +88,19 @@ def test_should_pickup_multipart_layout assert_equal "Hello from layout text/html multipart", mail.parts.last.body end + def test_should_fix_multipart_layout + mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain") + assert_equal "multipart/alternative", mail.content_type + assert_equal 2, mail.parts.size + + assert_equal 'text/plain', mail.parts.first.content_type + assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body + + assert_equal 'text/html', mail.parts.last.content_type + assert_equal "Hello from layout text/html multipart", mail.parts.last.body + end + + def test_should_pickup_layout_given_to_render mail = AutoLayoutMailer.create_spam(@recipient) assert_equal "Spammer layout Hello, Earth", mail.body.strip