diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-10-21 18:16:39 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-10-21 18:18:03 +0800 |
commit | 6061c9fa3d942c4b1aa466ee8f5f8eb3ae48853e (patch) | |
tree | 58420c8b0a2f5a6649c6aba516223942d4fc60c9 /spec/workers | |
parent | 1cdad622aacf9ae7e7d61e575aaa77dddf7ae7b9 (diff) | |
download | gitlab-ce-6061c9fa3d942c4b1aa466ee8f5f8eb3ae48853e.tar.gz |
Send only to users have :read_build access, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_17193335
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/pipeline_notification_worker_spec.rb | 132 |
1 files changed, 81 insertions, 51 deletions
diff --git a/spec/workers/pipeline_notification_worker_spec.rb b/spec/workers/pipeline_notification_worker_spec.rb index c334b2057a6..d487a719680 100644 --- a/spec/workers/pipeline_notification_worker_spec.rb +++ b/spec/workers/pipeline_notification_worker_spec.rb @@ -17,84 +17,114 @@ describe PipelineNotificationWorker do describe '#execute' do before do reset_delivered_emails! - pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER] + pipeline.project.team << [pusher, Gitlab::Access::DEVELOPER] end - shared_examples 'sending emails' do - it 'sends emails' do - perform_enqueued_jobs do - subject.perform(pipeline.id) - end + context 'when watcher has developer access' do + before do + pipeline.project.team << [watcher, Gitlab::Access::DEVELOPER] + end - emails = ActionMailer::Base.deliveries - actual = emails.flat_map(&:bcc).sort - expected_receivers = [pusher, watcher].map(&:email).uniq.sort + shared_examples 'sending emails' do + it 'sends emails' do + perform_enqueued_jobs do + subject.perform(pipeline.id) + end - expect(actual).to eq(expected_receivers) - expect(emails.size).to eq(1) - expect(emails.last.subject).to include(email_subject) - end - end + emails = ActionMailer::Base.deliveries + actual = emails.flat_map(&:bcc).sort + expected_receivers = receivers.map(&:email).uniq.sort - context 'with success pipeline' do - let(:status) { 'success' } - let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" } + expect(actual).to eq(expected_receivers) + expect(emails.size).to eq(1) + expect(emails.last.subject).to include(email_subject) + end + end - it_behaves_like 'sending emails' + context 'with success pipeline' do + let(:status) { 'success' } + let(:email_subject) { "Pipeline ##{pipeline.id} has succeeded" } + let(:receivers) { [pusher, watcher] } - context 'with pipeline from someone else' do - let(:pusher) { create(:user) } + it_behaves_like 'sending emails' - context 'with success pipeline notification on' do + context 'with pipeline from someone else' do + let(:pusher) { create(:user) } let(:watcher) { user } - before do - watcher.global_notification_setting. - update(level: 'custom', success_pipeline: true) + 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 - it_behaves_like 'sending emails' - end + context 'with success pipeline notification off' do + let(:receivers) { [pusher] } + + before do + watcher.global_notification_setting. + update(level: 'custom', success_pipeline: false) + end - context 'with success pipeline notification off' do - before do - watcher.global_notification_setting. - update(level: 'custom', success_pipeline: false) + 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 end - context 'with failed pipeline' do + context 'when watcher has no read_build access' do let(:status) { 'failed' } let(:email_subject) { "Pipeline ##{pipeline.id} has failed" } + let(:watcher) { create(:user) } - it_behaves_like 'sending emails' + before do + pipeline.project.team << [watcher, Gitlab::Access::GUEST] - 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 + watcher.global_notification_setting. + update(level: 'custom', failed_pipeline: true) - it_behaves_like 'sending emails' + perform_enqueued_jobs do + subject.perform(pipeline.id) end + 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 + it 'does not send emails' do + should_only_email(pusher, kind: :bcc) end end end |