summaryrefslogtreecommitdiff
path: root/spec/models/project_services/pipelines_email_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/project_services/pipelines_email_service_spec.rb')
-rw-r--r--spec/models/project_services/pipelines_email_service_spec.rb157
1 files changed, 127 insertions, 30 deletions
diff --git a/spec/models/project_services/pipelines_email_service_spec.rb b/spec/models/project_services/pipelines_email_service_spec.rb
index b85565e0c25..67358d6c3d6 100644
--- a/spec/models/project_services/pipelines_email_service_spec.rb
+++ b/spec/models/project_services/pipelines_email_service_spec.rb
@@ -53,9 +53,10 @@ describe PipelinesEmailService, :mailer do
end
end
- shared_examples 'sending email' do
+ shared_examples 'sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
+ subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
@@ -69,9 +70,10 @@ describe PipelinesEmailService, :mailer do
end
end
- shared_examples 'not sending email' do
+ shared_examples 'not sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
+ subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
@@ -101,27 +103,84 @@ describe PipelinesEmailService, :mailer do
it_behaves_like 'sending email'
end
- context 'when pipeline is failed and on a non-default branch' do
- before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ context 'when the pipeline failed' do
+ context 'on default branch' do
+ before do
+ data[:object_attributes][:ref] = project.default_branch
+ pipeline.update(ref: project.default_branch)
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with notify_only_default branch on' do
+ context 'on a protected branch' do
before do
- subject.notify_only_default_branch = true
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ data[:object_attributes][:ref] = 'a-protected-branch'
+ pipeline.update(ref: 'a-protected-branch')
end
- it_behaves_like 'sending email'
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with notify_only_default_branch off' do
- it_behaves_like 'sending email'
+ context 'on a neither protected nor default branch' do
+ before do
+ data[:object_attributes][:ref] = 'a-random-branch'
+ pipeline.update(ref: 'a-random-branch')
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
end
end
describe '#execute' do
+ before do
+ subject.project = project
+ end
+
def run
subject.execute(data)
end
@@ -159,37 +218,75 @@ describe PipelinesEmailService, :mailer do
end
end
- context 'with notify_only_default_branch off' do
- context 'with default branch' do
- it_behaves_like 'sending email'
+ context 'when the pipeline failed' do
+ context 'on default branch' do
+ before do
+ data[:object_attributes][:ref] = project.default_branch
+ pipeline.update(ref: project.default_branch)
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with non default branch' do
+ context 'on a protected branch' do
before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ data[:object_attributes][:ref] = 'a-protected-branch'
+ pipeline.update(ref: 'a-protected-branch')
end
- it_behaves_like 'sending email'
- end
- end
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default"
+ end
- context 'with notify_only_default_branch on' do
- before do
- subject.notify_only_default_branch = true
- end
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
- context 'with default branch' do
- it_behaves_like 'sending email'
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with non default branch' do
+ context 'on a neither protected nor default branch' do
before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ data[:object_attributes][:ref] = 'a-random-branch'
+ pipeline.update(ref: 'a-random-branch')
end
- it_behaves_like 'not sending email'
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
end
end