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
a52e3edd
Commit
a52e3edd
authored
Apr 04, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specify default value for Project#build_timeout
parent
909c277e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
14 deletions
+28
-14
app/models/concerns/chronic_duration_attribute.rb
app/models/concerns/chronic_duration_attribute.rb
+3
-3
app/models/project.rb
app/models/project.rb
+1
-1
spec/models/concerns/chronic_duration_attribute_spec.rb
spec/models/concerns/chronic_duration_attribute_spec.rb
+24
-10
No files found.
app/models/concerns/chronic_duration_attribute.rb
View file @
a52e3edd
...
...
@@ -8,14 +8,14 @@ module ChronicDurationAttribute
end
end
def
chronic_duration_attr_writer
(
virtual_attribute
,
source_attribute
)
def
chronic_duration_attr_writer
(
virtual_attribute
,
source_attribute
,
parameters
=
{}
)
chronic_duration_attr_reader
(
virtual_attribute
,
source_attribute
)
define_method
(
"
#{
virtual_attribute
}
="
)
do
|
value
|
chronic_duration_attributes
[
virtual_attribute
]
=
value
.
presence
||
''
chronic_duration_attributes
[
virtual_attribute
]
=
value
.
presence
||
parameters
[
:default
].
presence
.
to_s
begin
new_value
=
ChronicDuration
.
parse
(
value
).
to_i
if
value
.
present?
new_value
=
value
.
present?
?
ChronicDuration
.
parse
(
value
).
to_i
:
parameters
[
:default
].
presence
assign_attributes
(
source_attribute
=>
new_value
)
rescue
ChronicDuration
::
DurationParseError
# ignore error as it will be caught by validation
...
...
app/models/project.rb
View file @
a52e3edd
...
...
@@ -326,7 +326,7 @@ class Project < ActiveRecord::Base
enum
auto_cancel_pending_pipelines:
{
disabled:
0
,
enabled:
1
}
chronic_duration_attr
:build_timeout_human_readable
,
:build_timeout
chronic_duration_attr
:build_timeout_human_readable
,
:build_timeout
,
default:
3600
validates
:build_timeout
,
allow_nil:
true
,
numericality:
{
greater_than_or_equal_to:
600
,
...
...
spec/models/concerns/chronic_duration_attribute_spec.rb
View file @
a52e3edd
...
...
@@ -63,8 +63,8 @@ shared_examples 'ChronicDurationAttribute writer' do
subject
.
send
(
"
#{
virtual_field
}
="
,
''
)
end
it
'writes
nil
'
do
expect
(
subject
.
send
(
source_field
)).
to
be_nil
it
'writes
default value
'
do
expect
(
subject
.
send
(
source_field
)).
to
eq
(
default_value
)
end
it
'passes validation'
do
...
...
@@ -77,8 +77,8 @@ shared_examples 'ChronicDurationAttribute writer' do
subject
.
send
(
"
#{
virtual_field
}
="
,
nil
)
end
it
'writes
nil
'
do
expect
(
subject
.
send
(
source_field
)).
to
be_nil
it
'writes
default value
'
do
expect
(
subject
.
send
(
source_field
)).
to
eq
(
default_value
)
end
it
'passes validation'
do
...
...
@@ -92,20 +92,34 @@ shared_examples 'ChronicDurationAttribute writer' do
end
describe
'ChronicDurationAttribute'
do
context
'when default value is not set'
do
let
(
:source_field
)
{
:maximum_timeout
}
let
(
:virtual_field
)
{
:maximum_timeout_human_readable
}
let
(
:default_value
)
{
nil
}
subject
{
Ci
::
Runner
.
new
}
subject
{
create
(
:ci_runner
)
}
it_behaves_like
'ChronicDurationAttribute reader'
it_behaves_like
'ChronicDurationAttribute writer'
end
context
'when default value is set'
do
let
(
:source_field
)
{
:build_timeout
}
let
(
:virtual_field
)
{
:build_timeout_human_readable
}
let
(
:default_value
)
{
3600
}
subject
{
create
(
:project
)
}
it_behaves_like
'ChronicDurationAttribute reader'
it_behaves_like
'ChronicDurationAttribute writer'
end
end
describe
'ChronicDurationAttribute - reader'
do
let
(
:source_field
)
{
:timeout
}
let
(
:virtual_field
)
{
:timeout_human_readable
}
subject
{
Ci
::
BuildMetadata
.
new
}
subject
{
create
(
:ci_build
).
ensure_metadata
}
it
"doesn't contain dynamically created writer method"
do
expect
(
subject
.
class
).
not_to
be_public_method_defined
(
"
#{
virtual_field
}
="
)
...
...
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