Fixes comment notifications mailers

It was not commendable independent so avery email related with a comment on a proposal was not being sent. Removes dependency on debates and makes it commentable independent.
This commit is contained in:
Juanjo Bazán
2015-09-24 12:41:11 +02:00
parent 5df7917c24
commit 3f46b27371
4 changed files with 38 additions and 9 deletions

View File

@@ -4,23 +4,23 @@ class Mailer < ApplicationMailer
def comment(comment) def comment(comment)
@comment = comment @comment = comment
@debate = comment.debate @commentable = comment.commentable
mail(to: @debate.author.email, subject: t('mailer.comment.subject')) mail(to: @commentable.author.email, subject: t('mailers.comment.subject', commentable: t("activerecord.models.#{@commentable.class.name.downcase}").downcase)) if @commentable.present? && @commentable.author.present?
end end
def reply(reply) def reply(reply)
@reply = reply @reply = reply
@debate = @reply.debate @commentable = @reply.commentable
parent = Comment.find(@reply.parent_id) parent = Comment.find(@reply.parent_id)
@recipient = parent.author @recipient = parent.author
mail(to: @recipient.email, subject: t('mailer.reply.subject')) mail(to: @recipient.email, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present?
end end
def email_verification(user, recipient, token) def email_verification(user, recipient, token)
@user = user @user = user
@recipient = recipient @recipient = recipient
@token = token @token = token
mail(to: @recipient, subject: "Verifica tu email") mail(to: @recipient, subject: t('mailers.email_verification.subject'))
end end
end end

View File

@@ -5,11 +5,11 @@
</h1> </h1>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.comment.hi") %> <strong><%= @debate.author.name %></strong>, <%= t("mailers.comment.hi") %> <strong><%= @commentable.author.name %></strong>,
</p> </p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.comment.new_comment_by_html", commenter: @comment.author.name) %> <%= link_to @debate.title, debate_url(@debate), style: "color: #2895F1; text-decoration:none;" %> <%= t("mailers.comment.new_comment_by_html", commenter: @comment.author.name) %> <%= link_to @commentable.title, commentable_url(@commentable), style: "color: #2895F1; text-decoration:none;" %>
</p> </p>
<p style="border-left: 2px solid #DEE0E3;font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-style: italic;font-weight: normal;line-height: 24px;margin-left: 20px;padding: 10px;"> <p style="border-left: 2px solid #DEE0E3;font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-style: italic;font-weight: normal;line-height: 24px;margin-left: 20px;padding: 10px;">

View File

@@ -9,7 +9,7 @@
</p> </p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;"> <p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.reply.new_reply_by_html", commenter: @reply.author.name) %> <%= link_to @debate.title, debate_url(@debate), style: "color: #2895F1; text-decoration:none;" %> <%= t("mailers.reply.new_reply_by_html", commenter: @reply.author.name) %> <%= link_to @commentable.title, commentable_url(@commentable), style: "color: #2895F1; text-decoration:none;" %>
</p> </p>
<p style="border-left: 2px solid #DEE0E3;font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-style: italic;font-weight: normal;line-height: 24px;margin-left: 20px;padding: 10px;"> <p style="border-left: 2px solid #DEE0E3;font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-style: italic;font-weight: normal;line-height: 24px;margin-left: 20px;padding: 10px;">

View File

@@ -24,6 +24,35 @@ feature 'Emails' do
expect(email).to have_body_text(edit_user_password_path) expect(email).to have_body_text(edit_user_password_path)
end end
context 'Proposal comments' do
scenario "Send email on proposal comment", :js do
user = create(:user, email_on_comment: true)
proposal = create(:proposal, author: user)
comment_on(proposal)
email = open_last_email
expect(email).to have_subject('Someone has commented on your proposal')
expect(email).to deliver_to(proposal.author)
expect(email).to have_body_text(proposal_path(proposal))
end
scenario 'Do not send email about own proposal comments', :js do
user = create(:user, email_on_comment: true)
proposal = create(:proposal, author: user)
comment_on(proposal, user)
expect { open_last_email }.to raise_error "No email has been sent!"
end
scenario 'Do not send email about proposal comment unless set in preferences', :js do
user = create(:user, email_on_comment: false)
proposal = create(:proposal, author: user)
comment_on(proposal)
expect { open_last_email }.to raise_error "No email has been sent!"
end
end
context 'Debate comments' do context 'Debate comments' do
scenario "Send email on debate comment", :js do scenario "Send email on debate comment", :js do
user = create(:user, email_on_comment: true) user = create(:user, email_on_comment: true)
@@ -61,7 +90,7 @@ feature 'Emails' do
email = open_last_email email = open_last_email
expect(email).to have_subject('Someone has replied to your comment') expect(email).to have_subject('Someone has replied to your comment')
expect(email).to deliver_to(user) expect(email).to deliver_to(user)
expect(email).to have_body_text(debate_path(Comment.first.debate)) expect(email).to have_body_text(debate_path(Comment.first.commentable))
end end
scenario "Do not send email about own replies to own comments", :js do scenario "Do not send email about own replies to own comments", :js do