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
7ef24a47
Commit
7ef24a47
authored
Feb 28, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly handle empty value for chronic duration attribute
parent
14549703
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
app/models/concerns/chronic_duration_attribute.rb
app/models/concerns/chronic_duration_attribute.rb
+7
-1
spec/models/concerns/chronic_duration_attribute_spec.rb
spec/models/concerns/chronic_duration_attribute_spec.rb
+14
-2
No files found.
app/models/concerns/chronic_duration_attribute.rb
View file @
7ef24a47
...
...
@@ -10,14 +10,20 @@ module ChronicDurationAttribute
def
chronic_duration_attr_reader
(
virtual_attribute
,
source_attribute
)
define_method
(
virtual_attribute
)
do
value
=
self
.
send
(
source_attribute
)
# rubocop:disable GitlabSecurity/PublicSend
ChronicDuration
.
output
(
value
,
format: :short
)
unless
value
.
nil?
return
''
if
value
.
nil?
ChronicDuration
.
output
(
value
,
format: :short
)
end
end
def
chronic_duration_attr_writer
(
virtual_attribute
,
source_attribute
)
define_method
(
"
#{
virtual_attribute
}
="
)
do
|
value
|
new_value
=
ChronicDuration
.
parse
(
value
).
to_i
new_value
=
nil
if
new_value
<=
0
self
.
send
(
"
#{
source_attribute
}
="
,
new_value
)
# rubocop:disable GitlabSecurity/PublicSend
new_value
end
end
...
...
spec/models/concerns/chronic_duration_attribute_spec.rb
View file @
7ef24a47
...
...
@@ -5,11 +5,17 @@ shared_examples 'ChronicDurationAttribute reader' do
expect
(
subject
.
class
).
to
be_public_method_defined
(
virtual_field
)
end
it
'outputs chronic duration formated value'
do
it
'outputs chronic duration format
t
ed value'
do
subject
.
send
(
"
#{
source_field
}
="
,
120
)
expect
(
subject
.
send
(
virtual_field
)).
to
eq
(
'2m'
)
end
it
'outputs empty string when value set to nil'
do
subject
.
send
(
"
#{
source_field
}
="
,
nil
)
expect
(
subject
.
send
(
virtual_field
)).
to
be_empty
end
end
shared_examples
'ChronicDurationAttribute writer'
do
...
...
@@ -18,10 +24,16 @@ shared_examples 'ChronicDurationAttribute writer' do
end
it
'parses chronic duration input'
do
subject
.
send
(
"
#{
virtual_field
}
="
,
"10m"
)
subject
.
send
(
"
#{
virtual_field
}
="
,
'10m'
)
expect
(
subject
.
send
(
source_field
)).
to
eq
(
600
)
end
it
'writes null when empty input is used'
do
subject
.
send
(
"
#{
virtual_field
}
="
,
''
)
expect
(
subject
.
send
(
source_field
)).
to
be_nil
end
end
describe
'ChronicDurationAttribute'
do
...
...
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