Support multipart mail. #16

Merged
merged 1 commit into from Jan 5, 2013
View
10 lib/capybara/email/driver.rb
@@ -72,7 +72,15 @@ def source
#
# @return String
def raw
- email.body.encoded
+ if email.mime_type == 'multipart/alternative'
+ if email.html_part
+ return email.html_part.body.encoded
+ elsif email.text_part
+ return email.text_part.body.encoded
+ end
+ end
+
+ return email.body.encoded
end
private
View
28 spec/email/driver_spec.rb
@@ -40,6 +40,21 @@ def self.call(env)
all_emails.should be_empty
end
+ # should read html_part
+ scenario 'multipart email' do
+ email = deliver(multipart_email)
+
+ open_email('test@example.com')
+ current_email.click_link 'example'
+ page.should have_content 'Hello world!'
+ current_email.should have_content 'This is only a html test'
+
+ all_emails.first.should eq email
+
+ clear_emails
+ all_emails.should be_empty
+ end
+
scenario 'via ActionMailer' do
email = deliver(plain_email)
@@ -102,3 +117,16 @@ def plain_email
http://example.com
PLAIN
end
+
+def multipart_email
+ Mail::Message.new do
+ to 'test@example.com'
+ text_part do
+ body plain_email.body.encoded
+ end
+ html_part do
+ content_type 'text/html; charset=UTF-8'
+ body html_email.body.encoded
+ end
+ end
+end