mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 07:53:42 +08:00
c4d7545f35
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.
71 lines
2.5 KiB
Ruby
71 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe TopicTimestampChanger do
|
|
describe "change!" do
|
|
let(:old_timestamp) { Time.zone.now }
|
|
let(:topic) { Fabricate(:topic, created_at: old_timestamp) }
|
|
let!(:p1) { Fabricate(:post, topic: topic, created_at: old_timestamp) }
|
|
let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) }
|
|
|
|
context 'new timestamp is in the future' do
|
|
let(:new_timestamp) { old_timestamp + 2.day }
|
|
|
|
it 'should raise the right error' do
|
|
expect { TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change! }
|
|
.to raise_error(TopicTimestampChanger::InvalidTimestampError)
|
|
end
|
|
end
|
|
|
|
context 'new timestamp is in the past' do
|
|
let(:new_timestamp) { old_timestamp - 2.day }
|
|
|
|
it 'changes the timestamp of the topic and opening post' do
|
|
freeze_time
|
|
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(last_post_created_at)
|
|
expect(topic.last_posted_at).to eq_time(last_post_created_at)
|
|
|
|
expect(p1.created_at).to eq_time(new_timestamp)
|
|
expect(p1.updated_at).to eq_time(new_timestamp)
|
|
|
|
expect(p2.created_at).to eq_time(new_timestamp + 1.day)
|
|
expect(p2.updated_at).to eq_time(new_timestamp + 1.day)
|
|
end
|
|
|
|
describe 'when posts have timestamps in the future' do
|
|
it 'should set the new timestamp as the default timestamp' do
|
|
new_timestamp = freeze_time
|
|
|
|
p3 = Fabricate(:post, topic: topic, created_at: new_timestamp + 3.days)
|
|
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
|
|
|
|
p3.reload
|
|
|
|
expect(p3.created_at).to eq_time(new_timestamp)
|
|
expect(p3.updated_at).to eq_time(new_timestamp)
|
|
end
|
|
end
|
|
end
|
|
|
|
it 'deletes the stats cache' do
|
|
Discourse.redis.set AdminDashboardData.stats_cache_key, "X"
|
|
Discourse.redis.set About.stats_cache_key, "X"
|
|
|
|
TopicTimestampChanger.new(topic: topic, timestamp: Time.zone.now.to_f).change!
|
|
|
|
expect(Discourse.redis.get(AdminDashboardData.stats_cache_key)).to eq(nil)
|
|
expect(Discourse.redis.get(About.stats_cache_key)).to eq(nil)
|
|
end
|
|
end
|
|
end
|