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
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
Hide 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
...
@@ -8,14 +8,14 @@ module ChronicDurationAttribute
end
end
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
)
chronic_duration_attr_reader
(
virtual_attribute
,
source_attribute
)
define_method
(
"
#{
virtual_attribute
}
="
)
do
|
value
|
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
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
)
assign_attributes
(
source_attribute
=>
new_value
)
rescue
ChronicDuration
::
DurationParseError
rescue
ChronicDuration
::
DurationParseError
# ignore error as it will be caught by validation
# ignore error as it will be caught by validation
...
...
app/models/project.rb
View file @
a52e3edd
...
@@ -326,7 +326,7 @@ class Project < ActiveRecord::Base
...
@@ -326,7 +326,7 @@ class Project < ActiveRecord::Base
enum
auto_cancel_pending_pipelines:
{
disabled:
0
,
enabled:
1
}
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
,
validates
:build_timeout
,
allow_nil:
true
,
numericality:
{
greater_than_or_equal_to:
600
,
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
...
@@ -63,8 +63,8 @@ shared_examples 'ChronicDurationAttribute writer' do
subject
.
send
(
"
#{
virtual_field
}
="
,
''
)
subject
.
send
(
"
#{
virtual_field
}
="
,
''
)
end
end
it
'writes
nil
'
do
it
'writes
default value
'
do
expect
(
subject
.
send
(
source_field
)).
to
be_nil
expect
(
subject
.
send
(
source_field
)).
to
eq
(
default_value
)
end
end
it
'passes validation'
do
it
'passes validation'
do
...
@@ -77,8 +77,8 @@ shared_examples 'ChronicDurationAttribute writer' do
...
@@ -77,8 +77,8 @@ shared_examples 'ChronicDurationAttribute writer' do
subject
.
send
(
"
#{
virtual_field
}
="
,
nil
)
subject
.
send
(
"
#{
virtual_field
}
="
,
nil
)
end
end
it
'writes
nil
'
do
it
'writes
default value
'
do
expect
(
subject
.
send
(
source_field
)).
to
be_nil
expect
(
subject
.
send
(
source_field
)).
to
eq
(
default_value
)
end
end
it
'passes validation'
do
it
'passes validation'
do
...
@@ -92,20 +92,34 @@ shared_examples 'ChronicDurationAttribute writer' do
...
@@ -92,20 +92,34 @@ shared_examples 'ChronicDurationAttribute writer' do
end
end
describe
'ChronicDurationAttribute'
do
describe
'ChronicDurationAttribute'
do
let
(
:source_field
)
{
:maximum_timeout
}
context
'when default value is not set'
do
let
(
:virtual_field
)
{
:maximum_timeout_human_readable
}
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 reader'
it_behaves_like
'ChronicDurationAttribute writer'
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
end
describe
'ChronicDurationAttribute - reader'
do
describe
'ChronicDurationAttribute - reader'
do
let
(
:source_field
)
{
:timeout
}
let
(
:source_field
)
{
:timeout
}
let
(
:virtual_field
)
{
:timeout_human_readable
}
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
it
"doesn't contain dynamically created writer method"
do
expect
(
subject
.
class
).
not_to
be_public_method_defined
(
"
#{
virtual_field
}
="
)
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