Permalink
Browse files

Merge pull request #16 from doitian/multipart-mail

Support multipart mail.
  • Loading branch information...
2 parents fcae38b + 92d3af9 commit 6d97b2ca5fc6af6ba75ef068d8d19249af6a9b9c @bcardarella bcardarella committed Jan 5, 2013
Showing with 37 additions and 1 deletion.
  1. +9 −1 lib/capybara/email/driver.rb
  2. +28 −0 spec/email/driver_spec.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
@@ -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

0 comments on commit 6d97b2c

Please sign in to comment.