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:
@@ -4,23 +4,23 @@ class Mailer < ApplicationMailer
|
||||
|
||||
def comment(comment)
|
||||
@comment = comment
|
||||
@debate = comment.debate
|
||||
mail(to: @debate.author.email, subject: t('mailer.comment.subject'))
|
||||
@commentable = comment.commentable
|
||||
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
|
||||
|
||||
def reply(reply)
|
||||
@reply = reply
|
||||
@debate = @reply.debate
|
||||
@commentable = @reply.commentable
|
||||
parent = Comment.find(@reply.parent_id)
|
||||
@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
|
||||
|
||||
def email_verification(user, recipient, token)
|
||||
@user = user
|
||||
@recipient = recipient
|
||||
@token = token
|
||||
mail(to: @recipient, subject: "Verifica tu email")
|
||||
mail(to: @recipient, subject: t('mailers.email_verification.subject'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
</h1>
|
||||
|
||||
<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 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 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;">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</p>
|
||||
|
||||
<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 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;">
|
||||
|
||||
@@ -24,6 +24,35 @@ feature 'Emails' do
|
||||
expect(email).to have_body_text(edit_user_password_path)
|
||||
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
|
||||
scenario "Send email on debate comment", :js do
|
||||
user = create(:user, email_on_comment: true)
|
||||
@@ -61,7 +90,7 @@ feature 'Emails' do
|
||||
email = open_last_email
|
||||
expect(email).to have_subject('Someone has replied to your comment')
|
||||
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
|
||||
|
||||
scenario "Do not send email about own replies to own comments", :js do
|
||||
|
||||
Reference in New Issue
Block a user