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
22d8460b
Commit
22d8460b
authored
Jul 04, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some validations to persisted stage model
parent
a17c90b2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
8 deletions
+11
-8
app/models/ci/stage.rb
app/models/ci/stage.rb
+5
-0
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+4
-8
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+2
-0
No files found.
app/models/ci/stage.rb
View file @
22d8460b
module
Ci
module
Ci
class
Stage
<
ActiveRecord
::
Base
class
Stage
<
ActiveRecord
::
Base
extend
Ci
::
Model
extend
Ci
::
Model
include
Importable
include
HasStatus
include
HasStatus
enumerated_status!
enumerated_status!
...
@@ -10,5 +11,9 @@ module Ci
...
@@ -10,5 +11,9 @@ module Ci
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
has_many
:statuses
,
class_name:
'CommitStatus'
,
foreign_key: :commit_id
has_many
:builds
,
foreign_key: :commit_id
has_many
:builds
,
foreign_key: :commit_id
validates
:project
,
presence:
true
,
unless: :importing?
validates
:pipeline
,
presence:
true
,
unless: :importing?
validates
:name
,
presence:
true
,
unless: :importing?
end
end
end
end
app/models/concerns/has_status.rb
View file @
22d8460b
...
@@ -12,6 +12,10 @@ module HasStatus
...
@@ -12,6 +12,10 @@ module HasStatus
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}
class_methods
do
class_methods
do
def
enumerated_status!
enum
status:
HasStatus
::
STATUSES_ENUM
end
def
status_sql
def
status_sql
scope_relevant
=
respond_to?
(
:exclude_ignored
)
?
exclude_ignored
:
all
scope_relevant
=
respond_to?
(
:exclude_ignored
)
?
exclude_ignored
:
all
scope_warnings
=
respond_to?
(
:failed_but_allowed
)
?
failed_but_allowed
:
none
scope_warnings
=
respond_to?
(
:failed_but_allowed
)
?
failed_but_allowed
:
none
...
@@ -56,14 +60,6 @@ module HasStatus
...
@@ -56,14 +60,6 @@ module HasStatus
def
all_state_names
def
all_state_names
state_machines
.
values
.
flat_map
(
&
:states
).
flat_map
{
|
s
|
s
.
map
(
&
:name
)
}
state_machines
.
values
.
flat_map
(
&
:states
).
flat_map
{
|
s
|
s
.
map
(
&
:name
)
}
end
end
private
def
enumerated_status!
@status_strategy
=
:enumerator
enum
status:
HasStatus
::
STATUSES_ENUM
end
end
end
included
do
included
do
...
...
spec/factories/ci/stages.rb
View file @
22d8460b
...
@@ -19,6 +19,8 @@ FactoryGirl.define do
...
@@ -19,6 +19,8 @@ FactoryGirl.define do
factory
:ci_stage_entity
,
class:
Ci
::
Stage
do
factory
:ci_stage_entity
,
class:
Ci
::
Stage
do
project
factory: :empty_project
project
factory: :empty_project
pipeline
factory: :ci_empty_pipeline
pipeline
factory: :ci_empty_pipeline
name
'test'
status
'pending'
status
'pending'
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