2020-07-13 23:09:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'email_spec'
|
|
|
|
|
|
|
|
RSpec.describe DeviseMailer do
|
2020-09-04 05:08:38 -04:00
|
|
|
include EmailSpec::Matchers
|
|
|
|
include_context 'gitlab email notification'
|
|
|
|
|
2020-07-13 23:09:24 -04:00
|
|
|
describe "#confirmation_instructions" do
|
|
|
|
subject { described_class.confirmation_instructions(user, 'faketoken', {}) }
|
|
|
|
|
2020-07-14 14:09:55 -04:00
|
|
|
context "when confirming a new account" do
|
|
|
|
let(:user) { build(:user, created_at: 1.minute.ago, unconfirmed_email: nil) }
|
|
|
|
|
|
|
|
it "shows the expected text" do
|
|
|
|
expect(subject.body.encoded).to have_text "Welcome"
|
|
|
|
expect(subject.body.encoded).not_to have_text user.email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-13 23:09:24 -04:00
|
|
|
context "when confirming the unconfirmed_email" do
|
|
|
|
let(:user) { build(:user, unconfirmed_email: 'jdoe@example.com') }
|
|
|
|
|
2020-07-14 14:09:55 -04:00
|
|
|
it "shows the expected text" do
|
|
|
|
expect(subject.body.encoded).not_to have_text "Welcome"
|
2020-07-13 23:09:24 -04:00
|
|
|
expect(subject.body.encoded).to have_text user.unconfirmed_email
|
|
|
|
expect(subject.body.encoded).not_to have_text user.email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when re-confirming the primary email after a security issue" do
|
|
|
|
let(:user) { build(:user, created_at: 10.days.ago, unconfirmed_email: nil) }
|
|
|
|
|
2020-07-14 14:09:55 -04:00
|
|
|
it "shows the expected text" do
|
|
|
|
expect(subject.body.encoded).not_to have_text "Welcome"
|
2020-07-13 23:09:24 -04:00
|
|
|
expect(subject.body.encoded).to have_text user.email
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-09-04 05:08:38 -04:00
|
|
|
|
|
|
|
describe '#password_change_by_admin' do
|
|
|
|
subject { described_class.password_change_by_admin(user) }
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
it_behaves_like 'an email sent from GitLab'
|
|
|
|
it_behaves_like 'it should not have Gmail Actions links'
|
|
|
|
it_behaves_like 'a user cannot unsubscribe through footer link'
|
|
|
|
|
|
|
|
it 'is sent to the user' do
|
|
|
|
is_expected.to deliver_to user.email
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject' do
|
|
|
|
is_expected.to have_subject /^Password changed by administrator$/i
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the correct content' do
|
|
|
|
is_expected.to have_body_text /An administrator changed the password for your GitLab account/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes a link to GitLab' do
|
|
|
|
is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/
|
|
|
|
end
|
|
|
|
end
|
2020-11-12 16:09:19 -05:00
|
|
|
|
|
|
|
describe '#user_admin_approval' do
|
|
|
|
subject { described_class.user_admin_approval(user) }
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
it_behaves_like 'an email sent from GitLab'
|
|
|
|
it_behaves_like 'it should not have Gmail Actions links'
|
|
|
|
it_behaves_like 'a user cannot unsubscribe through footer link'
|
|
|
|
|
|
|
|
it 'is sent to the user' do
|
|
|
|
is_expected.to deliver_to user.email
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct subject' do
|
|
|
|
is_expected.to have_subject 'Welcome to GitLab!'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'greets the user' do
|
|
|
|
is_expected.to have_body_text /Hi #{user.name}!/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the correct content' do
|
|
|
|
is_expected.to have_body_text /Your GitLab account request has been approved!/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes a link to GitLab' do
|
|
|
|
is_expected.to have_link(Gitlab.config.gitlab.url)
|
|
|
|
end
|
|
|
|
end
|
2020-07-13 23:09:24 -04:00
|
|
|
end
|