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
890dc39e
Commit
890dc39e
authored
6 years ago
by
Jacopo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates updated_at on issue when using /spend quick action
parent
533593e9
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
9 deletions
+48
-9
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+6
-0
changelogs/unreleased/45442-updates-updated-at-to-issue-on-time-spent.yml
...eased/45442-updates-updated-at-to-issue-on-time-spent.yml
+5
-0
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+15
-3
spec/support/api/time_tracking_shared_examples.rb
spec/support/api/time_tracking_shared_examples.rb
+22
-6
No files found.
app/models/concerns/time_trackable.rb
View file @
890dc39e
...
...
@@ -30,6 +30,8 @@ module TimeTrackable
return
if
@time_spent
==
0
touch
if
touchable?
if
@time_spent
==
:reset
reset_spent_time
else
...
...
@@ -53,6 +55,10 @@ module TimeTrackable
private
def
touchable?
valid?
&&
persisted?
end
def
reset_spent_time
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
...
...
This diff is collapsed.
Click to expand it.
changelogs/unreleased/45442-updates-updated-at-to-issue-on-time-spent.yml
0 → 100644
View file @
890dc39e
---
title
:
Updates updated_at on issuable when setting time spent
merge_request
:
18757
author
:
Jacopo Beschi @jacopo-beschi
type
:
added
This diff is collapsed.
Click to expand it.
spec/models/concerns/issuable_spec.rb
View file @
890dc39e
...
...
@@ -495,6 +495,14 @@ describe Issuable do
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
it
'updates issues updated_at'
do
issue
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
{
spend_time
(
1800
)
}.
to
change
{
issue
.
updated_at
}
end
end
end
context
'substracting time'
do
...
...
@@ -510,9 +518,13 @@ describe Issuable do
context
'when time to substract exceeds the total time spent'
do
it
'raise a validation error'
do
expect
do
spend_time
(
-
3600
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
do
expect
do
spend_time
(
-
3600
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
.
not_to
change
{
issue
.
updated_at
}
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/support/api/time_tracking_shared_examples.rb
View file @
890dc39e
...
...
@@ -70,8 +70,12 @@ shared_examples 'time tracking endpoints' do |issuable_name|
end
it
"add spent time for
#{
issuable_name
}
"
do
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/add_spent_time"
,
user
),
duration:
'2h'
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/add_spent_time"
,
user
),
duration:
'2h'
end
.
to
change
{
issuable
.
reload
.
updated_at
}
end
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'human_total_time_spent'
]).
to
eq
(
'2h'
)
...
...
@@ -79,7 +83,11 @@ shared_examples 'time tracking endpoints' do |issuable_name|
context
'when subtracting time'
do
it
'subtracts time of the total spent time'
do
issuable
.
update_attributes!
(
spend_time:
{
duration:
7200
,
user_id:
user
.
id
})
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
do
issuable
.
update_attributes!
(
spend_time:
{
duration:
7200
,
user_id:
user
.
id
})
end
.
to
change
{
issuable
.
reload
.
updated_at
}
end
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/add_spent_time"
,
user
),
duration:
'-1h'
...
...
@@ -93,8 +101,12 @@ shared_examples 'time tracking endpoints' do |issuable_name|
it
'does not modify the total time spent'
do
issuable
.
update_attributes!
(
spend_time:
{
duration:
7200
,
user_id:
user
.
id
})
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/add_spent_time"
,
user
),
duration:
'-1w'
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/add_spent_time"
,
user
),
duration:
'-1w'
end
.
not_to
change
{
issuable
.
reload
.
updated_at
}
end
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
json_response
[
'message'
][
'time_spent'
].
first
).
to
match
(
/exceeds the total time spent/
)
...
...
@@ -110,7 +122,11 @@ shared_examples 'time tracking endpoints' do |issuable_name|
end
it
"resets spent time for
#{
issuable_name
}
"
do
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/reset_spent_time"
,
user
)
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/
#{
issuable_collection_name
}
/
#{
issuable
.
iid
}
/reset_spent_time"
,
user
)
end
.
to
change
{
issuable
.
reload
.
updated_at
}
end
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'total_time_spent'
]).
to
eq
(
0
)
...
...
This diff is collapsed.
Click to expand it.
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