diff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rb index ac3463a5d95..7632a244843 100644 --- a/lib/email/message_builder.rb +++ b/lib/email/message_builder.rb @@ -60,8 +60,7 @@ module Email def subject if @opts[:use_site_subject] subject = String.new(SiteSetting.email_subject) - subject.gsub!("%{site_name}", @template_args[:site_name]) - subject.gsub!("%{email_prefix}", @template_args[:email_prefix]) + subject.gsub!("%{site_name}", @template_args[:email_prefix]) subject.gsub!("%{optional_re}", @opts[:add_re_to_subject] ? I18n.t('subject_re', @template_args) : '') subject.gsub!("%{optional_pm}", @opts[:private_reply] ? I18n.t('subject_pm', @template_args) : '') subject.gsub!("%{optional_cat}", @template_args[:show_category_in_subject] ? "[#{@template_args[:show_category_in_subject]}] " : '') diff --git a/spec/components/email/message_builder_spec.rb b/spec/components/email/message_builder_spec.rb index 5cf6d4877ac..3ad30558ed0 100644 --- a/spec/components/email/message_builder_spec.rb +++ b/spec/components/email/message_builder_spec.rb @@ -199,11 +199,11 @@ describe Email::MessageBuilder do context "template_args" do let(:template_args) { builder.template_args } - it "has the email prefix as the site title when `SiteSetting.email_prefix` is not set" do + it "has site title as email_prefix when `SiteSetting.email_prefix` is not present" do expect(template_args[:email_prefix]).to eq(SiteSetting.title) end - it "has the email prefix as SiteSetting.email_prefix when it is set" do + it "has email prefix as email_prefix when `SiteSetting.email_prefix` is present" do SiteSetting.email_prefix = 'some email prefix' expect(template_args[:email_prefix]).to eq(SiteSetting.email_prefix) end @@ -217,6 +217,19 @@ describe Email::MessageBuilder do end end + context "email prefix in subject" do + context "when use_site_subject is true" do + let(:message_with_email_prefix) { Email::MessageBuilder.new(to_address, + body: 'hello world', + use_site_subject: true) } + + 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 + context "subject_template" do let(:templated_builder) { Email::MessageBuilder.new(to_address, template: 'mystery') }