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
519d1054
Commit
519d1054
authored
Dec 05, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom validation message for chronic duration attribute
parent
c6c21dd4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
5 deletions
+12
-5
app/models/ci/runner.rb
app/models/ci/runner.rb
+2
-1
app/models/concerns/chronic_duration_attribute.rb
app/models/concerns/chronic_duration_attribute.rb
+1
-1
app/models/project.rb
app/models/project.rb
+2
-1
app/validators/duration_validator.rb
app/validators/duration_validator.rb
+5
-1
spec/models/concerns/chronic_duration_attribute_spec.rb
spec/models/concerns/chronic_duration_attribute_spec.rb
+2
-1
No files found.
app/models/ci/runner.rb
View file @
519d1054
...
...
@@ -114,7 +114,8 @@ module Ci
cached_attr_reader
:version
,
:revision
,
:platform
,
:architecture
,
:ip_address
,
:contacted_at
chronic_duration_attr
:maximum_timeout_human_readable
,
:maximum_timeout
chronic_duration_attr
:maximum_timeout_human_readable
,
:maximum_timeout
,
error_message:
'Maximum job timeout has a value which could not be accepted'
validates
:maximum_timeout
,
allow_nil:
true
,
numericality:
{
greater_than_or_equal_to:
600
,
...
...
app/models/concerns/chronic_duration_attribute.rb
View file @
519d1054
...
...
@@ -24,7 +24,7 @@ module ChronicDurationAttribute
end
end
validates
virtual_attribute
,
allow_nil:
true
,
duration:
true
validates
virtual_attribute
,
allow_nil:
true
,
duration:
{
message:
parameters
[
:error_message
]
}
end
alias_method
:chronic_duration_attr
,
:chronic_duration_attr_writer
...
...
app/models/project.rb
View file @
519d1054
...
...
@@ -384,7 +384,8 @@ class Project < ActiveRecord::Base
enum
auto_cancel_pending_pipelines:
{
disabled:
0
,
enabled:
1
}
chronic_duration_attr
:build_timeout_human_readable
,
:build_timeout
,
default:
3600
chronic_duration_attr
:build_timeout_human_readable
,
:build_timeout
,
default:
3600
,
error_message:
'Maximum job timeout has a value which could not be accepted'
validates
:build_timeout
,
allow_nil:
true
,
numericality:
{
greater_than_or_equal_to:
10
.
minutes
,
...
...
app/validators/duration_validator.rb
View file @
519d1054
...
...
@@ -14,6 +14,10 @@ class DurationValidator < ActiveModel::EachValidator
def
validate_each
(
record
,
attribute
,
value
)
ChronicDuration
.
parse
(
value
)
rescue
ChronicDuration
::
DurationParseError
record
.
errors
.
add
(
attribute
,
"is not a correct duration"
)
if
options
[
:message
]
record
.
errors
.
add
(
:base
,
options
[
:message
])
else
record
.
errors
.
add
(
attribute
,
"is not a correct duration"
)
end
end
end
spec/models/concerns/chronic_duration_attribute_spec.rb
View file @
519d1054
...
...
@@ -54,7 +54,8 @@ shared_examples 'ChronicDurationAttribute writer' do
subject
.
send
(
"
#{
virtual_field
}
="
,
'-10m'
)
expect
(
subject
.
valid?
).
to
be_falsey
expect
(
subject
.
errors
&
.
messages
).
to
include
(
virtual_field
=>
[
'is not a correct duration'
])
expect
(
subject
.
errors
&
.
messages
)
.
to
include
(
base:
[
'Maximum job timeout has a value which could not be accepted'
])
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