Commit efe82fb4 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '349040-fix-edited-timestamp-when-reacting-to-old-notes' into 'master'

Keep edited timestamp when reacting to old notes

See merge request gitlab-org/gitlab!84568
parents 61b69675 96aaeb37
......@@ -509,7 +509,15 @@ class Note < ApplicationRecord
# Instead of calling touch which is throttled via ThrottledTouch concern,
# we bump the updated_at column directly. This also prevents executing
# after_commit callbacks that we don't need.
update_column(:updated_at, Time.current)
attributes_to_update = { updated_at: Time.current }
# Notes that were edited before the `last_edited_at` column was added, fall back to `updated_at` for the edit time.
# We copy this over to the correct column so we don't erroneously change the edit timestamp.
if updated_by_id.present? && read_attribute(:last_edited_at).blank?
attributes_to_update[:last_edited_at] = updated_at
end
update_columns(attributes_to_update)
end
def expire_etag_cache
......
......@@ -1753,4 +1753,27 @@ RSpec.describe Note do
expect(note.commands_changes.keys).to contain_exactly(:emoji_award, :time_estimate, :spend_time)
end
end
describe '#bump_updated_at', :freeze_time do
it 'sets updated_at to the current timestamp' do
note = create(:note, updated_at: 1.day.ago)
note.bump_updated_at
note.reload
expect(note.updated_at).to be_like_time(Time.current)
end
context 'with legacy edited note' do
it 'copies updated_at to last_edited_at before bumping the timestamp' do
note = create(:note, updated_at: 1.day.ago, updated_by: create(:user), last_edited_at: nil)
note.bump_updated_at
note.reload
expect(note.last_edited_at).to be_like_time(1.day.ago)
expect(note.updated_at).to be_like_time(Time.current)
end
end
end
end
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