FEATURE: remove the timecop gem

We should only have one way of mocking time, misuse of timecop
was causing build stability issues
This commit is contained in:
Sam Saffron
2017-07-24 12:11:10 -04:00
committed by Sam
parent 40174962e2
commit 045a2abcec
35 changed files with 459 additions and 473 deletions
+25 -25
View File
@@ -21,26 +21,25 @@ describe TopicTimestampChanger do
let(:new_timestamp) { old_timestamp - 2.day }
it 'changes the timestamp of the topic and opening post' do
Timecop.freeze do
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
freeze_time
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
topic.reload
[:created_at, :updated_at, :bumped_at].each do |column|
expect(topic.public_send(column)).to be_within(1.second).of(new_timestamp)
end
p1.reload
[:created_at, :updated_at].each do |column|
expect(p1.public_send(column)).to be_within(1.second).of(new_timestamp)
end
p2.reload
[:created_at, :updated_at].each do |column|
expect(p2.public_send(column)).to be_within(1.second).of(new_timestamp + 1.day)
end
expect(topic.last_posted_at).to be_within(1.second).of(p2.reload.created_at)
topic.reload
[:created_at, :updated_at, :bumped_at].each do |column|
expect(topic.public_send(column)).to be_within(1.second).of(new_timestamp)
end
p1.reload
[:created_at, :updated_at].each do |column|
expect(p1.public_send(column)).to be_within(1.second).of(new_timestamp)
end
p2.reload
[:created_at, :updated_at].each do |column|
expect(p2.public_send(column)).to be_within(1.second).of(new_timestamp + 1.day)
end
expect(topic.last_posted_at).to be_within(1.second).of(p2.reload.created_at)
end
describe 'when posts have timestamps in the future' do
@@ -48,15 +47,16 @@ describe TopicTimestampChanger do
let(:p3) { Fabricate(:post, topic: topic, created_at: new_timestamp + 3.day) }
it 'should set the new timestamp as the default timestamp' do
Timecop.freeze do
p3
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
freeze_time
p3.reload
p3
[:created_at, :updated_at].each do |column|
expect(p3.public_send(column)).to be_within(1.second).of(new_timestamp)
end
TopicTimestampChanger.new(topic: topic, timestamp: new_timestamp.to_f).change!
p3.reload
[:created_at, :updated_at].each do |column|
expect(p3.public_send(column)).to be_within(1.second).of(new_timestamp)
end
end
end