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
Jérome Perrin
gitlab-ce
Commits
e2c01f39
Commit
e2c01f39
authored
Aug 11, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests for pipeline events
parent
478990bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
18 deletions
+50
-18
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-1
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+47
-17
No files found.
app/models/ci/pipeline.rb
View file @
e2c01f39
...
@@ -208,8 +208,10 @@ module Ci
...
@@ -208,8 +208,10 @@ module Ci
self
.
started_at
=
statuses
.
started_at
self
.
started_at
=
statuses
.
started_at
self
.
finished_at
=
statuses
.
finished_at
self
.
finished_at
=
statuses
.
finished_at
self
.
duration
=
statuses
.
latest
.
duration
self
.
duration
=
statuses
.
latest
.
duration
should_execute_hooks
=
status_changed?
save
save
execute_hooks
if
s
tatus_changed?
execute_hooks
if
s
hould_execute_hooks
end
end
private
private
...
...
spec/models/ci/pipeline_spec.rb
View file @
e2c01f39
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Ci
::
Pipeline
,
models:
true
do
describe
Ci
::
Pipeline
,
models:
true
do
let
(
:project
)
{
FactoryGirl
.
create
:empty_project
}
let
(
:project
)
{
FactoryGirl
.
create
:empty_project
}
let
(
:pipeline
)
{
FactoryGirl
.
create
:ci_empty_pipeline
,
project:
project
}
let
(
:pipeline
)
{
FactoryGirl
.
create
:ci_empty_pipeline
,
status:
'created'
,
project:
project
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
...
@@ -303,6 +303,9 @@ describe Ci::Pipeline, models: true do
...
@@ -303,6 +303,9 @@ describe Ci::Pipeline, models: true do
end
end
describe
'#execute_hooks'
do
describe
'#execute_hooks'
do
let!
(
:build_a
)
{
create_build
(
'a'
)
}
let!
(
:build_b
)
{
create_build
(
'b'
)
}
let!
(
:hook
)
do
let!
(
:hook
)
do
create
(
:project_hook
,
project:
project
,
pipeline_events:
enabled
)
create
(
:project_hook
,
project:
project
,
pipeline_events:
enabled
)
end
end
...
@@ -314,30 +317,48 @@ describe Ci::Pipeline, models: true do
...
@@ -314,30 +317,48 @@ describe Ci::Pipeline, models: true do
context
'with pipeline hooks enabled'
do
context
'with pipeline hooks enabled'
do
let
(
:enabled
)
{
true
}
let
(
:enabled
)
{
true
}
before
do
WebMock
.
stub_request
(
:post
,
hook
.
url
)
end
context
'with multiple builds'
do
context
'with multiple builds'
do
let!
(
:build_a
)
{
create_build
(
'a'
)
}
context
'when build is queued'
do
let!
(
:build_b
)
{
create_build
(
'b'
)
}
before
do
build_a
.
queue
build_b
.
queue
end
it
'fires exactly 3 hooks
'
do
it
'receive a pending event once
'
do
stub_request
(
'pending'
)
expect
(
WebMock
).
to
requested
(
'pending'
).
once
build_a
.
queue
end
build_b
.
queue
end
stub_request
(
'running'
)
context
'when build is run'
do
build_a
.
run
before
do
build_b
.
run
build_a
.
queue
build_a
.
run
build_b
.
queue
build_b
.
run
end
stub_request
(
'success'
)
it
'receive a running event once'
do
build_a
.
success
expect
(
WebMock
).
to
requested
(
'running'
).
once
build_b
.
success
end
end
end
def
create_build
(
name
)
context
'when all builds succeed'
do
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
,
name:
name
)
before
do
build_a
.
success
build_b
.
success
end
it
'receive a success event once'
do
expect
(
WebMock
).
to
requested
(
'success'
).
once
end
end
end
def
stub_request
(
status
)
def
requested
(
status
)
WebMock
.
stub_request
(
:post
,
hook
.
url
).
with
do
|
req
|
have_requested
(
:post
,
hook
.
url
).
with
do
|
req
|
json_body
=
JSON
.
parse
(
req
.
body
)
json_body
=
JSON
.
parse
(
req
.
body
)
json_body
[
'object_attributes'
][
'status'
]
==
status
&&
json_body
[
'object_attributes'
][
'status'
]
==
status
&&
json_body
[
'builds'
].
length
==
2
json_body
[
'builds'
].
length
==
2
...
@@ -349,9 +370,18 @@ describe Ci::Pipeline, models: true do
...
@@ -349,9 +370,18 @@ describe Ci::Pipeline, models: true do
context
'with pipeline hooks disabled'
do
context
'with pipeline hooks disabled'
do
let
(
:enabled
)
{
false
}
let
(
:enabled
)
{
false
}
before
do
build_a
.
queue
build_b
.
queue
end
it
'did not execute pipeline_hook after touched'
do
it
'did not execute pipeline_hook after touched'
do
expect
(
WebMock
).
not_to
have_requested
(
:post
,
hook
.
url
)
expect
(
WebMock
).
not_to
have_requested
(
:post
,
hook
.
url
)
end
end
end
end
def
create_build
(
name
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
name
)
end
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