Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
15bb44fc
Commit
15bb44fc
authored
Sep 14, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test for real
parent
c5e0305d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
34 deletions
+82
-34
spec/models/project_services/pipeline_email_service_spec.rb
spec/models/project_services/pipeline_email_service_spec.rb
+82
-34
No files found.
spec/models/project_services/pipeline_email_service_spec.rb
View file @
15bb44fc
require
'spec_helper'
describe
PipelinesEmailService
do
let
(
:data
)
do
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
create
(
:ci_pipeline
))
end
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:recipient
)
{
'test@gitlab.com'
}
def
expect_pipeline_service
expect_any_instance_of
(
Ci
::
SendPipelineNotificationServic
e
)
let
(
:data
)
do
Gitlab
::
DataBuilder
::
Pipeline
.
build
(
pipelin
e
)
end
def
receive_execute
receive
(
:execute
).
with
([
recipient
])
before
do
ActionMailer
::
Base
.
deliveries
.
clear
end
describe
'Validations'
do
...
...
@@ -57,24 +54,53 @@ describe PipelinesEmailService do
end
end
describe
'#test
'
do
shared_examples
'sending email
'
do
before
do
subject
.
recipients
=
recipient
perform_enqueued_jobs
do
run
end
end
shared_examples
'sending email'
do
it
'sends email'
do
expect_pipeline_service
.
to
receive_execute
it
'sends email'
do
sent_to
=
ActionMailer
::
Base
.
deliveries
.
flat_map
(
&
:to
)
expect
(
sent_to
).
to
contain_exactly
(
recipient
)
end
end
subject
.
test
(
data
)
shared_examples
'not sending email'
do
before
do
perform_enqueued_jobs
do
run
end
end
it_behaves_like
'sending email'
it
'does not send email'
do
expect
(
ActionMailer
::
Base
.
deliveries
).
to
be_empty
end
end
describe
'#test'
do
def
run
subject
.
test
(
data
)
end
before
do
subject
.
recipients
=
recipient
end
context
'when pipeline is failed'
do
before
do
data
[
:object_attributes
][
:status
]
=
'failed'
pipeline
.
update
(
status:
'failed'
)
end
it_behaves_like
'sending email'
end
context
'when pipeline is succeeded'
do
before
do
data
[
:object_attributes
][
:status
]
=
'success'
pipeline
.
update
(
status:
'success'
)
end
it_behaves_like
'sending email'
...
...
@@ -82,25 +108,31 @@ describe PipelinesEmailService do
end
describe
'#execute'
do
def
run
subject
.
execute
(
data
)
end
context
'with recipients'
do
before
do
subject
.
recipients
=
recipient
end
it
'sends email for failed pipeline'
do
data
[
:object_attributes
][
:status
]
=
'failed'
expect_pipeline_service
.
to
receive_execute
context
'with failed pipeline'
do
before
do
data
[
:object_attributes
][
:status
]
=
'failed'
pipeline
.
update
(
status:
'failed'
)
end
subject
.
execute
(
data
)
it_behaves_like
'sending email'
end
it
'does not send email for succeeded pipeline'
do
data
[
:object_attributes
][
:status
]
=
'success'
expect_pipeline_service
.
not_to
receive_execute
context
'with succeeded pipeline'
do
before
do
data
[
:object_attributes
][
:status
]
=
'success'
pipeline
.
update
(
status:
'success'
)
end
subject
.
execute
(
data
)
it_behaves_like
'not sending email'
end
context
'with notify_only_broken_pipelines on'
do
...
...
@@ -108,23 +140,39 @@ describe PipelinesEmailService do
subject
.
notify_only_broken_pipelines
=
true
end
it
'sends email for failed pipeline'
do
data
[
:object_attributes
][
:status
]
=
'failed'
context
'with failed pipeline'
do
before
do
data
[
:object_attributes
][
:status
]
=
'failed'
pipeline
.
update
(
status:
'failed'
)
end
expect_pipeline_service
.
to
receive_execute
it_behaves_like
'sending email'
end
context
'with succeeded pipeline'
do
before
do
data
[
:object_attributes
][
:status
]
=
'success'
pipeline
.
update
(
status:
'success'
)
end
subject
.
execute
(
data
)
it_behaves_like
'not sending email'
end
end
end
it
'does not send email when recipients list is empty'
do
subject
.
recipients
=
' ,, '
data
[
:object_attributes
][
:status
]
=
'failed'
context
'with empty recipients list'
do
before
do
subject
.
recipients
=
' ,, '
end
expect_pipeline_service
.
not_to
receive_execute
context
'with failed pipeline'
do
before
do
data
[
:object_attributes
][
:status
]
=
'failed'
pipeline
.
update
(
status:
'failed'
)
end
subject
.
execute
(
data
)
it_behaves_like
'not sending email'
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment