Commit e8325d76 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'retain-timelog-spent_at-time' into 'master'

Don't drop time from timelogs.spent_at

See merge request gitlab-org/gitlab!60191
parents 35b0630a 5cbfd1ac
......@@ -62,12 +62,12 @@ module SystemNotes
if time_spent == :reset
body = "removed time spent"
else
spent_at = noteable.spent_at
spent_at = noteable.spent_at&.to_date
parsed_time = Gitlab::TimeTrackingFormatter.output(time_spent.abs)
action = time_spent > 0 ? 'added' : 'subtracted'
text_parts = ["#{action} #{parsed_time} of time spent"]
text_parts << "at #{spent_at}" if spent_at
text_parts << "at #{spent_at}" if spent_at && spent_at != DateTime.current.to_date
body = text_parts.join(' ')
end
......
---
title: Retain timelog spent_at time
merge_request: 60191
author: Lee Tickett @leetickett
type: changed
......@@ -19,7 +19,7 @@ module Gitlab
def execute
return if @spend_arg.blank?
return [get_time, DateTime.now.to_date] unless date_present?
return [get_time, DateTime.current] unless date_present?
return unless valid_date?
[get_time, get_date]
......
......@@ -13,7 +13,9 @@ RSpec.describe Gitlab::QuickActions::SpendTimeAndDateSeparator do
shared_examples 'arg line with valid parameters' do
it 'return time and date array' do
expect(subject.new(valid_arg).execute).to eq(expected_response)
freeze_time do
expect(subject.new(valid_arg).execute).to eq(expected_response)
end
end
end
......@@ -53,7 +55,7 @@ RSpec.describe Gitlab::QuickActions::SpendTimeAndDateSeparator do
it_behaves_like 'arg line with valid parameters' do
let(:valid_arg) { '2m 3m 5m 1h' }
let(:time) { Gitlab::TimeTrackingFormatter.parse(valid_arg) }
let(:date) { DateTime.now.to_date }
let(:date) { DateTime.current }
let(:expected_response) { [time, date] }
end
end
......
......@@ -103,6 +103,30 @@ RSpec.describe Notes::QuickActionsService do
expect(Timelog.last.note_id).to eq(note.id)
end
end
context 'adds a system note' do
context 'when not specifying a date' do
let(:note_text) { "/spend 1h" }
it 'does not include the date' do
_, update_params = service.execute(note)
service.apply_updates(update_params, note)
expect(Note.last.note).to eq('added 1h of time spent')
end
end
context 'when specifying a date' do
let(:note_text) { "/spend 1h 2020-01-01" }
it 'does include the date' do
_, update_params = service.execute(note)
service.apply_updates(update_params, note)
expect(Note.last.note).to eq('added 1h of time spent at 2020-01-01')
end
end
end
end
end
......
......@@ -360,25 +360,29 @@ RSpec.describe QuickActions::InterpretService do
shared_examples 'spend command' do
it 'populates spend_time: 3600 if content contains /spend 1h' do
_, updates, _ = service.execute(content, issuable)
freeze_time do
_, updates, _ = service.execute(content, issuable)
expect(updates).to eq(spend_time: {
duration: 3600,
user_id: developer.id,
spent_at: DateTime.current.to_date
})
expect(updates).to eq(spend_time: {
duration: 3600,
user_id: developer.id,
spent_at: DateTime.current
})
end
end
end
shared_examples 'spend command with negative time' do
it 'populates spend_time: -7200 if content contains -120m' do
_, updates, _ = service.execute(content, issuable)
freeze_time do
_, updates, _ = service.execute(content, issuable)
expect(updates).to eq(spend_time: {
duration: -7200,
user_id: developer.id,
spent_at: DateTime.current.to_date
})
expect(updates).to eq(spend_time: {
duration: -7200,
user_id: developer.id,
spent_at: DateTime.current
})
end
end
it 'returns the spend_time message including the formatted duration and verb' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment