summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-31 15:08:53 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-31 15:08:53 +0000
commit1e6a9268646e7346519610492fc2a02d6655a663 (patch)
tree3be2b434ac62b83154f7c93e15a9283498f00ba9 /spec/models
parent7ac9cddf764fe60a7f86ae9b0bfb5c30825d9a4e (diff)
downloadgitlab-ce-1e6a9268646e7346519610492fc2a02d6655a663.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/project_services/emails_on_push_service_spec.rb72
1 files changed, 64 insertions, 8 deletions
diff --git a/spec/models/project_services/emails_on_push_service_spec.rb b/spec/models/project_services/emails_on_push_service_spec.rb
index ffe241aa880..56f094ecb48 100644
--- a/spec/models/project_services/emails_on_push_service_spec.rb
+++ b/spec/models/project_services/emails_on_push_service_spec.rb
@@ -25,19 +25,75 @@ describe EmailsOnPushService do
let(:push_data) { { object_kind: 'push' } }
let(:project) { create(:project, :repository) }
let(:service) { create(:emails_on_push_service, project: project) }
+ let(:recipients) { 'test@gitlab.com' }
- it 'does not send emails when disabled' do
- expect(project).to receive(:emails_disabled?).and_return(true)
- expect(EmailsOnPushWorker).not_to receive(:perform_async)
+ before do
+ subject.recipients = recipients
+ end
+
+ shared_examples 'sending email' do |branches_to_be_notified, branch_being_pushed_to|
+ let(:push_data) { { object_kind: 'push', object_attributes: { ref: branch_being_pushed_to } } }
- service.execute(push_data)
+ before do
+ subject.branches_to_be_notified = branches_to_be_notified
+ end
+
+ it 'sends email' do
+ expect(EmailsOnPushWorker).not_to receive(:perform_async)
+
+ service.execute(push_data)
+ end
end
- it 'does send emails when enabled' do
- expect(project).to receive(:emails_disabled?).and_return(false)
- expect(EmailsOnPushWorker).to receive(:perform_async)
+ shared_examples 'not sending email' do |branches_to_be_notified, branch_being_pushed_to|
+ let(:push_data) { { object_kind: 'push', object_attributes: { ref: branch_being_pushed_to } } }
- service.execute(push_data)
+ before do
+ subject.branches_to_be_notified = branches_to_be_notified
+ end
+
+ it 'does not send email' do
+ expect(EmailsOnPushWorker).not_to receive(:perform_async)
+
+ service.execute(push_data)
+ end
+ end
+
+ context 'when emails are disabled on the project' do
+ it 'does not send emails' do
+ expect(project).to receive(:emails_disabled?).and_return(true)
+ expect(EmailsOnPushWorker).not_to receive(:perform_async)
+
+ service.execute(push_data)
+ end
+ end
+
+ context 'when emails are enabled on the project' do
+ before do
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ expect(project).to receive(:emails_disabled?).and_return(true)
+ end
+
+ using RSpec::Parameterized::TableSyntax
+
+ where(:case_name, :branches_to_be_notified, :branch_being_pushed_to, :expected_action) do
+ 'pushing to a random branch and notification configured for all branches' | 'all' | 'random' | 'sending email'
+ 'pushing to the default branch and notification configured for all branches' | 'all' | 'master' | 'sending email'
+ 'pushing to a protected branch and notification configured for all branches' | 'all' | 'a-protected-branch' | 'sending email'
+ 'pushing to a random branch and notification configured for default branch only' | 'default' | 'random' | 'not sending email'
+ 'pushing to the default branch and notification configured for default branch only' | 'default' | 'master' | 'sending email'
+ 'pushing to a protected branch and notification configured for default branch only' | 'default' | 'a-protected-branch' | 'not sending email'
+ 'pushing to a random branch and notification configured for protected branches only' | 'protected' | 'random' | 'not sending email'
+ 'pushing to the default branch and notification configured for protected branches only' | 'protected' | 'master' | 'not sending email'
+ 'pushing to a protected branch and notification configured for protected branches only' | 'protected' | 'a-protected-branch' | 'sending email'
+ 'pushing to a random branch and notification configured for default and protected branches only' | 'default_and_protected' | 'random' | 'not sending email'
+ 'pushing to the default branch and notification configured for default and protected branches only' | 'default_and_protected' | 'master' | 'sending email'
+ 'pushing to a protected branch and notification configured for default and protected branches only' | 'default_and_protected' | 'a-protected-branch' | 'sending email'
+ end
+
+ with_them do
+ include_examples params[:expected_action], branches_to_be_notified: params[:branches_to_be_notified], branch_being_pushed_to: params[:branch_being_pushed_to]
+ end
end
end
end