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:
authorLin Jen-Shin <godfat@godfat.org>2016-09-28 12:22:06 +0300
committerLin Jen-Shin <godfat@godfat.org>2016-10-17 10:25:20 +0300
commiteeeb96c9d0cab9c5da850809a9614e2a01fdb7d2 (patch)
tree76749cd11b4c9b18fdfa67d7fb5509e671ed9c57 /spec/workers
parent9622ef64e41058b8dec97c98f568d8fdea95fd61 (diff)
Change service to be a worker, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_16118195
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/send_pipeline_notification_worker_spec.rb103
1 files changed, 103 insertions, 0 deletions
diff --git a/spec/workers/send_pipeline_notification_worker_spec.rb b/spec/workers/send_pipeline_notification_worker_spec.rb
new file mode 100644
index 00000000000..0670d67501a
--- /dev/null
+++ b/spec/workers/send_pipeline_notification_worker_spec.rb
@@ -0,0 +1,103 @@
+require 'spec_helper'
+
+describe SendPipelineNotificationWorker, services: true do
+ let(:pipeline) do
+ create(:ci_pipeline,
+ project: project,
+ sha: project.commit('master').sha,
+ user: user,
+ status: status)
+ end
+
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:pusher) { user }
+ let(:watcher) { pusher }
+
+ describe '#execute' do
+ before do
+ reset_delivered_emails!
+ 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
+
+ expected_receivers = [pusher, watcher].uniq.sort_by(&:email)
+ actual = ActionMailer::Base.deliveries.sort_by(&:to)
+
+ expect(expected_receivers.size).to eq(actual.size)
+
+ actual.zip(expected_receivers).each do |(email, receiver)|
+ expect(email.subject).to include(email_subject)
+ expect(email.to).to eq([receiver.email])
+ end
+ end
+ end
+
+ context 'with success pipeline' do
+ let(:status) { 'success' }
+ let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" }
+
+ it_behaves_like 'sending emails'
+
+ context 'with pipeline from someone else' do
+ let(:pusher) { create(:user) }
+
+ context 'with success pipeline notification on' do
+ let(:watcher) { user }
+
+ 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
+ before do
+ watcher.global_notification_setting.
+ update(level: 'custom', success_pipeline: false)
+ end
+
+ it_behaves_like 'sending emails'
+ end
+ 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) }
+
+ context 'with failed pipeline notification on' do
+ let(:watcher) { user }
+
+ 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
+ before do
+ watcher.global_notification_setting.
+ update(level: 'custom', failed_pipeline: false)
+ end
+
+ it_behaves_like 'sending emails'
+ end
+ end
+ end
+ end
+end