Merge pull request #2521 from techAPJ/patch-3

FEATURE: include topic context in topic invite
This commit is contained in:
Neil Lalonde 2014-07-09 13:24:44 -04:00
commit 88d1e25354
4 changed files with 73 additions and 10 deletions

View File

@ -9,11 +9,24 @@ class InviteMailer < ActionMailer::Base
# If they were invited to a topic # If they were invited to a topic
if first_topic.present? if first_topic.present?
# get invitee name (based on site setting)
invitee_name = invite.invited_by.username
if (SiteSetting.enable_names)
invitee_name = "#{invite.invited_by.name} (#{invite.invited_by.username})"
end
# get topic excerpt
topic_excerpt = ""
if first_topic.excerpt
topic_excerpt = first_topic.excerpt.gsub("\n", " ")
end
build_email(invite.email, build_email(invite.email,
template: 'invite_mailer', template: 'invite_mailer',
invitee_name: invite.invited_by.username, invitee_name: invitee_name,
invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}", invite_link: "#{Discourse.base_url}/invites/#{invite.invite_key}",
topic_title: first_topic.try(:title), topic_title: first_topic.try(:title),
topic_excerpt: topic_excerpt,
site_description: SiteSetting.site_description, site_description: SiteSetting.site_description,
site_title: SiteSetting.title) site_title: SiteSetting.title)
else else

View File

@ -1051,7 +1051,9 @@ en:
text_body_template: | text_body_template: |
%{invitee_name} invited you to a discussion %{invitee_name} invited you to a discussion
> %{topic_title} > **%{topic_title}**
>
> %{topic_excerpt}
at at

View File

@ -3,14 +3,62 @@ require "spec_helper"
describe InviteMailer do describe InviteMailer do
describe "send_invite" do describe "send_invite" do
let(:invite) { Fabricate(:invite) }
subject { InviteMailer.send_invite(invite) }
its(:to) { should == [invite.email] } context "invite to site" do
its(:subject) { should be_present } let(:invite) { Fabricate(:invite) }
its(:body) { should be_present } let(:invite_mail) { InviteMailer.send_invite(invite) }
its(:from) { should == [SiteSetting.notification_email] }
it 'renders the invitee email' do
expect(invite_mail.to).to eql([invite.email])
end
it 'renders the subject' do
expect(invite_mail.subject).to be_present
end
it 'renders the body' do
expect(invite_mail.body).to be_present
end
it 'renders the inviter email' do
expect(invite_mail.from).to eql([SiteSetting.notification_email])
end
it 'renders invite link' do
expect(invite_mail.body.encoded).to match("#{Discourse.base_url}/invites/#{invite.invite_key}")
end
end
context "invite to topic" do
let(:topic) { Fabricate(:topic, excerpt: "Topic invite support is now available in Discourse!") }
let(:invite) { topic.invite(topic.user, 'name@example.com') }
let(:invite_mail) { InviteMailer.send_invite(invite) }
it 'renders the invitee email' do
expect(invite_mail.to).to eql(['name@example.com'])
end
it 'renders the subject' do
expect(invite_mail.subject).to be_present
end
it 'renders the body' do
expect(invite_mail.body).to be_present
end
it 'renders the inviter email' do
expect(invite_mail.from).to eql([SiteSetting.notification_email])
end
it 'renders invite link' do
expect(invite_mail.body.encoded).to match("#{Discourse.base_url}/invites/#{invite.invite_key}")
end
it 'renders topic title' do
expect(invite_mail.body.encoded).to match(topic.title)
end
end
end end
end end