From e94e9b7621215a9493b099686b102bdd41425fe6 Mon Sep 17 00:00:00 2001
From: Chris Hunt <c@chrishunt.co>
Date: Wed, 29 May 2013 09:37:31 -0700
Subject: [PATCH] Set UTF-8 charset for plain text email part

---
 lib/email_sender.rb                  |  2 ++
 spec/components/email_sender_spec.rb | 31 ++++++++++------------------
 2 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/lib/email_sender.rb b/lib/email_sender.rb
index 495542b18..5f6f1a392 100644
--- a/lib/email_sender.rb
+++ b/lib/email_sender.rb
@@ -27,6 +27,8 @@ class EmailSender
       body PrettyText.cook(plain_body, environment: 'email')
     end
 
+    @message.text_part.content_type = 'text/plain; charset=UTF-8'
+
     @message.deliver
 
     to_address = @message.to
diff --git a/spec/components/email_sender_spec.rb b/spec/components/email_sender_spec.rb
index 2465a7d75..f44c11181 100644
--- a/spec/components/email_sender_spec.rb
+++ b/spec/components/email_sender_spec.rb
@@ -62,36 +62,27 @@ describe EmailSender do
 
     end
 
-    context 'html' do
-      before do
-        email_sender.send
-      end
+    context 'email parts' do
+      before { email_sender.send }
 
       it 'makes the message multipart' do
         message.should be_multipart
       end
 
-      it 'has a html part' do
-        message.parts.detect {|p| p.content_type == "text/html; charset=UTF-8"}.should be_true
+      it 'sets the correct content type for the plain text part' do
+        expect(message.text_part.content_type).to eq 'text/plain; charset=UTF-8'
       end
 
-      context 'html part' do
-        let(:html_part) { message.parts.detect {|p| p.content_type == "text/html; charset=UTF-8"} }
-
-        it 'has a html part' do
-          html_part.should be_present
-        end
-
-        it 'has run markdown on the body' do
-          html_part.body.to_s.should == "<p><strong>hello</strong></p>"
-        end
-
+      it 'sets the correct content type for the html part' do
+        expect(message.html_part.content_type).to eq 'text/html; charset=UTF-8'
       end
 
-
+      it 'converts the html part to html' do
+        expect(message.html_part.body.to_s).to eq(
+          "<p><strong>hello</strong></p>"
+        )
+      end
     end
-
-
   end
 
   context 'with a user' do