diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 535dec5387a..a8c4234f6bd 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -9,6 +9,6 @@ class SubscriptionMailer < ActionMailer::Base template: "unsubscribe_mailer", site_title: SiteSetting.title, site_domain_name: Discourse.current_hostname, - confirm_unsubscribe_link: "#{Discourse.base_url}/unsubscribe/#{unsubscribe_key}" + confirm_unsubscribe_link: email_unsubscribe_url(unsubscribe_key, host: Discourse.base_url) end end diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb new file mode 100644 index 00000000000..696231d4ff9 --- /dev/null +++ b/spec/mailers/subscription_mailer_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe SubscriptionMailer do + fab!(:user) { Fabricate(:user) } + + subject { SubscriptionMailer.confirm_unsubscribe(user) } + + it "contains the right URL" do + expect(subject.body).to include("#{Discourse.base_url}/email/unsubscribe/#{UnsubscribeKey.last.key}") + end +end