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
6cafb687
Commit
6cafb687
authored
Nov 11, 2016
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid the total time spent to have a negative value.
parent
09b02e66
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletion
+56
-1
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+11
-1
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+32
-0
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+13
-0
No files found.
app/models/concerns/time_trackable.rb
View file @
6cafb687
...
...
@@ -15,7 +15,7 @@ module TimeTrackable
end
def
spend_time
=
(
seconds
)
return
unless
seconds
return
if
invalid_time_spent?
(
seconds
)
new_time_spent
=
seconds
.
zero?
?
-
(
total_time_spent
)
:
seconds
timelogs
.
new
(
time_spent:
new_time_spent
)
...
...
@@ -26,4 +26,14 @@ module TimeTrackable
def
total_time_spent
timelogs
.
sum
(
:time_spent
)
end
private
def
invalid_time_spent?
(
seconds
)
return
true
unless
seconds
# time to subtract exceeds the total time spent
return
true
if
seconds
<
0
&&
(
seconds
.
abs
>
total_time_spent
)
false
end
end
spec/models/concerns/issuable_spec.rb
View file @
6cafb687
...
...
@@ -384,4 +384,36 @@ describe Issue, "Issuable" do
expect
(
issue
.
assignee_or_author?
(
user
)).
to
eq
(
false
)
end
end
describe
'#spend_time'
do
let
(
:issue
)
{
create
(
:issue
)
}
context
'adding time'
do
it
'should update the total time spent'
do
issue
.
update_attributes!
(
spend_time:
1800
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
end
context
'substracting time'
do
before
do
issue
.
update_attributes!
(
spend_time:
1800
)
end
it
'should update the total time spent'
do
issue
.
update_attributes!
(
spend_time:
-
900
)
expect
(
issue
.
total_time_spent
).
to
eq
(
900
)
end
context
'when time to substract exceeds the total time spent'
do
it
'should not alter the total time spent'
do
issue
.
update_attributes!
(
spend_time:
-
3600
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
end
end
end
end
spec/services/slash_commands/interpret_service_spec.rb
View file @
6cafb687
...
...
@@ -226,6 +226,14 @@ describe SlashCommands::InterpretService, services: true do
end
end
shared_examples
'spend command with negative time'
do
it
'populates spend_time: "-1800" if content contains /spend -30m'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
-
1800
)
end
end
shared_examples
'remove_estimation command'
do
it
'populates time_estimate: "0" if content contains /remove_estimation'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
...
...
@@ -503,6 +511,11 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'spend command with negative time'
do
let
(
:content
)
{
'/spend -30m'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
'/spend'
}
let
(
:issuable
)
{
issue
}
...
...
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