summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-03-30 12:29:52 +0100
committerSean McGivern <sean@gitlab.com>2017-04-03 13:59:48 +0100
commita1805cbcd55a28658049b42c12a87a50ab9ab977 (patch)
treeaeab49a23df0bb52a8900e01a5c7348570f8bcef /spec/workers
parent2faf955c241ce7e99111f8fd0cae2e7ab6167e5a (diff)
downloadgitlab-ce-a1805cbcd55a28658049b42c12a87a50ab9ab977.tar.gz
Quiet pipeline emailsquiet-pipelines
1. Never send a pipeline email to anyone other than the user who created the pipeline. 2. Only send pipeline success emails to people with the custom notification setting for enabled. Watchers and participants will never receive this. 3. When custom settings are unset (for new settings and legacy ones), act as if failed_pipeline is set.
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/pipeline_notification_worker_spec.rb126
1 files changed, 7 insertions, 119 deletions
diff --git a/spec/workers/pipeline_notification_worker_spec.rb b/spec/workers/pipeline_notification_worker_spec.rb
index 5a7ce2e08c4..139032d77bd 100644
--- a/spec/workers/pipeline_notification_worker_spec.rb
+++ b/spec/workers/pipeline_notification_worker_spec.rb
@@ -3,131 +3,19 @@ require 'spec_helper'
describe PipelineNotificationWorker do
include EmailHelpers
- let(:pipeline) do
- create(:ci_pipeline,
- project: project,
- sha: project.commit('master').sha,
- user: pusher,
- status: status)
- end
-
- let(:project) { create(:project, :repository, public_builds: false) }
- let(:user) { create(:user) }
- let(:pusher) { user }
- let(:watcher) { pusher }
+ let(:pipeline) { create(:ci_pipeline) }
describe '#execute' do
- before do
- reset_delivered_emails!
- pipeline.project.team << [pusher, Gitlab::Access::DEVELOPER]
- end
-
- context 'when watcher has developer access' do
- before do
- pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER]
- end
-
- shared_examples 'sending emails' do
- it 'sends emails' do
- perform_enqueued_jobs do
- subject.perform(pipeline.id)
- end
-
- emails = ActionMailer::Base.deliveries
- actual = emails.flat_map(&:bcc).sort
- expected_receivers = receivers.map(&:email).uniq.sort
-
- expect(actual).to eq(expected_receivers)
- expect(emails.size).to eq(1)
- expect(emails.last.subject).to include(email_subject)
- end
- end
-
- context 'with success pipeline' do
- let(:status) { 'success' }
- let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
- let(:receivers) { [pusher, watcher] }
-
- it_behaves_like 'sending emails'
-
- context 'with pipeline from someone else' do
- let(:pusher) { create(:user) }
- let(:watcher) { user }
-
- context 'with success pipeline notification on' do
- before do
- watcher.global_notification_setting.
- update(level: 'custom', success_pipeline: true)
- end
-
- it_behaves_like 'sending emails'
- end
-
- context 'with success pipeline notification off' do
- let(:receivers) { [pusher] }
+ it 'calls NotificationService#pipeline_finished when the pipeline exists' do
+ expect(NotificationService).to receive_message_chain(:new, :pipeline_finished)
- before do
- watcher.global_notification_setting.
- update(level: 'custom', success_pipeline: false)
- end
-
- it_behaves_like 'sending emails'
- end
- end
-
- context 'with failed pipeline' do
- let(:status) { 'failed' }
- let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
-
- it_behaves_like 'sending emails'
-
- context 'with pipeline from someone else' do
- let(:pusher) { create(:user) }
- let(:watcher) { user }
-
- context 'with failed pipeline notification on' do
- before do
- watcher.global_notification_setting.
- update(level: 'custom', failed_pipeline: true)
- end
-
- it_behaves_like 'sending emails'
- end
-
- context 'with failed pipeline notification off' do
- let(:receivers) { [pusher] }
-
- before do
- watcher.global_notification_setting.
- update(level: 'custom', failed_pipeline: false)
- end
-
- it_behaves_like 'sending emails'
- end
- end
- end
- end
+ subject.perform(pipeline.id)
end
- context 'when watcher has no read_build access' do
- let(:status) { 'failed' }
- let(:email_subject) { "Pipeline ##{pipeline.id} has failed" }
- let(:watcher) { create(:user) }
-
- before do
- pipeline.project.team << [watcher, Gitlab::Access::GUEST]
-
- watcher.global_notification_setting.
- update(level: 'custom', failed_pipeline: true)
-
- perform_enqueued_jobs do
- subject.perform(pipeline.id)
- end
- end
+ it 'does nothing when the pipeline does not exist' do
+ expect(NotificationService).not_to receive(:new)
- it 'does not send emails' do
- should_only_email(pusher, kind: :bcc)
- end
+ subject.perform(Ci::Pipeline.maximum(:id).to_i.succ)
end
end
end