fix #1224 email reply to whom
This commit is contained in:
parent
bc27b2c929
commit
3d4b2c2b2d
|
@ -5,6 +5,13 @@ class EmailReply < ApplicationMailer
|
|||
@comment = comment
|
||||
@user = user
|
||||
|
||||
@replied_to = "you"
|
||||
if @comment.parent_comment.nil?
|
||||
@replied_to = "your story"
|
||||
elsif @comment.parent_comment.user != @user
|
||||
@replied_to = @comment.parent_comment.user.username
|
||||
end
|
||||
|
||||
mail(
|
||||
to: user.email,
|
||||
subject: "[#{Rails.application.name}] Reply from " \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<%= @comment.user.username %> has replied to you:
|
||||
<%= @comment.user.username %> has replied to <%= @replied_to %>:
|
||||
|
||||
<%= word_wrap(@comment.plaintext_comment, :line_width => 72).gsub(/\n/, "\n ") %>
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# typed: false
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe EmailReply, type: :mailer do
|
||||
it "addresses replies to receiver" do
|
||||
comment = create(:comment)
|
||||
user = comment.user
|
||||
reply = create(:comment, parent_comment: comment)
|
||||
|
||||
email = EmailReply.reply(reply, user)
|
||||
expect(email.body.encoded).to match("replied to you")
|
||||
end
|
||||
|
||||
it "addresses top-level story responses" do
|
||||
user = create(:story).user
|
||||
comment = create(:comment)
|
||||
|
||||
email = EmailReply.reply(comment, user)
|
||||
expect(email.body.encoded).to match("replied to your story")
|
||||
end
|
||||
|
||||
it "addresses story replies" do
|
||||
user = create(:story).user
|
||||
comment = create(:comment, user: create(:user, username: "alice"))
|
||||
reply = create(:comment, parent_comment: comment)
|
||||
|
||||
email = EmailReply.reply(reply, user)
|
||||
expect(email.body.encoded).to match("replied to alice")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
# Preview all emails at http://localhost:3000/rails/mailers/email_reply
|
||||
class EmailReplyPreview < ActionMailer::Preview
|
||||
|
||||
end
|
Loading…
Reference in New Issue