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
4c878363
Commit
4c878363
authored
Jun 01, 2018
by
🙈 jacopo beschi 🙉
Committed by
Douwe Maan
Jun 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Update `updated_at` on an issue/mr on every issue/mr changes"
parent
d637fbe9
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
43 additions
and
18 deletions
+43
-18
app/models/concerns/time_trackable.rb
app/models/concerns/time_trackable.rb
+0
-6
app/models/timelog.rb
app/models/timelog.rb
+2
-2
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+4
-1
changelogs/unreleased/46478-update-updated-at-on-mr.yml
changelogs/unreleased/46478-update-updated-at-on-mr.yml
+5
-0
spec/factories/issues.rb
spec/factories/issues.rb
+1
-0
spec/fixtures/api/schemas/entities/issue.json
spec/fixtures/api/schemas/entities/issue.json
+1
-1
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+3
-2
spec/models/timelog_spec.rb
spec/models/timelog_spec.rb
+3
-0
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+10
-4
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+7
-1
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+7
-1
No files found.
app/models/concerns/time_trackable.rb
View file @
4c878363
...
@@ -30,8 +30,6 @@ module TimeTrackable
...
@@ -30,8 +30,6 @@ module TimeTrackable
return
if
@time_spent
==
0
return
if
@time_spent
==
0
touch
if
touchable?
if
@time_spent
==
:reset
if
@time_spent
==
:reset
reset_spent_time
reset_spent_time
else
else
...
@@ -59,10 +57,6 @@ module TimeTrackable
...
@@ -59,10 +57,6 @@ module TimeTrackable
private
private
def
touchable?
valid?
&&
persisted?
end
def
reset_spent_time
def
reset_spent_time
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
timelogs
.
new
(
time_spent:
total_time_spent
*
-
1
,
user:
@time_spent_user
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
end
...
...
app/models/timelog.rb
View file @
4c878363
...
@@ -2,8 +2,8 @@ class Timelog < ActiveRecord::Base
...
@@ -2,8 +2,8 @@ class Timelog < ActiveRecord::Base
validates
:time_spent
,
:user
,
presence:
true
validates
:time_spent
,
:user
,
presence:
true
validate
:issuable_id_is_present
validate
:issuable_id_is_present
belongs_to
:issue
belongs_to
:issue
,
touch:
true
belongs_to
:merge_request
belongs_to
:merge_request
,
touch:
true
belongs_to
:user
belongs_to
:user
def
issuable
def
issuable
...
...
app/services/issuable_base_service.rb
View file @
4c878363
...
@@ -183,7 +183,10 @@ class IssuableBaseService < BaseService
...
@@ -183,7 +183,10 @@ class IssuableBaseService < BaseService
old_associations
=
associations_before_update
(
issuable
)
old_associations
=
associations_before_update
(
issuable
)
label_ids
=
process_label_ids
(
params
,
existing_label_ids:
issuable
.
label_ids
)
label_ids
=
process_label_ids
(
params
,
existing_label_ids:
issuable
.
label_ids
)
params
[
:label_ids
]
=
label_ids
if
labels_changing?
(
issuable
.
label_ids
,
label_ids
)
if
labels_changing?
(
issuable
.
label_ids
,
label_ids
)
params
[
:label_ids
]
=
label_ids
issuable
.
touch
end
if
issuable
.
changed?
||
params
.
present?
if
issuable
.
changed?
||
params
.
present?
issuable
.
assign_attributes
(
params
.
merge
(
updated_by:
current_user
))
issuable
.
assign_attributes
(
params
.
merge
(
updated_by:
current_user
))
...
...
changelogs/unreleased/46478-update-updated-at-on-mr.yml
0 → 100644
View file @
4c878363
---
title
:
Updates updated_at on label changes
merge_request
:
19065
author
:
Jacopo Beschi @jacopo-beschi
type
:
fixed
spec/factories/issues.rb
View file @
4c878363
...
@@ -3,6 +3,7 @@ FactoryBot.define do
...
@@ -3,6 +3,7 @@ FactoryBot.define do
title
{
generate
(
:title
)
}
title
{
generate
(
:title
)
}
project
project
author
{
project
.
creator
}
author
{
project
.
creator
}
updated_by
{
author
}
trait
:confidential
do
trait
:confidential
do
confidential
true
confidential
true
...
...
spec/fixtures/api/schemas/entities/issue.json
View file @
4c878363
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
"due_date"
:
{
"type"
:
"date"
},
"due_date"
:
{
"type"
:
"date"
},
"confidential"
:
{
"type"
:
"boolean"
},
"confidential"
:
{
"type"
:
"boolean"
},
"discussion_locked"
:
{
"type"
:
[
"boolean"
,
"null"
]
},
"discussion_locked"
:
{
"type"
:
[
"boolean"
,
"null"
]
},
"updated_by_id"
:
{
"type"
:
[
"
string
"
,
"null"
]
},
"updated_by_id"
:
{
"type"
:
[
"
integer
"
,
"null"
]
},
"time_estimate"
:
{
"type"
:
"integer"
},
"time_estimate"
:
{
"type"
:
"integer"
},
"total_time_spent"
:
{
"type"
:
"integer"
},
"total_time_spent"
:
{
"type"
:
"integer"
},
"human_time_estimate"
:
{
"type"
:
[
"integer"
,
"null"
]
},
"human_time_estimate"
:
{
"type"
:
[
"integer"
,
"null"
]
},
...
...
spec/models/concerns/issuable_spec.rb
View file @
4c878363
...
@@ -12,6 +12,7 @@ describe Issuable do
...
@@ -12,6 +12,7 @@ describe Issuable do
it
{
is_expected
.
to
belong_to
(
:author
)
}
it
{
is_expected
.
to
belong_to
(
:author
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:todos
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:labels
)
}
context
'Notes'
do
context
'Notes'
do
let!
(
:note
)
{
create
(
:note
,
noteable:
issue
,
project:
issue
.
project
)
}
let!
(
:note
)
{
create
(
:note
,
noteable:
issue
,
project:
issue
.
project
)
}
...
@@ -274,8 +275,8 @@ describe Issuable do
...
@@ -274,8 +275,8 @@ describe Issuable do
it
'skips coercion for not Integer values'
do
it
'skips coercion for not Integer values'
do
expect
{
issue
.
time_estimate
=
nil
}.
to
change
{
issue
.
time_estimate
}.
to
(
nil
)
expect
{
issue
.
time_estimate
=
nil
}.
to
change
{
issue
.
time_estimate
}.
to
(
nil
)
expect
{
issue
.
time_estimate
=
'invalid time'
}.
not_to
raise_error
(
StandardError
)
expect
{
issue
.
time_estimate
=
'invalid time'
}.
not_to
raise_error
expect
{
issue
.
time_estimate
=
22.33
}.
not_to
raise_error
(
StandardError
)
expect
{
issue
.
time_estimate
=
22.33
}.
not_to
raise_error
end
end
end
end
...
...
spec/models/timelog_spec.rb
View file @
4c878363
...
@@ -5,6 +5,9 @@ RSpec.describe Timelog do
...
@@ -5,6 +5,9 @@ RSpec.describe Timelog do
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:issue
)
{
create
(
:issue
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
{
is_expected
.
to
belong_to
(
:issue
).
touch
(
true
)
}
it
{
is_expected
.
to
belong_to
(
:merge_request
).
touch
(
true
)
}
it
{
is_expected
.
to
be_valid
}
it
{
is_expected
.
to
be_valid
}
it
{
is_expected
.
to
validate_presence_of
(
:time_spent
)
}
it
{
is_expected
.
to
validate_presence_of
(
:time_spent
)
}
...
...
spec/requests/api/issues_spec.rb
View file @
4c878363
...
@@ -1351,19 +1351,25 @@ describe API::Issues do
...
@@ -1351,19 +1351,25 @@ describe API::Issues do
expect
(
json_response
[
'labels'
]).
to
eq
([
label
.
title
])
expect
(
json_response
[
'labels'
]).
to
eq
([
label
.
title
])
end
end
it
'removes all labels'
do
it
'removes all labels and touches the record'
do
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
"
,
user
),
labels:
''
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
"
,
user
),
labels:
''
end
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
eq
([])
expect
(
json_response
[
'labels'
]).
to
eq
([])
expect
(
json_response
[
'updated_at'
]).
to
be
>
Time
.
now
end
end
it
'updates labels'
do
it
'updates labels and touches the record'
do
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
"
,
user
),
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
"
,
user
),
labels:
'foo,bar'
labels:
'foo,bar'
end
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
include
'foo'
expect
(
json_response
[
'labels'
]).
to
include
'foo'
expect
(
json_response
[
'labels'
]).
to
include
'bar'
expect
(
json_response
[
'labels'
]).
to
include
'bar'
expect
(
json_response
[
'updated_at'
]).
to
be
>
Time
.
now
end
end
it
'allows special label names'
do
it
'allows special label names'
do
...
...
spec/services/issues/update_service_spec.rb
View file @
4c878363
...
@@ -337,12 +337,18 @@ describe Issues::UpdateService, :mailer do
...
@@ -337,12 +337,18 @@ describe Issues::UpdateService, :mailer do
context
'when the labels change'
do
context
'when the labels change'
do
before
do
before
do
Timecop
.
freeze
(
1
.
minute
.
from_now
)
do
update_issue
(
label_ids:
[
label
.
id
])
update_issue
(
label_ids:
[
label
.
id
])
end
end
end
it
'marks todos as done'
do
it
'marks todos as done'
do
expect
(
todo
.
reload
.
done?
).
to
eq
true
expect
(
todo
.
reload
.
done?
).
to
eq
true
end
end
it
'updates updated_at'
do
expect
(
issue
.
reload
.
updated_at
).
to
be
>
Time
.
now
end
end
end
end
end
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
4c878363
...
@@ -326,12 +326,18 @@ describe MergeRequests::UpdateService, :mailer do
...
@@ -326,12 +326,18 @@ describe MergeRequests::UpdateService, :mailer do
context
'when the labels change'
do
context
'when the labels change'
do
before
do
before
do
Timecop
.
freeze
(
1
.
minute
.
from_now
)
do
update_merge_request
({
label_ids:
[
label
.
id
]
})
update_merge_request
({
label_ids:
[
label
.
id
]
})
end
end
end
it
'marks pending todos as done'
do
it
'marks pending todos as done'
do
expect
(
pending_todo
.
reload
).
to
be_done
expect
(
pending_todo
.
reload
).
to
be_done
end
end
it
'updates updated_at'
do
expect
(
merge_request
.
reload
.
updated_at
).
to
be
>
Time
.
now
end
end
end
context
'when the assignee changes'
do
context
'when the assignee changes'
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