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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2b0b53cd
Commit
2b0b53cd
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for stage API endpoint
parent
ac86c495
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
3 deletions
+70
-3
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+1
-3
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-0
app/models/ci/stage.rb
app/models/ci/stage.rb
+4
-0
spec/features/projects/pipelines/pipelines_spec.rb
spec/features/projects/pipelines/pipelines_spec.rb
+29
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+20
-0
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+11
-0
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
2b0b53cd
...
...
@@ -42,9 +42,7 @@ class Projects::PipelinesController < Projects::ApplicationController
end
def
stage
@stage
=
pipeline
.
stages
.
find
do
|
stage
|
stage
.
name
==
params
[
:stage
]
end
@stage
=
pipeline
.
stage
(
params
[
:stage
])
return
not_found
unless
@stage
respond_to
do
|
format
|
...
...
app/models/ci/pipeline.rb
View file @
2b0b53cd
...
...
@@ -116,6 +116,11 @@ module Ci
where
.
not
(
duration:
nil
).
sum
(
:duration
)
end
def
stage
(
name
)
stage
=
Ci
::
Stage
.
new
(
self
,
name:
name
)
stage
unless
stage
.
statuses_count
.
zero?
end
def
stages_count
statuses
.
select
(
:stage
).
distinct
.
count
end
...
...
app/models/ci/stage.rb
View file @
2b0b53cd
...
...
@@ -18,6 +18,10 @@ module Ci
name
end
def
statuses_count
@statuses_count
||=
statuses
.
count
end
def
status
@status
||=
statuses
.
latest
.
status
end
...
...
spec/features/projects/pipelines/pipelines_spec.rb
View file @
2b0b53cd
...
...
@@ -152,6 +152,35 @@ describe "Pipelines" do
end
end
describe
'GET /:project/pipelines/stage?name=stage'
do
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
,
status:
'running'
)
end
context
'when accessing existing stage'
do
let!
(
:build
)
do
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'build'
)
end
before
do
visit
stage_namespace_project_pipeline_path
(
project
.
namespace
,
project
,
pipeline
,
format: :json
,
stage:
'build'
)
end
it
{
expect
(
page
).
to
have_http_status
(
:ok
)
}
end
context
'when accessing unknown stage'
do
before
do
visit
stage_namespace_project_pipeline_path
(
project
.
namespace
,
project
,
pipeline
,
format: :json
,
stage:
'test'
)
end
it
{
expect
(
page
).
to
have_http_status
(
:not_found
)
}
end
end
describe
'POST /:project/pipelines'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/ci/pipeline_spec.rb
View file @
2b0b53cd
...
...
@@ -175,6 +175,26 @@ describe Ci::Pipeline, models: true do
end
end
describe
'#stage'
do
subject
{
pipeline
.
stage
(
'test'
)
}
context
'with status in stage'
do
let!
(
:status
)
{
create
(
:commit_status
,
pipeline:
pipeline
,
stage:
'test'
)
}
it
'return stage object'
do
is_expected
.
to
be_a
(
Ci
::
Stage
)
end
end
context
'without status in stage'
do
let!
(
:status
)
{
create
(
:commit_status
,
pipeline:
pipeline
,
stage:
'build'
)
}
it
'return stage object'
do
is_expected
.
to
be_nil
end
end
end
describe
'state machine'
do
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
let
(
:build
)
{
create_build
(
'build1'
,
0
)
}
...
...
spec/models/ci/stage_spec.rb
View file @
2b0b53cd
...
...
@@ -28,6 +28,17 @@ describe Ci::Stage, models: true do
end
end
describe
'#statuses_count'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
)
}
let!
(
:other_build
)
{
create_job
(
:ci_build
,
stage:
'other stage'
)
}
subject
{
stage
.
statuses_count
}
it
"statuses only from current stage"
do
is_expected
.
to
eq
(
1
)
end
end
describe
'#builds'
do
let!
(
:stage_build
)
{
create_job
(
:ci_build
)
}
let!
(
:commit_status
)
{
create_job
(
:commit_status
)
}
...
...
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