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
a17c90b2
Commit
a17c90b2
authored
Jul 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use enumerated status in persisted stage class
parent
f9228f6b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
2 deletions
+43
-2
app/models/ci/stage.rb
app/models/ci/stage.rb
+3
-0
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+10
-0
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+6
-0
spec/migrations/migrate_stages_statuses_spec.rb
spec/migrations/migrate_stages_statuses_spec.rb
+3
-2
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+21
-0
No files found.
app/models/ci/stage.rb
View file @
a17c90b2
module
Ci
class
Stage
<
ActiveRecord
::
Base
extend
Ci
::
Model
include
HasStatus
enumerated_status!
belongs_to
:project
belongs_to
:pipeline
...
...
app/models/concerns/has_status.rb
View file @
a17c90b2
...
...
@@ -8,6 +8,8 @@ module HasStatus
ACTIVE_STATUSES
=
%w[pending running]
.
freeze
COMPLETED_STATUSES
=
%w[success failed canceled skipped]
.
freeze
ORDERED_STATUSES
=
%w[failed pending running manual canceled success skipped created]
.
freeze
STATUSES_ENUM
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
class_methods
do
def
status_sql
...
...
@@ -54,6 +56,14 @@ module HasStatus
def
all_state_names
state_machines
.
values
.
flat_map
(
&
:states
).
flat_map
{
|
s
|
s
.
map
(
&
:name
)
}
end
private
def
enumerated_status!
@status_strategy
=
:enumerator
enum
status:
HasStatus
::
STATUSES_ENUM
end
end
included
do
...
...
spec/factories/ci/stages.rb
View file @
a17c90b2
...
...
@@ -15,4 +15,10 @@ FactoryGirl.define do
warnings:
warnings
)
end
end
factory
:ci_stage_entity
,
class:
Ci
::
Stage
do
project
factory: :empty_project
pipeline
factory: :ci_empty_pipeline
status
'pending'
end
end
spec/migrations/migrate_stages_statuses_spec.rb
View file @
a17c90b2
...
...
@@ -9,7 +9,6 @@ describe MigrateStagesStatuses, :migration do
STATUSES
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
STAGES
=
{
test:
1
,
build:
2
,
deploy:
3
}
before
do
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
...
...
@@ -42,8 +41,10 @@ describe MigrateStagesStatuses, :migration do
end
def
create_job
(
project
:,
pipeline
:,
stage
:,
status
:,
**
opts
)
stages
=
{
test:
1
,
build:
2
,
deploy:
3
}
jobs
.
create!
(
project_id:
project
,
commit_id:
pipeline
,
stage_idx:
STAGES
[
stage
.
to_sym
],
stage:
stage
,
stage_idx:
stages
[
stage
.
to_sym
],
stage:
stage
,
status:
status
,
**
opts
)
end
end
spec/models/ci/stage_spec.rb
0 → 100644
View file @
a17c90b2
require
'spec_helper'
describe
Ci
::
Stage
,
:models
do
describe
'#status'
do
context
'when stage is pending'
do
let
(
:stage
)
{
create
(
:ci_stage_entity
,
status:
'pending'
)
}
it
'has a correct status value'
do
expect
(
stage
.
status
).
to
eq
'pending'
end
end
context
'when stage is success'
do
let
(
:stage
)
{
create
(
:ci_stage_entity
,
status:
'success'
)
}
it
'has a correct status value'
do
expect
(
stage
.
status
).
to
eq
'success'
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