2015-10-11 04:41:23 -05:00
|
|
|
require "rails_helper"
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
describe InviteMailer do
|
2013-02-25 10:42:20 -06:00
|
|
|
|
2013-02-05 13:16:51 -06:00
|
|
|
describe "send_invite" do
|
|
|
|
|
2014-07-08 12:03:11 -05:00
|
|
|
context "invite to site" do
|
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
context "default invite message" do
|
2017-06-30 05:39:37 -05:00
|
|
|
let(:invite) { Fabricate(:invite) }
|
2016-06-05 12:22:46 -05:00
|
|
|
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
it 'renders the invitee email' do
|
|
|
|
expect(invite_mail.to).to eql([invite.email])
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
it 'renders the subject' do
|
|
|
|
expect(invite_mail.subject).to be_present
|
|
|
|
end
|
2014-07-10 00:27:40 -05:00
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
it 'renders site domain name in subject' do
|
|
|
|
expect(invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the body' do
|
|
|
|
expect(invite_mail.body).to be_present
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
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
|
2014-07-08 12:03:11 -05:00
|
|
|
end
|
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
context "custom invite message" do
|
2017-06-30 05:39:37 -05:00
|
|
|
let(:invite) { Fabricate(:invite, custom_message: "Hey, you should join this forum!") }
|
2016-06-05 12:22:46 -05:00
|
|
|
|
|
|
|
context "custom message includes invite link" do
|
2017-06-30 05:39:37 -05:00
|
|
|
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
|
2016-06-05 12:22:46 -05:00
|
|
|
|
|
|
|
it 'renders the invitee email' do
|
|
|
|
expect(custom_invite_mail.to).to eql([invite.email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the subject' do
|
|
|
|
expect(custom_invite_mail.subject).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders site domain name in subject' do
|
|
|
|
expect(custom_invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
|
|
|
|
2016-06-08 07:34:25 -05:00
|
|
|
it 'renders the body' do
|
|
|
|
expect(custom_invite_mail.body).to be_present
|
2016-06-05 12:22:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders custom_message' do
|
2016-06-08 07:34:25 -05:00
|
|
|
expect(custom_invite_mail.body.encoded).to match("Hey, you should join this forum!")
|
2016-06-05 12:22:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders the inviter email' do
|
|
|
|
expect(custom_invite_mail.from).to eql([SiteSetting.notification_email])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders invite link' do
|
2016-06-08 07:34:25 -05:00
|
|
|
expect(custom_invite_mail.body.encoded).to match("#{Discourse.base_url}/invites/#{invite.invite_key}")
|
2016-06-05 12:22:46 -05:00
|
|
|
end
|
2017-04-24 14:26:06 -05:00
|
|
|
|
2016-06-05 12:22:46 -05:00
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "invite to topic" do
|
2017-02-02 11:38:25 -06:00
|
|
|
let(:trust_level_2) { build(:user, trust_level: 2) }
|
|
|
|
let(:topic) { Fabricate(:topic, excerpt: "Topic invite support is now available in Discourse!", user: trust_level_2) }
|
2013-02-05 13:16:51 -06:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
context "default invite message" do
|
2017-06-30 05:39:37 -05:00
|
|
|
let(:invite) { topic.invite(topic.user, 'name@example.com') }
|
2016-06-07 12:24:45 -05:00
|
|
|
let(:invite_mail) { InviteMailer.send_invite(invite) }
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
it 'renders the invitee email' do
|
|
|
|
expect(invite_mail.to).to eql(['name@example.com'])
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
it 'renders the subject' do
|
|
|
|
expect(invite_mail.subject).to be_present
|
|
|
|
end
|
2014-07-09 23:33:09 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
it 'renders topic title in subject' do
|
|
|
|
expect(invite_mail.subject).to match(topic.title)
|
|
|
|
end
|
2014-07-09 23:33:09 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
it 'renders site domain name in subject' do
|
|
|
|
expect(invite_mail.subject).to match(Discourse.current_hostname)
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
it 'renders the body' do
|
|
|
|
expect(invite_mail.body).to be_present
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
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
|
2017-04-24 14:26:06 -05:00
|
|
|
|
|
|
|
it "respects the private_email setting" do
|
|
|
|
SiteSetting.private_email = true
|
|
|
|
|
|
|
|
message = invite_mail
|
|
|
|
expect(message.body.to_s).not_to include(topic.title)
|
|
|
|
expect(message.body.to_s).not_to include(topic.slug)
|
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
end
|
|
|
|
|
2016-06-07 12:24:45 -05:00
|
|
|
context "custom invite message" do
|
2017-06-30 05:39:37 -05:00
|
|
|
let(:invite) { topic.invite(topic.user, 'name@example.com', nil, "Hey, I thought you might enjoy this topic!") }
|
|
|
|
let(:custom_invite_mail) { InviteMailer.send_invite(invite) }
|
2016-06-07 12:24:45 -05:00
|
|
|
|
|
|
|
it 'renders custom_message' do
|
2016-06-08 07:34:25 -05:00
|
|
|
expect(custom_invite_mail.body.encoded).to match("Hey, I thought you might enjoy this topic!")
|
2016-06-07 12:24:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders invite link' do
|
2016-06-08 07:34:25 -05:00
|
|
|
expect(custom_invite_mail.body.encoded).to match("#{Discourse.base_url}/invites/#{invite.invite_key}")
|
2016-06-07 12:24:45 -05:00
|
|
|
end
|
2014-07-08 12:03:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
end
|