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
220663f2
Commit
220663f2
authored
Nov 11, 2016
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a reference to the User who registered the time spent.
parent
6cafb687
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
18 deletions
+31
-18
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+11
-7
app/models/timelog.rb
app/models/timelog.rb
+1
-0
app/services/slash_commands/interpret_service.rb
app/services/slash_commands/interpret_service.rb
+5
-2
db/migrate/20161030020610_create_timelogs.rb
db/migrate/20161030020610_create_timelogs.rb
+2
-0
db/schema.rb
db/schema.rb
+2
-0
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+5
-4
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+5
-5
No files found.
app/models/concerns/time_trackable.rb
View file @
220663f2
...
...
@@ -14,11 +14,13 @@ module TimeTrackable
alias_method
:time_spent?
,
:time_spent
end
def
spend_time
=
(
second
s
)
return
if
invalid_time_spent?
(
second
s
)
def
spend_time
=
(
arg
s
)
return
unless
valid_spend_time_args?
(
arg
s
)
seconds
=
args
[
:seconds
]
new_time_spent
=
seconds
.
zero?
?
-
(
total_time_spent
)
:
seconds
timelogs
.
new
(
time_spent:
new_time_spent
)
timelogs
.
new
(
user:
args
[
:user
],
time_spent:
new_time_spent
)
@time_spent
=
seconds
end
...
...
@@ -29,11 +31,13 @@ module TimeTrackable
private
def
invalid_time_spent?
(
seconds
)
return
true
unless
seconds
def
valid_spend_time_args?
(
args
)
return
false
unless
[
:seconds
,
:user
].
all?
{
|
k
|
args
.
key?
(
k
)
}
# time to subtract exceeds the total time spent
return
true
if
seconds
<
0
&&
(
seconds
.
abs
>
total_time_spent
)
seconds
=
args
[
:seconds
]
return
false
if
seconds
<
0
&&
(
seconds
.
abs
>
total_time_spent
)
fals
e
tru
e
end
end
app/models/timelog.rb
View file @
220663f2
...
...
@@ -2,4 +2,5 @@ class Timelog < ActiveRecord::Base
validates
:time_spent
,
presence:
true
belongs_to
:trackable
,
polymorphic:
true
belongs_to
:user
end
app/services/slash_commands/interpret_service.rb
View file @
220663f2
...
...
@@ -271,7 +271,10 @@ module SlashCommands
time_spent
=
ChronicDuration
.
parse
(
raw_duration
,
default_unit:
'hours'
)
rescue
nil
if
time_spent
@updates
[
:spend_time
]
=
reduce_time
?
(
time_spent
*
-
1
)
:
time_spent
@updates
[
:spend_time
]
=
{
seconds:
reduce_time
?
(
time_spent
*
-
1
)
:
time_spent
,
user:
current_user
}
end
end
...
...
@@ -290,7 +293,7 @@ module SlashCommands
current_user
.
can?
(
:"admin_
#{
issuable
.
to_ability_name
}
"
,
project
)
end
command
:remove_time_spent
do
@updates
[
:spend_time
]
=
0
@updates
[
:spend_time
]
=
{
seconds:
0
,
user:
current_user
}
end
def
find_label_ids
(
labels_param
)
...
...
db/migrate/20161030020610_create_timelogs.rb
View file @
220663f2
...
...
@@ -7,10 +7,12 @@ class CreateTimelogs < ActiveRecord::Migration
create_table
:timelogs
do
|
t
|
t
.
integer
:time_spent
,
null:
false
t
.
references
:trackable
,
polymorphic:
true
t
.
references
:user
t
.
timestamps
null:
false
end
add_index
:timelogs
,
[
:trackable_type
,
:trackable_id
]
add_index
:timelogs
,
:user_id
end
end
db/schema.rb
View file @
220663f2
...
...
@@ -1257,11 +1257,13 @@ ActiveRecord::Schema.define(version: 20161106185620) do
t
.
integer
"time_spent"
,
null:
false
t
.
integer
"trackable_id"
t
.
string
"trackable_type"
t
.
integer
"user_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
add_index
"timelogs"
,
[
"trackable_type"
,
"trackable_id"
],
name:
"index_timelogs_on_trackable_type_and_trackable_id"
,
using: :btree
add_index
"timelogs"
,
[
"user_id"
],
name:
"index_timelogs_on_user_id"
,
using: :btree
create_table
"todos"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
,
null:
false
...
...
spec/models/concerns/issuable_spec.rb
View file @
220663f2
...
...
@@ -386,11 +386,12 @@ describe Issue, "Issuable" do
end
describe
'#spend_time'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
)
}
context
'adding time'
do
it
'should update the total time spent'
do
issue
.
update_attributes!
(
spend_time:
1800
)
issue
.
update_attributes!
(
spend_time:
{
seconds:
1800
,
user:
user
}
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
...
...
@@ -398,18 +399,18 @@ describe Issue, "Issuable" do
context
'substracting time'
do
before
do
issue
.
update_attributes!
(
spend_time:
1800
)
issue
.
update_attributes!
(
spend_time:
{
seconds:
1800
,
user:
user
}
)
end
it
'should update the total time spent'
do
issue
.
update_attributes!
(
spend_time:
-
900
)
issue
.
update_attributes!
(
spend_time:
{
seconds:
-
900
,
user:
user
}
)
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
)
issue
.
update_attributes!
(
spend_time:
{
seconds:
-
3600
,
user:
user
}
)
expect
(
issue
.
total_time_spent
).
to
eq
(
1800
)
end
...
...
spec/services/slash_commands/interpret_service_spec.rb
View file @
220663f2
...
...
@@ -219,18 +219,18 @@ describe SlashCommands::InterpretService, services: true do
end
shared_examples
'spend command'
do
it
'populates spend_time:
"3600"
if content contains /spend 1h'
do
it
'populates spend_time:
{ seconds: 3600, user: user }
if content contains /spend 1h'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
3600
)
expect
(
updates
).
to
eq
(
spend_time:
{
seconds:
3600
,
user:
developer
}
)
end
end
shared_examples
'spend command with negative time'
do
it
'populates spend_time:
"-1800"
if content contains /spend -30m'
do
it
'populates spend_time:
{ seconds: -1800, user: user }
if content contains /spend -30m'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
-
1800
)
expect
(
updates
).
to
eq
(
spend_time:
{
seconds:
-
1800
,
user:
developer
}
)
end
end
...
...
@@ -246,7 +246,7 @@ describe SlashCommands::InterpretService, services: true do
it
'populates spend_time: "0" if content contains /remove_time_spent'
do
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
spend_time:
0
)
expect
(
updates
).
to
eq
(
spend_time:
{
seconds:
0
,
user:
developer
}
)
end
end
...
...
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