specs for previous

This commit is contained in:
Peter Bhat Harkins 2023-12-13 12:09:22 -06:00
parent ff19562026
commit e77495999e
2 changed files with 31 additions and 8 deletions

View File

@ -13,14 +13,14 @@ class EmailReply < ApplicationMailer
end
# threading
headers "Message-Id" => @comment.mailing_list_message_id
if @comment.parent_comment.present?
headers "In-Reply-To" => @comment.parent_comment.mailing_list_message_id
end
headers "References" => (
([@comment.story.mailing_list_message_id] + @comment.parents.map(&:mailing_list_message_id))
.map { |r| "<#{r}>" }
)
headers "Message-Id" => @comment.mailing_list_message_id,
"References" => (
([@comment.story.mailing_list_message_id] + @comment.parents.map(&:mailing_list_message_id))
.map { |r| "<#{r}>" }
),
"In-Reply-To" => @comment.parent_comment.present? ?
@comment.parent_comment.mailing_list_message_id :
@comment.story.mailing_list_message_id
mail(
to: user.email,

View File

@ -3,6 +3,29 @@
require "rails_helper"
RSpec.describe EmailReply, type: :mailer do
it "has a stable message-id" do
comment = create(:comment)
user = comment.user
e1 = EmailReply.reply(comment, user)
e2 = EmailReply.reply(comment, user)
expect(e1["Message-ID"]).to_not be_nil
expect(e1["Message-ID"].to_s).to eq(e2["Message-ID"].to_s)
end
it "has parent in-reply-to and in references" do
user = create(:user)
comment = create(:comment)
reply = create(:comment, parent_comment: comment)
email = EmailReply.reply(reply, user)
expect(email["Message-ID"].to_s).to eq("<#{reply.mailing_list_message_id}>")
expect(email["In-Reply-To"].to_s).to eq("<#{comment.mailing_list_message_id}>")
expect(email["References"].to_s).to include(comment.mailing_list_message_id)
# test inconsistency - factory will create reply with different story id
expect(email["References"].to_s).to include(reply.story.mailing_list_message_id)
end
it "addresses replies to receiver" do
comment = create(:comment)
user = comment.user