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
Boxiang Sun
gitlab-ce
Commits
8ed7b340
Commit
8ed7b340
authored
Sep 26, 2018
by
Shinya Maeda
Committed by
Alessio Caiazza
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for CommitStatus and Ci::Stage
parent
cc8b8a60
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
2 deletions
+96
-2
spec/factories/commit_statuses.rb
spec/factories/commit_statuses.rb
+4
-0
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+24
-0
spec/models/commit_status_spec.rb
spec/models/commit_status_spec.rb
+20
-0
spec/models/concerns/has_status_spec.rb
spec/models/concerns/has_status_spec.rb
+48
-2
No files found.
spec/factories/commit_statuses.rb
View file @
8ed7b340
...
...
@@ -41,6 +41,10 @@ FactoryBot.define do
status
'manual'
end
trait
:scheduled
do
status
'scheduled'
end
after
(
:build
)
do
|
build
,
evaluator
|
build
.
project
=
build
.
pipeline
.
project
end
...
...
spec/models/ci/stage_spec.rb
View file @
8ed7b340
...
...
@@ -89,6 +89,18 @@ describe Ci::Stage, :models do
end
end
context
'when stage is scheduled because of scheduled builds'
do
before
do
create
(
:ci_build
,
:scheduled
,
stage_id:
stage
.
id
)
end
it
'updates status to scheduled'
do
expect
{
stage
.
update_status
}
.
to
change
{
stage
.
reload
.
status
}
.
to
'scheduled'
end
end
context
'when stage is skipped because is empty'
do
it
'updates status to skipped'
do
expect
{
stage
.
update_status
}
...
...
@@ -188,6 +200,18 @@ describe Ci::Stage, :models do
end
end
describe
'#schedule'
do
subject
{
stage
.
schedule
}
let
(
:stage
)
{
create
(
:ci_stage_entity
,
status: :created
)
}
it
'updates stage status'
do
subject
expect
(
stage
).
to
be_scheduled
end
end
describe
'#position'
do
context
'when stage has been imported and does not have position index set'
do
before
do
...
...
spec/models/commit_status_spec.rb
View file @
8ed7b340
...
...
@@ -129,6 +129,20 @@ describe CommitStatus do
end
end
describe
'#cancel'
do
subject
{
job
.
cancel
}
context
'when status is scheduled'
do
let
(
:job
)
{
build
(
:commit_status
,
:scheduled
)
}
it
'updates the status'
do
subject
expect
(
job
).
to
be_canceled
end
end
end
describe
'#auto_canceled?'
do
subject
{
commit_status
.
auto_canceled?
}
...
...
@@ -564,6 +578,12 @@ describe CommitStatus do
it_behaves_like
'commit status enqueued'
end
context
'when initial state is :scheduled'
do
let
(
:commit_status
)
{
create
(
:commit_status
,
:scheduled
)
}
it_behaves_like
'commit status enqueued'
end
end
describe
'#present'
do
...
...
spec/models/concerns/has_status_spec.rb
View file @
8ed7b340
...
...
@@ -270,11 +270,11 @@ describe HasStatus do
describe
'.cancelable'
do
subject
{
CommitStatus
.
cancelable
}
%i[running pending created]
.
each
do
|
status
|
%i[running pending created
scheduled
]
.
each
do
|
status
|
it_behaves_like
'containing the job'
,
status
end
%i[failed success skipped canceled]
.
each
do
|
status
|
%i[failed success skipped canceled
manual
]
.
each
do
|
status
|
it_behaves_like
'not containing the job'
,
status
end
end
...
...
@@ -290,6 +290,18 @@ describe HasStatus do
it_behaves_like
'not containing the job'
,
status
end
end
describe
'.scheduled'
do
subject
{
CommitStatus
.
scheduled
}
%i[scheduled]
.
each
do
|
status
|
it_behaves_like
'containing the job'
,
status
end
%i[failed success skipped canceled]
.
each
do
|
status
|
it_behaves_like
'not containing the job'
,
status
end
end
end
describe
'::DEFAULT_STATUS'
do
...
...
@@ -303,4 +315,38 @@ describe HasStatus do
expect
(
described_class
::
BLOCKED_STATUS
).
to
eq
%w[manual scheduled]
end
end
describe
'blocked?'
do
subject
{
object
.
blocked?
}
%w[ci_pipeline ci_stage ci_build generic_commit_status]
.
each
do
|
type
|
let
(
:object
)
{
build
(
type
,
status:
status
)
}
context
'when status is scheduled'
do
let
(
:status
)
{
:scheduled
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when status is manual'
do
let
(
:status
)
{
:manual
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when status is created'
do
let
(
:status
)
{
:created
}
it
{
is_expected
.
to
be_falsy
}
end
end
end
describe
'.status_sql'
do
subject
{
Ci
::
Build
.
status_sql
}
it
'returns SQL'
do
puts
subject
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