2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2015-07-25 12:06:49 -04:00
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
describe TopicTimestampChanger do
|
2015-07-25 12:06:49 -04:00
|
|
|
describe "change!" do
|
|
|
|
let(:old_timestamp) { Time.zone.now }
|
|
|
|
let(:new_timestamp) { old_timestamp + 1.day }
|
|
|
|
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) }
|
|
|
|
let(:params) { { topic_id: topic.id, timestamp: new_timestamp.to_f } }
|
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
context 'new timestamp is in the future' do
|
|
|
|
let(:new_timestamp) { old_timestamp + 2.day }
|
2015-07-25 12:06:49 -04:00
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
it 'changes the timestamp of the topic and opening post' do
|
|
|
|
Timecop.freeze do
|
|
|
|
TopicTimestampChanger.new(params).change!
|
2015-07-25 12:06:49 -04:00
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
topic.reload
|
|
|
|
[:created_at, :updated_at, :bumped_at].each do |column|
|
|
|
|
expect(topic.public_send(column)).to be_within_one_second_of(new_timestamp)
|
|
|
|
end
|
|
|
|
|
|
|
|
p1.reload
|
|
|
|
[:created_at, :updated_at].each do |column|
|
|
|
|
expect(p1.public_send(column)).to be_within_one_second_of(new_timestamp)
|
|
|
|
end
|
2015-10-19 22:12:52 -04:00
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
expect(topic.last_posted_at).to be_within_one_second_of(p2.reload.created_at)
|
|
|
|
end
|
|
|
|
end
|
2015-07-25 12:06:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'predated timestamp' do
|
|
|
|
it 'updates the timestamp of posts in the topic with the time difference applied' do
|
2017-05-22 03:01:33 -04:00
|
|
|
TopicTimestampChanger.new(params).change!
|
2015-07-25 12:06:49 -04:00
|
|
|
|
|
|
|
p2.reload
|
|
|
|
[:created_at, :updated_at].each do |column|
|
2015-08-21 22:09:55 -04:00
|
|
|
expect(p2.public_send(column)).to be_within_one_second_of(old_timestamp + 2.day)
|
2015-07-25 12:06:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'backdated timestamp' do
|
|
|
|
let(:new_timestamp) { old_timestamp - 1.day }
|
|
|
|
|
|
|
|
it 'updates the timestamp of posts in the topic with the time difference applied' do
|
2017-05-22 03:01:33 -04:00
|
|
|
TopicTimestampChanger.new(params).change!
|
2015-07-25 12:06:49 -04:00
|
|
|
|
|
|
|
p2.reload
|
|
|
|
[:created_at, :updated_at].each do |column|
|
2015-08-21 22:09:55 -04:00
|
|
|
expect(p2.public_send(column)).to be_within_one_second_of(old_timestamp)
|
2015-07-25 12:06:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes the stats cache' do
|
2017-03-20 16:15:23 -04:00
|
|
|
$redis.set AdminDashboardData.stats_cache_key, "X"
|
|
|
|
$redis.set About.stats_cache_key, "X"
|
|
|
|
|
2017-05-22 03:01:33 -04:00
|
|
|
TopicTimestampChanger.new(params).change!
|
2017-03-20 16:15:23 -04:00
|
|
|
|
|
|
|
expect($redis.get(AdminDashboardData.stats_cache_key)).to eq(nil)
|
|
|
|
expect($redis.get(About.stats_cache_key)).to eq(nil)
|
2015-07-25 12:06:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|