Skip to content
This repository
Browse code

Allow custom type for multipart emails [#1691 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
commit 1dff106888d671dac07f93711ecb319170132c56 1 parent e8b07dc
Sean Dague authored lifo committed
2  actionmailer/lib/action_mailer/base.rb
@@ -479,7 +479,7 @@ def create!(method_name, *parameters) #:nodoc:
479 479
             )
480 480
           end
481 481
           unless @parts.empty?
482  
-            @content_type = "multipart/alternative"
  482
+            @content_type = "multipart/alternative" if @content_type !~ /^multipart/
483 483
             @parts = sort_parts(@parts, @implicit_parts_order)
484 484
           end
485 485
         end
30  actionmailer/test/mail_layout_test.rb
@@ -21,10 +21,12 @@ def nolayout(recipient)
21 21
     body       render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
22 22
   end
23 23
 
24  
-  def multipart(recipient)
  24
+  def multipart(recipient, type = nil)
25 25
     recipients recipient
26 26
     subject    "You have a mail"
27 27
     from       "tester@example.com"
  28
+
  29
+    content_type(type) if type
28 30
   end
29 31
 end
30 32
 
@@ -64,6 +66,19 @@ def test_should_pickup_default_layout
64 66
 
65 67
   def test_should_pickup_multipart_layout
66 68
     mail = AutoLayoutMailer.create_multipart(@recipient)
  69
+    assert_equal "multipart/alternative", mail.content_type
  70
+    assert_equal 2, mail.parts.size
  71
+
  72
+    assert_equal 'text/plain', mail.parts.first.content_type
  73
+    assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
  74
+
  75
+    assert_equal 'text/html', mail.parts.last.content_type
  76
+    assert_equal "Hello from layout text/html multipart", mail.parts.last.body
  77
+  end
  78
+
  79
+  def test_should_pickup_multipartmixed_layout
  80
+    mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed")
  81
+    assert_equal "multipart/mixed", mail.content_type
67 82
     assert_equal 2, mail.parts.size
68 83
 
69 84
     assert_equal 'text/plain', mail.parts.first.content_type
@@ -73,6 +88,19 @@ def test_should_pickup_multipart_layout
73 88
     assert_equal "Hello from layout text/html multipart", mail.parts.last.body
74 89
   end
75 90
 
  91
+  def test_should_fix_multipart_layout
  92
+    mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain")
  93
+    assert_equal "multipart/alternative", mail.content_type
  94
+    assert_equal 2, mail.parts.size
  95
+
  96
+    assert_equal 'text/plain', mail.parts.first.content_type
  97
+    assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
  98
+
  99
+    assert_equal 'text/html', mail.parts.last.content_type
  100
+    assert_equal "Hello from layout text/html multipart", mail.parts.last.body
  101
+  end
  102
+
  103
+
76 104
   def test_should_pickup_layout_given_to_render
77 105
     mail = AutoLayoutMailer.create_spam(@recipient)
78 106
     assert_equal "Spammer layout Hello, Earth", mail.body.strip

0 notes on commit 1dff106

Please sign in to comment.
Something went wrong with that request. Please try again.