2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
require "email/message_builder"
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Email::MessageBuilder do
|
2013-06-10 16:46:08 -04:00
|
|
|
let(:to_address) { "jake@adventuretime.ooo" }
|
|
|
|
let(:subject) { "Tree Trunks has made some apple pie!" }
|
|
|
|
let(:body) { "oh my glob Jake, Tree Trunks just made the tastiest apple pie ever!" }
|
|
|
|
let(:builder) { Email::MessageBuilder.new(to_address, subject: subject, body: body) }
|
|
|
|
let(:build_args) { builder.build_args }
|
2013-06-13 17:00:00 -04:00
|
|
|
let(:header_args) { builder.header_args }
|
2018-07-18 04:28:44 -04:00
|
|
|
let(:allow_reply_header) { described_class::ALLOW_REPLY_BY_EMAIL_HEADER }
|
2013-06-10 16:46:08 -04:00
|
|
|
|
|
|
|
it "has the correct to address" do
|
|
|
|
expect(build_args[:to]).to eq(to_address)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the subject" do
|
|
|
|
expect(builder.subject).to eq(subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the body" do
|
|
|
|
expect(builder.body).to eq(body)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a utf-8 charset" do
|
|
|
|
expect(builder.build_args[:charset]).to eq("UTF-8")
|
|
|
|
end
|
|
|
|
|
2016-08-03 05:02:07 -04:00
|
|
|
it "ask politely not to receive automated responses" do
|
|
|
|
expect(header_args["X-Auto-Response-Suppress"]).to eq("All")
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "reply by email" do
|
2013-06-13 10:56:16 -04:00
|
|
|
context "without allow_reply_by_email" do
|
2013-06-18 15:54:02 -04:00
|
|
|
it "does not have a X-Discourse-Reply-Key" do
|
|
|
|
expect(header_args["X-Discourse-Reply-Key"]).to be_blank
|
2013-06-13 17:00:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a Reply-To header that's the same as From" do
|
|
|
|
expect(header_args["Reply-To"]).to eq(build_args[:from])
|
2013-06-13 10:56:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with allow_reply_by_email" do
|
|
|
|
let(:reply_by_email_builder) do
|
|
|
|
Email::MessageBuilder.new(to_address, allow_reply_by_email: true)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2013-06-13 10:56:16 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with the SiteSetting enabled" do
|
2013-06-13 10:56:16 -04:00
|
|
|
before do
|
2013-06-13 17:00:00 -04:00
|
|
|
SiteSetting.stubs(:reply_by_email_enabled?).returns(true)
|
|
|
|
SiteSetting.stubs(:reply_by_email_address).returns("r+%{reply_key}@reply.myforum.com")
|
2013-06-13 10:56:16 -04:00
|
|
|
end
|
|
|
|
|
2013-06-13 17:00:00 -04:00
|
|
|
it "returns a Reply-To header with the reply key" do
|
2018-07-18 04:28:44 -04:00
|
|
|
expect(reply_by_email_builder.header_args["Reply-To"]).to eq(
|
|
|
|
"\"#{SiteSetting.title}\" <r+%{reply_key}@reply.myforum.com>",
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args[allow_reply_header]).to eq(true)
|
2014-06-09 06:26:19 -04:00
|
|
|
end
|
2014-08-08 13:35:25 -04:00
|
|
|
|
|
|
|
it "cleans up the site title" do
|
2017-03-07 17:37:21 -05:00
|
|
|
SiteSetting.stubs(:title).returns(">>>Obnoxious Title: Deal, \"With\" It<<<")
|
2018-07-18 04:28:44 -04:00
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args["Reply-To"]).to eq(
|
|
|
|
"\"Obnoxious Title Deal With It\" <r+%{reply_key}@reply.myforum.com>",
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args[allow_reply_header]).to eq(true)
|
2014-08-08 13:35:25 -04:00
|
|
|
end
|
2014-06-09 06:26:19 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with the SiteSetting disabled" do
|
2014-06-09 06:26:19 -04:00
|
|
|
before { SiteSetting.stubs(:reply_by_email_enabled?).returns(false) }
|
|
|
|
|
|
|
|
it "returns a Reply-To header that's the same as From" do
|
2018-07-18 04:28:44 -04:00
|
|
|
expect(reply_by_email_builder.header_args["Reply-To"]).to eq(
|
|
|
|
reply_by_email_builder.build_args[:from],
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args[allow_reply_header]).to eq(nil)
|
2014-06-09 06:26:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with allow_reply_by_email" do
|
2018-07-18 04:28:44 -04:00
|
|
|
let(:reply_by_email_builder) do
|
|
|
|
Email::MessageBuilder.new(
|
|
|
|
to_address,
|
|
|
|
allow_reply_by_email: true,
|
|
|
|
private_reply: true,
|
|
|
|
from_alias: "Username",
|
|
|
|
)
|
|
|
|
end
|
2014-06-09 06:26:19 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with the SiteSetting enabled" do
|
2014-06-09 06:26:19 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.stubs(:reply_by_email_enabled?).returns(true)
|
|
|
|
|
2018-07-18 04:28:44 -04:00
|
|
|
SiteSetting.stubs(:reply_by_email_address).returns("r+%{reply_key}@reply.myforum.com")
|
2014-06-09 06:26:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a Reply-To header with the reply key" do
|
2018-07-18 04:28:44 -04:00
|
|
|
expect(reply_by_email_builder.header_args["Reply-To"]).to eq(
|
|
|
|
"\"Username\" <r+%{reply_key}@reply.myforum.com>",
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args[allow_reply_header]).to eq(true)
|
2013-06-13 17:00:00 -04:00
|
|
|
end
|
2013-06-13 10:56:16 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with the SiteSetting disabled" do
|
2013-06-13 17:00:00 -04:00
|
|
|
before { SiteSetting.stubs(:reply_by_email_enabled?).returns(false) }
|
2013-06-13 10:56:16 -04:00
|
|
|
|
2013-06-13 17:00:00 -04:00
|
|
|
it "returns a Reply-To header that's the same as From" do
|
2018-07-18 04:28:44 -04:00
|
|
|
expect(reply_by_email_builder.header_args["Reply-To"]).to eq(
|
|
|
|
reply_by_email_builder.build_args[:from],
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reply_by_email_builder.header_args[allow_reply_header]).to eq(nil)
|
2013-06-13 17:00:00 -04:00
|
|
|
end
|
2013-06-13 10:56:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "custom headers" do
|
2013-07-06 20:37:44 -04:00
|
|
|
let(:custom_headers_string) do
|
|
|
|
" Precedence : bulk | :: | No-colon | No-Value: | Multi-colon : : value : : | Auto-Submitted : auto-generated "
|
|
|
|
end
|
|
|
|
let(:custom_headers_result) do
|
|
|
|
{
|
|
|
|
"Precedence" => "bulk",
|
|
|
|
"Multi-colon" => ": value : :",
|
|
|
|
"Auto-Submitted" => "auto-generated",
|
|
|
|
}
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2013-07-06 20:37:44 -04:00
|
|
|
|
|
|
|
it "custom headers builder" do
|
|
|
|
expect(Email::MessageBuilder.custom_headers(custom_headers_string)).to eq(
|
|
|
|
custom_headers_result,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2013-07-09 12:19:10 -04:00
|
|
|
it "empty headers builder" do
|
|
|
|
expect(Email::MessageBuilder.custom_headers("")).to eq({})
|
|
|
|
end
|
|
|
|
|
|
|
|
it "null headers builder" do
|
|
|
|
expect(Email::MessageBuilder.custom_headers(nil)).to eq({})
|
|
|
|
end
|
2013-07-06 20:37:44 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "header args" do
|
2021-06-27 18:55:13 -04:00
|
|
|
let(:additional_opts) { {} }
|
2016-04-07 10:21:17 -04:00
|
|
|
let(:message_with_header_args) do
|
|
|
|
Email::MessageBuilder.new(
|
|
|
|
to_address,
|
2021-06-27 18:55:13 -04:00
|
|
|
{
|
2016-04-07 10:21:17 -04:00
|
|
|
body: "hello world",
|
|
|
|
topic_id: 1234,
|
|
|
|
post_id: 4567,
|
2023-01-05 19:03:02 -05:00
|
|
|
show_tags_in_subject: "foo bar baz",
|
|
|
|
show_category_in_subject: "random",
|
2021-06-27 18:55:13 -04:00
|
|
|
}.merge(additional_opts),
|
2016-04-07 10:21:17 -04:00
|
|
|
)
|
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
it "passes through a post_id" do
|
2013-06-18 15:54:02 -04:00
|
|
|
expect(message_with_header_args.header_args["X-Discourse-Post-Id"]).to eq("4567")
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "passes through a topic_id" do
|
2013-06-18 15:54:02 -04:00
|
|
|
expect(message_with_header_args.header_args["X-Discourse-Topic-Id"]).to eq("1234")
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
|
|
|
|
2021-06-27 18:55:13 -04:00
|
|
|
it "uses the default reply-to header" do
|
|
|
|
expect(message_with_header_args.header_args["Reply-To"]).to eq(
|
|
|
|
"\"Discourse\" <#{SiteSetting.notification_email}>",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-01-05 19:03:02 -05:00
|
|
|
it "passes through the topic tags" do
|
|
|
|
expect(message_with_header_args.header_args["X-Discourse-Tags"]).to eq("foo bar baz")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes through the topic category" do
|
|
|
|
expect(message_with_header_args.header_args["X-Discourse-Category"]).to eq("random")
|
|
|
|
end
|
|
|
|
|
2021-06-27 18:55:13 -04:00
|
|
|
context "when allow_reply_by_email is enabled " do
|
|
|
|
let(:additional_opts) { { allow_reply_by_email: true } }
|
|
|
|
|
|
|
|
it "uses the reply by email address if that is enabled" do
|
|
|
|
SiteSetting.manual_polling_enabled = true
|
|
|
|
SiteSetting.reply_by_email_address = "test+%{reply_key}@test.com"
|
|
|
|
SiteSetting.reply_by_email_enabled = true
|
|
|
|
expect(message_with_header_args.header_args["Reply-To"]).to eq(
|
|
|
|
"\"Discourse\" <test+%{reply_key}@test.com>",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when allow_reply_by_email is enabled and use_from_address_for_reply_to is enabled but no from address is specified" do
|
|
|
|
let(:additional_opts) { { allow_reply_by_email: true, use_from_address_for_reply_to: true } }
|
|
|
|
|
|
|
|
it "uses the notification_email address, the default reply-to header" do
|
|
|
|
SiteSetting.manual_polling_enabled = true
|
|
|
|
SiteSetting.reply_by_email_address = "test+%{reply_key}@test.com"
|
|
|
|
SiteSetting.reply_by_email_enabled = true
|
|
|
|
expect(message_with_header_args.header_args["Reply-To"]).to eq(
|
|
|
|
"\"Discourse\" <#{SiteSetting.notification_email}>",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when allow_reply_by_email is enabled and use_from_address_for_reply_to is enabled and from is specified" do
|
|
|
|
let(:additional_opts) do
|
|
|
|
{ allow_reply_by_email: true, use_from_address_for_reply_to: true, from: "team@test.com" }
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2021-06-27 18:55:13 -04:00
|
|
|
|
|
|
|
it "removes the reply-to header because it is identical to the from header" do
|
|
|
|
SiteSetting.manual_polling_enabled = true
|
|
|
|
SiteSetting.reply_by_email_address = "test+%{reply_key}@test.com"
|
|
|
|
SiteSetting.reply_by_email_enabled = true
|
|
|
|
expect(message_with_header_args.header_args["Reply-To"]).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "unsubscribe link" do
|
2013-06-10 16:46:08 -04:00
|
|
|
context "with add_unsubscribe_link false" do
|
|
|
|
it "has no unsubscribe header by default" do
|
|
|
|
expect(builder.header_args["List-Unsubscribe"]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't have the user preferences url in the body" do
|
|
|
|
expect(builder.body).not_to match(builder.template_args[:user_preferences_url])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with add_unsubscribe_link true" do
|
|
|
|
let(:message_with_unsubscribe) do
|
|
|
|
Email::MessageBuilder.new(
|
|
|
|
to_address,
|
|
|
|
body: "hello world",
|
2015-08-12 17:00:16 -04:00
|
|
|
add_unsubscribe_link: true,
|
2016-06-03 09:48:54 -04:00
|
|
|
url: "/t/1234",
|
2015-08-12 17:00:16 -04:00
|
|
|
unsubscribe_url: "/t/1234/unsubscribe",
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
|
|
|
|
it "has an List-Unsubscribe header" do
|
|
|
|
expect(message_with_unsubscribe.header_args["List-Unsubscribe"]).to be_present
|
|
|
|
end
|
|
|
|
|
2016-06-16 21:27:52 -04:00
|
|
|
it "has the unsubscribe url in the body" do
|
|
|
|
expect(message_with_unsubscribe.body).to match("/t/1234/unsubscribe")
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
2016-06-03 09:48:54 -04:00
|
|
|
it "does not add unsubscribe via email link without site setting set" do
|
|
|
|
expect(message_with_unsubscribe.body).to_not match(
|
|
|
|
/mailto:reply@#{Discourse.current_hostname}\?subject=unsubscribe/,
|
|
|
|
)
|
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "template_args" do
|
2013-06-10 16:46:08 -04:00
|
|
|
let(:template_args) { builder.template_args }
|
|
|
|
|
2017-06-21 11:22:10 -04:00
|
|
|
it "has site title as email_prefix when `SiteSetting.email_prefix` is not present" do
|
2017-03-21 09:11:15 -04:00
|
|
|
expect(template_args[:email_prefix]).to eq(SiteSetting.title)
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
2017-06-21 11:22:10 -04:00
|
|
|
it "has email prefix as email_prefix when `SiteSetting.email_prefix` is present" do
|
2014-03-26 18:06:00 -04:00
|
|
|
SiteSetting.email_prefix = "some email prefix"
|
2017-03-21 09:11:15 -04:00
|
|
|
expect(template_args[:email_prefix]).to eq(SiteSetting.email_prefix)
|
2014-03-26 18:06:00 -04:00
|
|
|
end
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
it "has the base url" do
|
|
|
|
expect(template_args[:base_url]).to eq(Discourse.base_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the user_preferences_url" do
|
2014-04-29 21:18:23 -04:00
|
|
|
expect(template_args[:user_preferences_url]).to eq("#{Discourse.base_url}/my/preferences")
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "email prefix in subject" do
|
2017-06-21 11:22:10 -04:00
|
|
|
context "when use_site_subject is true" do
|
|
|
|
let(:message_with_email_prefix) do
|
|
|
|
Email::MessageBuilder.new(to_address, body: "hello world", use_site_subject: true)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2017-06-21 11:22:10 -04:00
|
|
|
|
|
|
|
it "when email_prefix is set it should be present in subject" do
|
|
|
|
SiteSetting.email_prefix = "some email prefix"
|
|
|
|
expect(message_with_email_prefix.subject).to match(SiteSetting.email_prefix)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "subject_template" do
|
2013-06-10 16:46:08 -04:00
|
|
|
let(:templated_builder) { Email::MessageBuilder.new(to_address, template: "mystery") }
|
|
|
|
let(:rendered_template) { "rendered template" }
|
|
|
|
|
|
|
|
it "has the body rendered from a template" do
|
|
|
|
I18n
|
|
|
|
.expects(:t)
|
|
|
|
.with("mystery.text_body_template", templated_builder.template_args)
|
|
|
|
.returns(rendered_template)
|
|
|
|
expect(templated_builder.body).to eq(rendered_template)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has the subject rendered from a template" do
|
|
|
|
I18n
|
|
|
|
.expects(:t)
|
|
|
|
.with("mystery.subject_template", templated_builder.template_args)
|
|
|
|
.returns(rendered_template)
|
|
|
|
expect(templated_builder.subject).to eq(rendered_template)
|
|
|
|
end
|
|
|
|
|
2020-01-29 14:48:55 -05:00
|
|
|
context "when use_site_subject is true" do
|
2020-11-02 23:00:11 -05:00
|
|
|
let(:templated_builder) do
|
|
|
|
Email::MessageBuilder.new(
|
|
|
|
to_address,
|
|
|
|
template: "user_notifications.user_replied",
|
|
|
|
use_site_subject: true,
|
|
|
|
topic_title: "Topic Title",
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2020-01-29 14:48:55 -05:00
|
|
|
|
|
|
|
it "can use subject override" do
|
2020-11-02 23:00:11 -05:00
|
|
|
override =
|
|
|
|
TranslationOverride.upsert!(
|
|
|
|
I18n.locale,
|
|
|
|
"user_notifications.user_replied.subject_template",
|
|
|
|
"my customized subject",
|
2020-01-29 14:48:55 -05:00
|
|
|
)
|
2020-11-02 23:00:11 -05:00
|
|
|
override.save!
|
2020-01-29 14:48:55 -05:00
|
|
|
expect(templated_builder.subject).to eq(override.value)
|
|
|
|
end
|
2020-11-02 23:00:11 -05:00
|
|
|
|
|
|
|
it "can use interpolation arguments in the override" do
|
|
|
|
SiteSetting.email_prefix = "some email prefix"
|
|
|
|
override =
|
|
|
|
TranslationOverride.upsert!(
|
|
|
|
I18n.locale,
|
|
|
|
"user_notifications.user_replied.subject_template",
|
|
|
|
"[%{site_name}] %{topic_title} my customized subject",
|
|
|
|
).save!
|
|
|
|
expect(templated_builder.subject).to match("some email prefix")
|
|
|
|
expect(templated_builder.subject).to match("customized subject")
|
|
|
|
end
|
2020-01-29 14:48:55 -05:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "from field" do
|
2013-06-10 16:46:08 -04:00
|
|
|
it "has the default from" do
|
2017-02-27 14:22:56 -05:00
|
|
|
SiteSetting.title = ""
|
2013-06-10 16:46:08 -04:00
|
|
|
expect(build_args[:from]).to eq(SiteSetting.notification_email)
|
|
|
|
end
|
|
|
|
|
2017-02-27 14:22:56 -05:00
|
|
|
it "title setting will be added if present" do
|
|
|
|
SiteSetting.title = "Dog Talk"
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(build_args[:from]).to eq("\"Dog Talk\" <#{SiteSetting.notification_email}>")
|
2017-02-27 14:22:56 -05:00
|
|
|
end
|
|
|
|
|
2013-06-10 16:46:08 -04:00
|
|
|
let(:finn_email) { "finn@adventuretime.ooo" }
|
|
|
|
let(:custom_from) { Email::MessageBuilder.new(to_address, from: finn_email).build_args }
|
|
|
|
|
|
|
|
it "allows us to override from" do
|
|
|
|
expect(custom_from[:from]).to eq(finn_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:aliased_from) { Email::MessageBuilder.new(to_address, from_alias: "Finn the Dog") }
|
|
|
|
|
|
|
|
it "allows us to alias the from address" do
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(aliased_from.build_args[:from]).to eq(
|
|
|
|
"\"Finn the Dog\" <#{SiteSetting.notification_email}>",
|
|
|
|
)
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:custom_aliased_from) do
|
|
|
|
Email::MessageBuilder.new(to_address, from_alias: "Finn the Dog", from: finn_email)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
|
|
|
|
it "allows us to alias a custom from address" do
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(custom_aliased_from.build_args[:from]).to eq("\"Finn the Dog\" <#{finn_email}>")
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
|
2014-07-22 15:52:14 -04:00
|
|
|
it "email_site_title will be added if it's set" do
|
2017-02-27 14:22:56 -05:00
|
|
|
SiteSetting.email_site_title = "The Forum"
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(build_args[:from]).to eq("\"The Forum\" <#{SiteSetting.notification_email}>")
|
2017-02-27 14:22:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "email_site_title overrides title" do
|
|
|
|
SiteSetting.title = "Dog Talk"
|
|
|
|
SiteSetting.email_site_title = "The Forum"
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(build_args[:from]).to eq("\"The Forum\" <#{SiteSetting.notification_email}>")
|
2014-07-22 15:52:14 -04:00
|
|
|
end
|
|
|
|
|
2014-08-08 13:35:25 -04:00
|
|
|
it "cleans up aliases in the from_alias arg" do
|
2014-11-24 09:16:15 -05:00
|
|
|
builder =
|
|
|
|
Email::MessageBuilder.new(to_address, from_alias: "Finn: the Dog, <3", from: finn_email)
|
2017-03-07 17:37:21 -05:00
|
|
|
expect(builder.build_args[:from]).to eq("\"Finn the Dog 3\" <#{finn_email}>")
|
2014-08-08 13:35:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "cleans up the email_site_title" do
|
2017-03-07 17:37:21 -05:00
|
|
|
SiteSetting.stubs(:email_site_title).returns("::>>>Best \"Forum\", EU: Award Winning<<<")
|
|
|
|
expect(build_args[:from]).to eq(
|
|
|
|
"\"Best Forum EU Award Winning\" <#{SiteSetting.notification_email}>",
|
|
|
|
)
|
2014-08-08 13:35:25 -04:00
|
|
|
end
|
2013-06-10 16:46:08 -04:00
|
|
|
end
|
|
|
|
end
|