Skip to content
This repository
Browse code

Merge pull request #16 from doitian/multipart-mail

Support multipart mail.
  • Loading branch information...
commit 6d97b2ca5fc6af6ba75ef068d8d19249af6a9b9c 2 parents fcae38b + 92d3af9
Brian Cardarella authored January 05, 2013
10  lib/capybara/email/driver.rb
@@ -72,7 +72,15 @@ def source
72 72
   #
73 73
   # @return String
74 74
   def raw
75  
-    email.body.encoded
  75
+    if email.mime_type == 'multipart/alternative'
  76
+      if email.html_part
  77
+        return email.html_part.body.encoded
  78
+      elsif email.text_part
  79
+        return email.text_part.body.encoded
  80
+      end
  81
+    end
  82
+
  83
+    return email.body.encoded
76 84
   end
77 85
 
78 86
   private
28  spec/email/driver_spec.rb
@@ -40,6 +40,21 @@ def self.call(env)
40 40
     all_emails.should be_empty
41 41
   end
42 42
 
  43
+  # should read html_part
  44
+  scenario 'multipart email' do
  45
+    email = deliver(multipart_email)
  46
+
  47
+    open_email('test@example.com')
  48
+    current_email.click_link 'example'
  49
+    page.should have_content 'Hello world!'
  50
+    current_email.should have_content 'This is only a html test'
  51
+
  52
+    all_emails.first.should eq email
  53
+
  54
+    clear_emails
  55
+    all_emails.should be_empty
  56
+  end
  57
+
43 58
   scenario 'via ActionMailer' do
44 59
     email = deliver(plain_email)
45 60
 
@@ -102,3 +117,16 @@ def plain_email
102 117
 http://example.com
103 118
   PLAIN
104 119
 end
  120
+
  121
+def multipart_email
  122
+  Mail::Message.new do
  123
+    to 'test@example.com'
  124
+    text_part do
  125
+      body plain_email.body.encoded
  126
+    end
  127
+    html_part do
  128
+      content_type 'text/html; charset=UTF-8'
  129
+      body html_email.body.encoded
  130
+    end
  131
+  end
  132
+end

0 notes on commit 6d97b2c

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