Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/emails/in_product_marketing_spec.rb34
-rw-r--r--spec/mailers/emails/merge_requests_spec.rb24
-rw-r--r--spec/mailers/emails/profile_spec.rb100
-rw-r--r--spec/mailers/emails/projects_spec.rb1
-rw-r--r--spec/mailers/emails/releases_spec.rb1
-rw-r--r--spec/mailers/emails/service_desk_spec.rb1
-rw-r--r--spec/mailers/notify_spec.rb96
7 files changed, 176 insertions, 81 deletions
diff --git a/spec/mailers/emails/in_product_marketing_spec.rb b/spec/mailers/emails/in_product_marketing_spec.rb
index e4157eaf5dc..25735e64bdf 100644
--- a/spec/mailers/emails/in_product_marketing_spec.rb
+++ b/spec/mailers/emails/in_product_marketing_spec.rb
@@ -13,6 +13,38 @@ RSpec.describe Emails::InProductMarketing do
describe '#in_product_marketing_email' do
using RSpec::Parameterized::TableSyntax
+ let(:track) { :create }
+ let(:series) { 0 }
+
+ subject { Notify.in_product_marketing_email(user.id, group.id, track, series) }
+
+ include_context 'gitlab email notification'
+
+ it 'sends to the right user with a link to unsubscribe' do
+ aggregate_failures do
+ expect(subject).to deliver_to(user.notification_email)
+ expect(subject).to have_body_text(profile_notifications_url)
+ end
+ end
+
+ context 'when on gitlab.com' do
+ before do
+ allow(Gitlab).to receive(:com?).and_return(true)
+ end
+
+ it 'has custom headers' do
+ aggregate_failures do
+ expect(subject).to deliver_from(described_class::FROM_ADDRESS)
+ expect(subject).to reply_to(described_class::FROM_ADDRESS)
+ expect(subject).to have_header('X-Mailgun-Track', 'yes')
+ expect(subject).to have_header('X-Mailgun-Track-Clicks', 'yes')
+ expect(subject).to have_header('X-Mailgun-Track-Opens', 'yes')
+ expect(subject).to have_header('X-Mailgun-Tag', 'marketing')
+ expect(subject).to have_body_text('%tag_unsubscribe_url%')
+ end
+ end
+ end
+
where(:track, :series) do
:create | 0
:create | 1
@@ -29,8 +61,6 @@ RSpec.describe Emails::InProductMarketing do
end
with_them do
- subject { Notify.in_product_marketing_email(user.id, group.id, track, series) }
-
it 'has the correct subject and content' do
aggregate_failures do
is_expected.to have_subject(subject_line(track, series))
diff --git a/spec/mailers/emails/merge_requests_spec.rb b/spec/mailers/emails/merge_requests_spec.rb
index 0c0dae6d7e6..dea54f7315d 100644
--- a/spec/mailers/emails/merge_requests_spec.rb
+++ b/spec/mailers/emails/merge_requests_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe Emails::MergeRequests do
aggregate_failures do
is_expected.to have_referable_subject(merge_request, reply: true)
is_expected.to have_body_text(project_merge_request_path(project, merge_request))
- is_expected.to have_body_text('You have been mentioned in Merge Request')
+ is_expected.to have_body_text('You have been mentioned in merge request')
is_expected.to have_link(merge_request.to_reference, href: project_merge_request_url(merge_request.target_project, merge_request))
is_expected.to have_text_part_content(assignee.name)
is_expected.to have_text_part_content(reviewer.name)
@@ -55,9 +55,7 @@ RSpec.describe Emails::MergeRequests do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the merge request author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(merge_request.author.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(merge_request.author)
end
it 'has the correct subject and body' do
@@ -85,9 +83,7 @@ RSpec.describe Emails::MergeRequests do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -120,9 +116,7 @@ RSpec.describe Emails::MergeRequests do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the merge author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(merge_author.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(merge_author)
end
it 'has the correct subject and body' do
@@ -153,9 +147,7 @@ RSpec.describe Emails::MergeRequests do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -229,4 +221,10 @@ RSpec.describe Emails::MergeRequests do
it { expect(subject).to have_content('attachment has been truncated to avoid exceeding the maximum allowed attachment size of 15 MB.') }
end
end
+
+ def expect_sender(user)
+ sender = subject.header[:from].addrs[0]
+ expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
+ expect(sender.address).to eq(gitlab_sender)
+ end
end
diff --git a/spec/mailers/emails/profile_spec.rb b/spec/mailers/emails/profile_spec.rb
index a32e566fc90..8ac1f15d67e 100644
--- a/spec/mailers/emails/profile_spec.rb
+++ b/spec/mailers/emails/profile_spec.rb
@@ -212,6 +212,106 @@ RSpec.describe Emails::Profile do
end
end
+ describe 'SSH key notification' do
+ let_it_be_with_reload(:user) { create(:user) }
+ let_it_be(:fingerprints) { ["aa:bb:cc:dd:ee:zz"] }
+
+ shared_examples 'is sent to the user' do
+ it { is_expected.to deliver_to user.email }
+ end
+
+ shared_examples 'has the correct subject' do |subject_text|
+ it { is_expected.to have_subject subject_text }
+ end
+
+ shared_examples 'has the correct body text' do |body_text|
+ it { is_expected.to have_body_text body_text }
+ end
+
+ shared_examples 'includes a link to ssh key page' do
+ it { is_expected.to have_body_text /#{profile_keys_url}/ }
+ end
+
+ shared_examples 'includes the email reason' do
+ it { is_expected.to have_body_text /You're receiving this email because of your account on localhost/ }
+ end
+
+ shared_examples 'valid use case' do
+ 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_behaves_like 'is sent to the user'
+ it_behaves_like 'includes a link to ssh key page'
+ it_behaves_like 'includes the email reason'
+ end
+
+ shared_examples 'does not send email' do
+ it do
+ expect { subject }.not_to change { ActionMailer::Base.deliveries.count }
+ end
+ end
+
+ shared_context 'block user' do
+ before do
+ user.block!
+ end
+ end
+
+ context 'notification email for expired ssh key' do
+ context 'when valid' do
+ subject { Notify.ssh_key_expired_email(user, fingerprints) }
+
+ include_examples 'valid use case'
+
+ it_behaves_like 'has the correct subject', /Your SSH key has expired/
+ it_behaves_like 'has the correct body text', /Your SSH keys with the following fingerprints has expired/
+ end
+
+ context 'when invalid' do
+ context 'when user does not exist' do
+ subject { Notify.ssh_key_expired_email(nil, fingerprints) }
+
+ it_behaves_like 'does not send email'
+ end
+
+ context 'when user is not active' do
+ subject { Notify.ssh_key_expired_email(user, fingerprints) }
+
+ include_context 'block user'
+
+ it_behaves_like 'does not send email'
+ end
+ end
+ end
+
+ context 'notification email for expiring ssh key' do
+ context 'when valid' do
+ subject { Notify.ssh_key_expiring_soon_email(user, fingerprints) }
+
+ include_examples 'valid use case'
+
+ it_behaves_like 'has the correct subject', /Your SSH key is expiring soon/
+ it_behaves_like 'has the correct body text', /Your SSH keys with the following fingerprints are scheduled to expire soon/
+ end
+
+ context 'when invalid' do
+ context 'when user does not exist' do
+ subject { Notify.ssh_key_expiring_soon_email(nil, fingerprints) }
+
+ it_behaves_like 'does not send email'
+ end
+
+ context 'when user is not active' do
+ subject { Notify.ssh_key_expiring_soon_email(user, fingerprints) }
+
+ include_context 'block user'
+
+ it_behaves_like 'does not send email'
+ end
+ end
+ end
+ end
+
describe 'user unknown sign in email' do
let_it_be(:user) { create(:user) }
let_it_be(:ip) { '169.0.0.1' }
diff --git a/spec/mailers/emails/projects_spec.rb b/spec/mailers/emails/projects_spec.rb
index a1f19a972f1..a5b89d16bc2 100644
--- a/spec/mailers/emails/projects_spec.rb
+++ b/spec/mailers/emails/projects_spec.rb
@@ -81,6 +81,7 @@ RSpec.describe Emails::Projects do
context 'with environment' do
let_it_be(:environment) { create(:environment, project: project) }
+
let(:payload) { { 'gitlab_environment_name' => environment.name } }
let(:metrics_url) { metrics_project_environment_url(project, environment) }
diff --git a/spec/mailers/emails/releases_spec.rb b/spec/mailers/emails/releases_spec.rb
index 6ee87724c83..287971d35a8 100644
--- a/spec/mailers/emails/releases_spec.rb
+++ b/spec/mailers/emails/releases_spec.rb
@@ -10,6 +10,7 @@ RSpec.describe Emails::Releases do
describe '#new_release_email' do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
+
let(:release) { create(:release, project: project) }
subject { Notify.new_release_email(user.id, release) }
diff --git a/spec/mailers/emails/service_desk_spec.rb b/spec/mailers/emails/service_desk_spec.rb
index cb74194020d..57fa990d399 100644
--- a/spec/mailers/emails/service_desk_spec.rb
+++ b/spec/mailers/emails/service_desk_spec.rb
@@ -14,6 +14,7 @@ RSpec.describe Emails::ServiceDesk do
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:email) { 'someone@gitlab.com' }
+
let(:template) { double(content: template_content) }
before_all do
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 79358d3e40c..94a081ae0c9 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -69,11 +69,8 @@ RSpec.describe Notify do
it_behaves_like 'an email sent to a user'
it 'is sent to the assignee as the author' do
- sender = subject.header[:from].addrs.first
-
aggregate_failures do
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
expect(subject).to deliver_to(recipient.notification_email)
end
end
@@ -146,9 +143,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -187,9 +182,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -251,9 +244,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -389,9 +380,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -456,9 +445,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(current_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(current_user)
end
it 'has the correct subject and body' do
@@ -486,10 +473,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the push user' do
- sender = subject.header[:from].addrs[0]
-
- expect(sender.display_name).to eq(push_user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(push_user)
end
it 'has the correct subject and body' do
@@ -815,14 +799,14 @@ RSpec.describe Notify do
is_expected.to have_link('Join now', href: invite_url(project_member.invite_token, invite_type: Members::InviteEmailExperiment::INVITE_TYPE))
end
- it 'contains invite link for the avatar', :experiment do
+ it 'contains invite link for the avatar' do
stub_experiments('members/invite_email': :avatar)
is_expected.not_to have_content('You are invited!')
is_expected.not_to have_body_text 'What is a GitLab'
end
- it 'contains invite link for the avatar', :experiment do
+ it 'contains invite link for the avatar' do
stub_experiments('members/invite_email': :permission_info)
is_expected.not_to have_content('You are invited!')
@@ -1002,11 +986,8 @@ RSpec.describe Notify do
it_behaves_like 'it should have Gmail Actions links'
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(note_author.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(note_author)
expect(subject).to deliver_to(recipient.notification_email)
end
end
@@ -1162,11 +1143,8 @@ RSpec.describe Notify do
it_behaves_like 'it should have Gmail Actions links'
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(note_author.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(note_author)
expect(subject).to deliver_to(recipient.notification_email)
end
end
@@ -1221,12 +1199,6 @@ RSpec.describe Notify do
issue.issue_email_participants.create!(email: 'service.desk@example.com')
end
- def expect_sender(username)
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(username)
- expect(sender.address).to eq(gitlab_sender)
- end
-
describe 'thank you email' do
subject { described_class.service_desk_thank_you_email(issue.id) }
@@ -1244,14 +1216,16 @@ RSpec.describe Notify do
end
it 'uses service bot name by default' do
- expect_sender(User.support_bot.name)
+ expect_sender(User.support_bot)
end
context 'when custom outgoing name is set' do
let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: 'some custom name') }
it 'uses custom name in "from" header' do
- expect_sender('some custom name')
+ sender = subject.header[:from].addrs[0]
+ expect(sender.display_name).to eq('some custom name')
+ expect(sender.address).to eq(gitlab_sender)
end
end
@@ -1259,7 +1233,7 @@ RSpec.describe Notify do
let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: '') }
it 'uses service bot name' do
- expect_sender(User.support_bot.name)
+ expect_sender(User.support_bot)
end
end
end
@@ -1276,7 +1250,7 @@ RSpec.describe Notify do
end
it 'uses author\'s name in "from" header' do
- expect_sender(first_note.author.name)
+ expect_sender(first_note.author)
end
it 'has the correct subject and body' do
@@ -1672,9 +1646,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject and body' do
@@ -1699,9 +1671,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject and body' do
@@ -1725,9 +1695,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject' do
@@ -1748,9 +1716,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject' do
@@ -1777,9 +1743,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject and body' do
@@ -1870,9 +1834,7 @@ RSpec.describe Notify do
it_behaves_like 'appearance header and footer not enabled'
it 'is sent as the author' do
- sender = subject.header[:from].addrs[0]
- expect(sender.display_name).to eq(user.name)
- expect(sender.address).to eq(gitlab_sender)
+ expect_sender(user)
end
it 'has the correct subject and body' do
@@ -1962,12 +1924,8 @@ RSpec.describe Notify do
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)
+ expect_sender(review.author)
end
end
@@ -2002,4 +1960,10 @@ RSpec.describe Notify do
end
end
end
+
+ def expect_sender(user)
+ sender = subject.header[:from].addrs[0]
+ expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
+ expect(sender.address).to eq(gitlab_sender)
+ end
end