mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:03:44 +08:00
9ebabc1de8
Previously we would bypass touching `Topic.updated_at` for whispers and post recovery / deletions. This meant that certain types of caching can not be done where we rely on this information for cache accuracy. For example if we know we have zero unread topics as of yesterday and whisper is made I need to bump this date so the cache remains accurate This is only half of a larger change but provides the groundwork. Confirmed none of our serializers leak out Topic.updated_at so this is safe spot for this info At the moment edits still do not change this but it is not relevant for the unread cache. This commit also cleans up some specs to use the new `eq_time` matcher for millisecond fidelity comparison of times Previously `freeze_time` would fudge this which is not that clean.
101 lines
2.5 KiB
Ruby
101 lines
2.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Jobs::ToggleTopicClosed do
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:topic) do
|
|
Fabricate(:topic_timer, user: admin).topic
|
|
end
|
|
|
|
it 'should be able to close a topic' do
|
|
topic
|
|
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: true
|
|
)
|
|
|
|
expect(topic.reload.closed).to eq(true)
|
|
|
|
expect(Post.last.raw).to eq(I18n.t(
|
|
'topic_statuses.autoclosed_enabled_minutes', count: 61
|
|
))
|
|
end
|
|
end
|
|
|
|
describe 'opening a topic' do
|
|
it 'should be work' do
|
|
topic.update!(closed: true)
|
|
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: false
|
|
)
|
|
|
|
expect(topic.reload.closed).to eq(false)
|
|
|
|
expect(Post.last.raw).to eq(I18n.t(
|
|
'topic_statuses.autoclosed_disabled_minutes', count: 61
|
|
))
|
|
end
|
|
end
|
|
|
|
describe 'when category has auto close configured' do
|
|
let(:category) { Fabricate(:category, auto_close_hours: 5) }
|
|
let(:topic) { Fabricate(:topic, category: category, closed: true) }
|
|
|
|
it "should restore the category's auto close timer" do
|
|
Fabricate(:topic_timer,
|
|
status_type: TopicTimer.types[:open],
|
|
topic: topic,
|
|
user: admin
|
|
)
|
|
|
|
freeze_time(61.minutes.from_now) do
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: false
|
|
)
|
|
|
|
expect(topic.reload.closed).to eq(false)
|
|
|
|
topic_timer = topic.public_topic_timer
|
|
|
|
expect(topic_timer.status_type).to eq(TopicTimer.types[:close])
|
|
expect(topic_timer.execute_at).to eq_time(5.hours.from_now)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'when trying to close a topic that has been deleted' do
|
|
it 'should not do anything' do
|
|
topic.trash!
|
|
|
|
Topic.any_instance.expects(:update_status).never
|
|
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: true
|
|
)
|
|
end
|
|
end
|
|
|
|
describe 'when user is not authorized to close topics' do
|
|
let(:topic) do
|
|
Fabricate(:topic_timer, execute_at: 2.hours.from_now).topic
|
|
end
|
|
|
|
it 'should not do anything' do
|
|
described_class.new.execute(
|
|
topic_timer_id: topic.public_topic_timer.id,
|
|
state: false
|
|
)
|
|
|
|
expect(topic.reload.closed).to eq(false)
|
|
end
|
|
end
|
|
end
|