mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 17:13:25 +08:00
DEV: Fix topic_timer_spec (#9483)
File it under "how did it even work".
This commit is contained in:
@ -3,22 +3,11 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe TopicTimer, type: :model do
|
RSpec.describe TopicTimer, type: :model do
|
||||||
let(:topic_timer) {
|
fab!(:topic_timer) { Fabricate(:topic_timer) }
|
||||||
# we should not need to do this but somehow
|
|
||||||
# fabricator is failing here
|
|
||||||
TopicTimer.create!(
|
|
||||||
user_id: -1,
|
|
||||||
topic: Fabricate(:topic),
|
|
||||||
execute_at: 1.hour.from_now,
|
|
||||||
status_type: TopicTimer.types[:close]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
fab!(:topic) { Fabricate(:topic) }
|
fab!(:topic) { Fabricate(:topic) }
|
||||||
fab!(:admin) { Fabricate(:admin) }
|
fab!(:admin) { Fabricate(:admin) }
|
||||||
|
|
||||||
before do
|
before { freeze_time }
|
||||||
freeze_time Time.new(2018)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "validations" do
|
context "validations" do
|
||||||
describe '#status_type' do
|
describe '#status_type' do
|
||||||
@ -107,15 +96,7 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
context 'callbacks' do
|
context 'callbacks' do
|
||||||
describe 'when #execute_at and #user_id are not changed' do
|
describe 'when #execute_at and #user_id are not changed' do
|
||||||
it 'should not schedule another to update topic' do
|
it 'should not schedule another to update topic' do
|
||||||
Jobs.expects(:enqueue_at).with(
|
Jobs.expects(:enqueue_at).never
|
||||||
topic_timer.execute_at,
|
|
||||||
:toggle_topic_closed,
|
|
||||||
topic_timer_id: topic_timer.id,
|
|
||||||
state: true
|
|
||||||
).once
|
|
||||||
|
|
||||||
topic_timer
|
|
||||||
|
|
||||||
Jobs.expects(:cancel_scheduled_job).never
|
Jobs.expects(:cancel_scheduled_job).never
|
||||||
|
|
||||||
topic_timer.update!(topic: Fabricate(:topic))
|
topic_timer.update!(topic: Fabricate(:topic))
|
||||||
@ -124,9 +105,6 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
|
|
||||||
describe 'when #execute_at value is changed' do
|
describe 'when #execute_at value is changed' do
|
||||||
it 'reschedules the job' do
|
it 'reschedules the job' do
|
||||||
freeze_time
|
|
||||||
topic_timer
|
|
||||||
|
|
||||||
Jobs.expects(:cancel_scheduled_job).with(
|
Jobs.expects(:cancel_scheduled_job).with(
|
||||||
:toggle_topic_closed, topic_timer_id: topic_timer.id
|
:toggle_topic_closed, topic_timer_id: topic_timer.id
|
||||||
)
|
)
|
||||||
@ -142,9 +120,6 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
|
|
||||||
describe 'when execute_at is smaller than the current time' do
|
describe 'when execute_at is smaller than the current time' do
|
||||||
it 'should enqueue the job immediately' do
|
it 'should enqueue the job immediately' do
|
||||||
freeze_time
|
|
||||||
topic_timer
|
|
||||||
|
|
||||||
Jobs.expects(:enqueue_at).with(
|
Jobs.expects(:enqueue_at).with(
|
||||||
Time.zone.now, :toggle_topic_closed,
|
Time.zone.now, :toggle_topic_closed,
|
||||||
topic_timer_id: topic_timer.id,
|
topic_timer_id: topic_timer.id,
|
||||||
@ -161,15 +136,10 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
|
|
||||||
describe 'when user is changed' do
|
describe 'when user is changed' do
|
||||||
it 'should update the job' do
|
it 'should update the job' do
|
||||||
freeze_time
|
|
||||||
topic_timer
|
|
||||||
|
|
||||||
Jobs.expects(:cancel_scheduled_job).with(
|
Jobs.expects(:cancel_scheduled_job).with(
|
||||||
:toggle_topic_closed, topic_timer_id: topic_timer.id
|
:toggle_topic_closed, topic_timer_id: topic_timer.id
|
||||||
)
|
)
|
||||||
|
|
||||||
admin = Fabricate(:admin)
|
|
||||||
|
|
||||||
Jobs.expects(:enqueue_at).with(
|
Jobs.expects(:enqueue_at).with(
|
||||||
topic_timer.execute_at,
|
topic_timer.execute_at,
|
||||||
:toggle_topic_closed,
|
:toggle_topic_closed,
|
||||||
@ -183,8 +153,7 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
|
|
||||||
describe 'when a open topic status update is created for an open topic' do
|
describe 'when a open topic status update is created for an open topic' do
|
||||||
fab!(:topic) { Fabricate(:topic, closed: false) }
|
fab!(:topic) { Fabricate(:topic, closed: false) }
|
||||||
|
fab!(:topic_timer) do
|
||||||
let(:topic_timer) do
|
|
||||||
Fabricate(:topic_timer,
|
Fabricate(:topic_timer,
|
||||||
status_type: described_class.types[:open],
|
status_type: described_class.types[:open],
|
||||||
topic: topic
|
topic: topic
|
||||||
@ -212,8 +181,7 @@ RSpec.describe TopicTimer, type: :model do
|
|||||||
|
|
||||||
describe 'when a close topic status update is created for a closed topic' do
|
describe 'when a close topic status update is created for a closed topic' do
|
||||||
fab!(:topic) { Fabricate(:topic, closed: true) }
|
fab!(:topic) { Fabricate(:topic, closed: true) }
|
||||||
|
fab!(:topic_timer) do
|
||||||
let(:topic_timer) do
|
|
||||||
Fabricate(:topic_timer,
|
Fabricate(:topic_timer,
|
||||||
status_type: described_class.types[:close],
|
status_type: described_class.types[:close],
|
||||||
topic: topic
|
topic: topic
|
||||||
|
Reference in New Issue
Block a user