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.
This commit is contained in:
parent
207c3085fc
commit
c4d7545f35
|
@ -29,6 +29,7 @@ class TopicTimestampChanger
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@topic.reset_bumped_at
|
||||||
update_topic(last_posted_at)
|
update_topic(last_posted_at)
|
||||||
|
|
||||||
yield(@topic) if block_given?
|
yield(@topic) if block_given?
|
||||||
|
@ -48,7 +49,6 @@ class TopicTimestampChanger
|
||||||
@topic.update(
|
@topic.update(
|
||||||
created_at: @timestamp,
|
created_at: @timestamp,
|
||||||
updated_at: @timestamp,
|
updated_at: @timestamp,
|
||||||
bumped_at: @timestamp,
|
|
||||||
last_posted_at: last_posted_at
|
last_posted_at: last_posted_at
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,19 +26,20 @@ describe TopicTimestampChanger do
|
||||||
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
|
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
|
||||||
|
|
||||||
topic.reload
|
topic.reload
|
||||||
|
p1.reload
|
||||||
|
p2.reload
|
||||||
|
last_post_created_at = p2.created_at
|
||||||
|
|
||||||
expect(topic.created_at).to eq_time(new_timestamp)
|
expect(topic.created_at).to eq_time(new_timestamp)
|
||||||
expect(topic.updated_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.created_at).to eq_time(new_timestamp)
|
||||||
expect(p1.updated_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.created_at).to eq_time(new_timestamp + 1.day)
|
||||||
expect(p2.updated_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
|
end
|
||||||
|
|
||||||
describe 'when posts have timestamps in the future' do
|
describe 'when posts have timestamps in the future' do
|
||||||
|
|
Loading…
Reference in New Issue