summaryrefslogtreecommitdiff
path: root/spec/mailers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 11:18:50 +0000
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/mailers
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
downloadgitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/emails/profile_spec.rb32
-rw-r--r--spec/mailers/notify_spec.rb61
2 files changed, 81 insertions, 12 deletions
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index f84bf43b9c4..cbf42da2085 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -160,38 +160,48 @@ describe Emails::Profile do
describe 'user unknown sign in email' do
let_it_be(:user) { create(:user) }
let_it_be(:ip) { '169.0.0.1' }
+ let_it_be(:current_time) { Time.current }
+ let_it_be(:email) { Notify.unknown_sign_in_email(user, ip, current_time) }
- subject { Notify.unknown_sign_in_email(user, ip) }
+ subject { email }
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
- expect(subject).to deliver_to user.email
+ is_expected.to deliver_to user.email
end
it 'has the correct subject' do
- expect(subject).to have_subject /^Unknown sign-in from new location$/
+ is_expected.to have_subject "#{Gitlab.config.gitlab.host} sign-in from new location"
+ end
+
+ it 'mentions the new sign-in IP' do
+ is_expected.to have_body_text ip
end
- it 'mentions the unknown sign-in IP' do
- expect(subject).to have_body_text /A sign-in to your account has been made from the following IP address: #{ip}./
+ it 'mentioned the time' do
+ is_expected.to have_body_text current_time.strftime('%Y-%m-%d %l:%M:%S %p %Z')
end
- it 'includes a link to the change password page' do
- expect(subject).to have_body_text /#{edit_profile_password_path}/
+ it 'includes a link to the change password documentation' do
+ is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/#changing-your-password'
end
it 'mentions two factor authentication when two factor is not enabled' do
- expect(subject).to have_body_text /two-factor authentication/
+ is_expected.to have_body_text 'two-factor authentication'
+ end
+
+ it 'includes a link to two-factor authentication documentation' do
+ is_expected.to have_body_text 'https://docs.gitlab.com/ee/user/profile/account/two_factor_authentication.html'
end
context 'when two factor authentication is enabled' do
- it 'does not mention two factor authentication' do
- two_factor_user = create(:user, :two_factor)
+ let(:user) { create(:user, :two_factor) }
- expect( Notify.unknown_sign_in_email(two_factor_user, ip) )
+ it 'does not mention two factor authentication' do
+ expect( Notify.unknown_sign_in_email(user, ip, current_time) )
.not_to have_body_text /two-factor authentication/
end
end
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 3c66902bb2e..8b99cc41a53 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -104,7 +104,11 @@ describe Notify do
it 'contains a link to issue author' do
is_expected.to have_body_text(issue.author_name)
- is_expected.to have_body_text 'created an issue:'
+ is_expected.to have_body_text 'created an issue'
+ end
+
+ it 'contains a link to the issue' do
+ is_expected.to have_body_text(issue.to_reference(full: false))
end
end
@@ -1722,4 +1726,59 @@ describe Notify do
is_expected.to have_body_text target_url
end
end
+
+ describe 'merge request reviews' do
+ let!(:review) { create(:review, project: project, merge_request: merge_request) }
+ let!(:notes) { create_list(:note, 3, review: review, project: project, author: review.author, noteable: merge_request) }
+
+ subject { described_class.new_review_email(recipient.id, review.id) }
+
+ it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
+ let(:model) { review.merge_request }
+ end
+
+ it_behaves_like 'it should show Gmail Actions View Merge request link'
+ it_behaves_like 'an unsubscribeable thread'
+
+ it 'is sent to the given recipient as the author' do
+ sender = subject.header[:from].addrs[0]
+
+ aggregate_failures do
+ expect(sender.display_name).to eq(review.author_name)
+ expect(sender.address).to eq(gitlab_sender)
+ expect(subject).to deliver_to(recipient.notification_email)
+ end
+ end
+
+ it 'contains the message from the notes of the review' do
+ review.notes.each do |note|
+ is_expected.to have_body_text note.note
+ end
+ end
+
+ context 'when diff note' do
+ let!(:notes) { create_list(:diff_note_on_merge_request, 3, review: review, project: project, author: review.author, noteable: merge_request) }
+
+ it 'links to notes' do
+ review.notes.each do |note|
+ # Text part
+ expect(subject.text_part.body.raw_source).to include(
+ project_merge_request_url(project, merge_request, anchor: "note_#{note.id}")
+ )
+ end
+ end
+ end
+
+ it 'contains review author name' do
+ is_expected.to have_body_text review.author_name
+ end
+
+ it 'has the correct subject and body' do
+ aggregate_failures do
+ is_expected.to have_subject "Re: #{project.name} | #{merge_request.title} (#{merge_request.to_reference})"
+
+ is_expected.to have_body_text project_merge_request_path(project, merge_request)
+ end
+ end
+ end
end