A platform for community discussion. Free, open, simple.
FIX: Correctly use invite to topic email templates (#12411)
Dan Ungureanufb19ee9eee15
diff --git a/app/jobs/regular/invite_email.rb b/app/jobs/regular/invite_email.rbindex b8278ff40a7..5d0b0e68df6 100644--- a/app/jobs/regular/invite_email.rb+++ b/app/jobs/regular/invite_email.rb@@ -11,7 +11,7 @@ module Jobsinvite = Invite.find_by(id: args[:invite_id])return unless invite.present?- message = InviteMailer.send_invite(invite)+ message = InviteMailer.send_invite(invite, invite_to_topic: args[:invite_to_topic])Email::Sender.new(message, :invite).sendif invite.emailed_status != Invite.emailed_status_types[:not_required]diff --git a/app/mailers/invite_mailer.rb b/app/mailers/invite_mailer.rbindex 050f6e8a7ce..2f751e30f94 100644--- a/app/mailers/invite_mailer.rb+++ b/app/mailers/invite_mailer.rb@@ -5,7 +5,7 @@ class InviteMailer < ActionMailer::Baselayout 'email_template'- def send_invite(invite)+ def send_invite(invite, invite_to_topic: false)# Find the first topic they were invited tofirst_topic = invite.topics.order(:created_at).first@@ -19,7 +19,7 @@ class InviteMailer < ActionMailer::BaseActionView::Base.full_sanitizer.sanitize(invite.custom_message.gsub(/\n+/, " ").strip) : nil# If they were invited to a topic- if first_topic.present?+ if invite_to_topic && first_topic.present?# get topic excerpttopic_excerpt = ""if first_topic.excerptdiff --git a/app/models/invite.rb b/app/models/invite.rbindex ed5638b2186..f376db0e653 100644--- a/app/models/invite.rb+++ b/app/models/invite.rb@@ -156,7 +156,7 @@ class Invite < ActiveRecord::Baseif emailed_status == emailed_status_types[:pending]invite.update_column(:emailed_status, emailed_status_types[:sending])- Jobs.enqueue(:invite_email, invite_id: invite.id)+ Jobs.enqueue(:invite_email, invite_id: invite.id, invite_to_topic: opts[:invite_to_topic])endinvite.reloaddiff --git a/app/models/topic.rb b/app/models/topic.rbindex dd9d2871d14..ff605b7962c 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -1059,7 +1059,8 @@ class Topic < ActiveRecord::Baseemail: username_or_email,topic: self,group_ids: group_ids,- custom_message: custom_message+ custom_message: custom_message,+ invite_to_topic: true)endenddiff --git a/spec/jobs/invite_email_spec.rb b/spec/jobs/invite_email_spec.rbindex d998b85baed..d72de95818f 100644--- a/spec/jobs/invite_email_spec.rb+++ b/spec/jobs/invite_email_spec.rb@@ -17,7 +17,7 @@ describe Jobs::InviteEmail doit 'delegates to the test mailer' doEmail::Sender.any_instance.expects(:send)- InviteMailer.expects(:send_invite).with(invite, nil).returns(mailer)+ InviteMailer.expects(:send_invite).with(invite, anything).returns(mailer)Jobs::InviteEmail.new.execute(invite_id: invite.id)enddiff --git a/spec/mailers/invite_mailer_spec.rb b/spec/mailers/invite_mailer_spec.rbindex b9dcbcfebe3..2e7c2041b6d 100644--- a/spec/mailers/invite_mailer_spec.rb+++ b/spec/mailers/invite_mailer_spec.rb@@ -90,7 +90,7 @@ describe InviteMailer doInvite.find_by(invited_by_id: topic.user.id)end- let(:invite_mail) { InviteMailer.send_invite(invite) }+ let(:invite_mail) { InviteMailer.send_invite(invite, invite_to_topic: true) }it 'renders the invitee email' doexpect(invite_mail.to).to eql(['[email protected]'])diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 6f45a32708f..13447a09ad4 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -894,12 +894,14 @@ describe Topic dobefore { user.update!(trust_level: TrustLevel[2]) }it 'should create an invite' do+ Jobs.run_immediately!expect(topic.invite(user, '[email protected]')).to eq(true)invite = Invite.lastexpect(invite.email).to eq('[email protected]')expect(invite.invited_by).to eq(user)+ expect(ActionMailer::Base.deliveries.last.body).to include(topic.title)endendend