2019-10-14 08:54:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-10-20 08:47:26 +00:00
|
|
|
require 'rails_helper'
|
2019-10-14 08:54:58 +00:00
|
|
|
|
|
|
|
RSpec.describe 'Confirmation Instructions', type: :mailer do
|
|
|
|
describe :notify do
|
2020-03-07 06:48:16 +00:00
|
|
|
let(:account) { create(:account) }
|
|
|
|
let(:confirmable_user) { build(:user, inviter: inviter_val, account: account) }
|
2019-10-14 08:54:58 +00:00
|
|
|
let(:inviter_val) { nil }
|
2019-12-24 21:33:02 +00:00
|
|
|
let(:mail) { Devise::Mailer.confirmation_instructions(confirmable_user, nil, {}) }
|
2019-10-14 08:54:58 +00:00
|
|
|
|
|
|
|
it 'has the correct header data' do
|
|
|
|
expect(mail.reply_to).to contain_exactly('accounts@chatwoot.com')
|
|
|
|
expect(mail.to).to contain_exactly(confirmable_user.email)
|
|
|
|
expect(mail.subject).to eq('Confirmation Instructions')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the user\'s name' do
|
2019-12-03 17:24:08 +00:00
|
|
|
expect(mail.body).to match("Welcome, #{CGI.escapeHTML(confirmable_user.name)}!")
|
2019-10-14 08:54:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not refer to the inviter and their account' do
|
|
|
|
expect(mail.body).to_not match('has invited you to try out Chatwoot!')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is an inviter' do
|
2020-03-07 06:48:16 +00:00
|
|
|
let(:inviter_val) { create(:user, :administrator, skip_confirmation: true, account: account) }
|
2019-10-14 08:54:58 +00:00
|
|
|
|
|
|
|
it 'refers to the inviter and their account' do
|
2020-05-26 17:08:48 +00:00
|
|
|
Current.account = account
|
2019-10-14 08:54:58 +00:00
|
|
|
expect(mail.body).to match(
|
2020-04-17 10:18:23 +00:00
|
|
|
"#{CGI.escapeHTML(inviter_val.name)}, with #{CGI.escapeHTML(inviter_val.account.name)}, has invited you to try out Chatwoot!"
|
2019-10-14 08:54:58 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|