From f3862de9fc62d4d2b957e14922931beb098a2ded Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 20 May 2019 11:41:28 +0200 Subject: [PATCH] Fixed bug: received_merge Ticket history entry has timestamp of previous history entry. --- app/models/ticket.rb | 6 ++++++ spec/models/ticket_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index ebf748bef..2b965c3f0 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -311,6 +311,12 @@ returns # quiet update of reassign of articles Ticket::Article.where(ticket_id: id).update_all(['ticket_id = ?', data[:ticket_id]]) # rubocop:disable Rails/SkipsModelValidations + # mark target ticket as updated + # otherwise the "received_merge" history entry + # will be the same as the last updated_at + # which might be a long time ago + target_ticket.updated_at = Time.zone.now + # add merge event to both ticket's history (Issue #2469 - Add information "Ticket merged" to History) target_ticket.history_log( 'received_merge', diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index a009a53ae..949a61419 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -81,6 +81,14 @@ RSpec.describe Ticket, type: :model do context 'when merging' do let(:merge_user) { create(:user) } + before do + # create target ticket early + # to avoid a race condition + # when creating the history entries + target_ticket + travel 5.minutes + end + it 'creates history entries in both the origin ticket and the target ticket' do ticket.merge_to(ticket_id: target_ticket.id, user_id: merge_user.id)