mirror of
https://github.com/discourse/discourse.git
synced 2025-09-12 21:10:47 +08:00
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:
parent
40174962e2
commit
045a2abcec
35 changed files with 459 additions and 473 deletions
|
@ -145,13 +145,11 @@ describe BadgeGranter do
|
|||
end
|
||||
|
||||
it 'sets granted_at' do
|
||||
time = Time.zone.now
|
||||
Timecop.freeze time
|
||||
time = 1.day.ago
|
||||
freeze_time time
|
||||
|
||||
user_badge = BadgeGranter.grant(badge, user)
|
||||
expect(user_badge.granted_at).to eq(time)
|
||||
|
||||
Timecop.return
|
||||
expect(user_badge.granted_at).to be_within(1.second).of(time)
|
||||
end
|
||||
|
||||
it 'sets granted_by if the option is present' do
|
||||
|
|
|
@ -86,15 +86,13 @@ describe PostAlerter do
|
|||
post.revise(admin, {raw: 'I made a revision'})
|
||||
|
||||
# skip this notification cause we already notified on a similar edit
|
||||
Timecop.freeze(2.hours.from_now) do
|
||||
post.revise(admin, {raw: 'I made another revision'})
|
||||
end
|
||||
freeze_time 2.hours.from_now
|
||||
post.revise(admin, {raw: 'I made another revision'})
|
||||
|
||||
post.revise(Fabricate(:admin), {raw: 'I made a revision'})
|
||||
|
||||
Timecop.freeze(4.hours.from_now) do
|
||||
post.revise(admin, {raw: 'I made another revision'})
|
||||
end
|
||||
freeze_time 2.hours.from_now
|
||||
post.revise(admin, {raw: 'I made another revision'})
|
||||
|
||||
expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(3)
|
||||
end
|
||||
|
@ -147,9 +145,8 @@ describe PostAlerter do
|
|||
admin2 = Fabricate(:admin)
|
||||
|
||||
# Travel 1 hour in time to test that order post_actions by `created_at`
|
||||
Timecop.freeze(1.hour.from_now) do
|
||||
PostAction.act(admin2, post, PostActionType.types[:like])
|
||||
end
|
||||
freeze_time 1.hour.from_now
|
||||
PostAction.act(admin2, post, PostActionType.types[:like])
|
||||
|
||||
expect(Notification.where(post_number: 1, topic_id: post.topic_id).count)
|
||||
.to eq(1)
|
||||
|
@ -187,10 +184,10 @@ describe PostAlerter do
|
|||
admin3 = Fabricate(:admin)
|
||||
PostAction.act(admin3, post, PostActionType.types[:like])
|
||||
|
||||
Timecop.freeze(2.days.from_now) do
|
||||
admin4 = Fabricate(:admin)
|
||||
PostAction.act(admin4, post, PostActionType.types[:like])
|
||||
end
|
||||
freeze_time 2.days.from_now
|
||||
|
||||
admin4 = Fabricate(:admin)
|
||||
PostAction.act(admin4, post, PostActionType.types[:like])
|
||||
|
||||
# first happend within the same day, no need to notify
|
||||
expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(2)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue