Skip to content

Commit

Permalink
mailer test for barnstar (#2433)
Browse files Browse the repository at this point in the history
  • Loading branch information
grvsachdeva authored and jywarren committed Mar 7, 2018
1 parent 000ef21 commit 73a4d87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/comment_mailer/notify_barnstar.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @giver.name %>"><%= @giver.name %></a> has awarded you a <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/barnstars">Barnstar</a> for your work in the research note "<a href="<%= @note.path %>"><%= @note.title %></a>". Do NOT reply to this email; click this link to respond:
'<a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @giver.name %>'><%= @giver.name %></a>' has awarded you a '<a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/barnstars'>Barnstar</a>' for your work in the research note '<a href='https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %>'><%= @note.title %></a>'. Do NOT reply to this email; click this link to respond:

<p>https://<%= ActionMailer::Base.default_url_options[:host] %><%= @note.path %></p>

Expand Down
15 changes: 15 additions & 0 deletions test/unit/comment_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@ class CommentMailerTest < ActionMailer::TestCase
assert_equal "New comment on your answer on '" + comment.parent.title + "'", email.subject
assert email.body.include?("Hi! There's been a new comment to your answer on '<a href='https://#{request_host}#{comment.parent.path(:question)}#a#{comment.answer.id}'>#{comment.parent.title}</a>'")
end

test 'notify barnstar' do
user = users(:bob)
note = nodes(:one)
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
CommentMailer.notify_barnstar(user, note)
end
assert !ActionMailer::Base.deliveries.empty?

email = ActionMailer::Base.deliveries.last
assert_equal ["do-not-reply@#{request_host}"], email.from
assert_equal [note.author.email], email.to
assert_equal "You were awarded a Barnstar!", email.subject
assert email.body.include?("'<a href='https://#{request_host}/profile/#{user.name}'>#{user.name}</a>' has awarded you a '<a href='https://#{request_host}/wiki/barnstars'>Barnstar</a>' for your work in the research note '<a href='https://#{request_host}#{note.path}'>#{note.title}</a>'")
end
end

0 comments on commit 73a4d87

Please sign in to comment.