Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show html/text part both if mail consists of multipart #2

Merged
merged 1 commit into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/automaildoc/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,17 @@ def subject
def body
mail.body || ''
end

def multipart?
mail.multipart?
end

def text_part
mail.text_part
end

def html_part
mail.html_part
end
end
end
16 changes: 14 additions & 2 deletions lib/automaildoc/templates/mail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,20 @@
<span class="badge badge-default"><%= mail %></span>
<% end %>
</div>

<h4>Subject</h4>
<pre><%= subject %></pre>
<pre><%= body %></pre>

<h4>Body</h4>
<% if multipart? %>
<h5><%= html_part.content_type %></h5>
<pre><%= html_part.body %></pre>

<h5><%= text_part.content_type %></h5>
<pre><%= text_part.body %></pre>
<% else %>
<pre><%= body %></pre>
<% end %>
</div>

<hr>
<hr/>
37 changes: 32 additions & 5 deletions spec/dummy/doc/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ <h3>Meetup mail should sent to user</h3>
BCC:

</div>

<h4>Subject</h4>
<pre>How about pair programming session?</pre>
<pre>Hey, Chris!

<h4>Body</h4>

<pre>Hey, Chris!

As you know, we keep the meetups on a regular monthly basis: the first Monday of the month, at 7:30pm.

Expand All @@ -146,9 +151,10 @@ <h3>Meetup mail should sent to user</h3>
Awesome Startup
https://awesome.example.com/
</pre>

</div>

<hr>
<hr/>


<div id="./spec/mails/signup_spec.rb[1:1]" class="mail">
Expand All @@ -171,10 +177,30 @@ <h3>Sign up mail for newly signed up user</h3>
<span class="badge badge-default">data-analysis@example.com</span>

</div>

<h4>Subject</h4>
<pre>Welcome to our awesome new service!</pre>
<pre>Hello Johns Lee!

You’ve recently signed up to our <br>Awesome Product</br>, and we hope that you’ve noticed that there is much more to it than boring one.
<h4>Body</h4>

<h5>text/html; charset=UTF-8</h5>
<pre><h1>Hello Johns Lee!</h1>

You’ve recently signed up to our <b>Awesome Product</b>,<br/>and we hope that you’ve noticed that there is much more to it than boring one.

Let’s see what else you can do on our product.

----------------------------------------------------

Awesome Startup
https://awesome.example.com/
</pre>

<h5>text/plain</h5>
<pre>Hello Johns Lee!

You’ve recently signed up to our Awesome Product,
and we hope that you’ve noticed that there is much more to it than boring one.

Let’s see what else you can do on our product.

Expand All @@ -183,9 +209,10 @@ <h3>Sign up mail for newly signed up user</h3>
Awesome Startup
https://awesome.example.com/
</pre>

</div>

<hr>
<hr/>


</div>
Expand Down
41 changes: 31 additions & 10 deletions spec/mails/signup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,46 @@
to 'early-adoptor@example.com'
bcc ['customer-support@example.com', 'data-analysis@example.com']
subject 'Welcome to our awesome new service!'
body <<~EOS
Hello Johns Lee!

You’ve recently signed up to our <br>Awesome Product</br>, and we hope that you’ve noticed that there is much more to it than boring one.
text_part do
body <<~EOS
Hello Johns Lee!

Let’s see what else you can do on our product.
You’ve recently signed up to our Awesome Product,
and we hope that you’ve noticed that there is much more to it than boring one.

----------------------------------------------------
Let’s see what else you can do on our product.

Awesome Startup
https://awesome.example.com/
EOS
----------------------------------------------------

Awesome Startup
https://awesome.example.com/
EOS
end

html_part do
content_type 'text/html; charset=UTF-8'
body <<~EOS
<h1>Hello Johns Lee!</h1>

You’ve recently signed up to our <b>Awesome Product</b>,<br/>and we hope that you’ve noticed that there is much more to it than boring one.

Let’s see what else you can do on our product.

----------------------------------------------------

Awesome Startup
https://awesome.example.com/
EOS
end
end
}

it 'should sent to user' do
it 'should sent to user with text/html parts' do
expect(mail.from).to match_array ['awesome-startup@example.com']
expect(mail.to).to match_array ['early-adoptor@example.com']
expect(mail.subject).to eq('Welcome to our awesome new service!')
expect(mail.body.to_s).to include 'Johns Lee'
expect(mail.text_part.body.to_s).to include 'Johns Lee'
expect(mail.html_part.body.to_s).to include 'Johns Lee'
end
end