From c4d7545f356582d280ffeba2637b15392ad21fa0 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Fri, 16 Jul 2021 11:56:51 +0400 Subject: [PATCH] FIX: when updating timestamps on topic set a correct bump date (#13746) There was a bug with changing timestamps using the topic wrench button. Under some circumstances, a topic was disappearing from the top of the latest tab after changing timestamps. Steps to reproduce: - Choose a topic on the latest tab (the topic should be created some time ago, but has recent posts) - Change topic timestamps (for example, move them one day forward): - Go back to the latest tab and see that topic has disappeared. This PR fixes this. We were setting topic.bumped_at to the timestamp user specified on the modal. This is incorrect. Instead, we should be setting topic.bumped_at to the created_at timestamp of the last regular (not a whisper and so on) post on the topic. --- app/services/topic_timestamp_changer.rb | 2 +- spec/services/topic_timestamp_changer_spec.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/services/topic_timestamp_changer.rb b/app/services/topic_timestamp_changer.rb index d02cda99f48..a8d5059c4d2 100644 --- a/app/services/topic_timestamp_changer.rb +++ b/app/services/topic_timestamp_changer.rb @@ -29,6 +29,7 @@ class TopicTimestampChanger end end + @topic.reset_bumped_at update_topic(last_posted_at) yield(@topic) if block_given? @@ -48,7 +49,6 @@ class TopicTimestampChanger @topic.update( created_at: @timestamp, updated_at: @timestamp, - bumped_at: @timestamp, last_posted_at: last_posted_at ) end diff --git a/spec/services/topic_timestamp_changer_spec.rb b/spec/services/topic_timestamp_changer_spec.rb index c94cecfb921..255530f68ca 100644 --- a/spec/services/topic_timestamp_changer_spec.rb +++ b/spec/services/topic_timestamp_changer_spec.rb @@ -26,19 +26,20 @@ describe TopicTimestampChanger do TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change! topic.reload + p1.reload + p2.reload + last_post_created_at = p2.created_at + expect(topic.created_at).to eq_time(new_timestamp) expect(topic.updated_at).to eq_time(new_timestamp) - expect(topic.bumped_at).to eq_time(new_timestamp) + expect(topic.bumped_at).to eq_time(last_post_created_at) + expect(topic.last_posted_at).to eq_time(last_post_created_at) - p1.reload expect(p1.created_at).to eq_time(new_timestamp) expect(p1.updated_at).to eq_time(new_timestamp) - p2.reload expect(p2.created_at).to eq_time(new_timestamp + 1.day) expect(p2.updated_at).to eq_time(new_timestamp + 1.day) - - expect(topic.last_posted_at).to eq_time(p2.reload.created_at) end describe 'when posts have timestamps in the future' do