mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FEATURE: Allow admin to auto reopen at topic.
* This commit also introduces a `TopicStatusUpdate` model to support other forms of deferred topic status update in the future.
This commit is contained in:
@ -1112,82 +1112,6 @@ describe TopicsController do
|
||||
|
||||
end
|
||||
|
||||
describe 'autoclose' do
|
||||
|
||||
it 'needs you to be logged in' do
|
||||
expect {
|
||||
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false
|
||||
}.to raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
it 'needs you to be an admin or mod' do
|
||||
log_in
|
||||
xhr :put, :autoclose, topic_id: 99, auto_close_time: '24', auto_close_based_on_last_post: false
|
||||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
before do
|
||||
@admin = log_in(:admin)
|
||||
@topic = Fabricate(:topic, user: @admin)
|
||||
end
|
||||
|
||||
it "can set a topic's auto close time and 'based on last post' property" do
|
||||
Topic.any_instance.expects(:set_auto_close).with("24", {by_user: @admin, timezone_offset: -240})
|
||||
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: '24', auto_close_based_on_last_post: true, timezone_offset: -240
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json).to have_key('auto_close_at')
|
||||
expect(json).to have_key('auto_close_hours')
|
||||
end
|
||||
|
||||
it "can remove a topic's auto close time" do
|
||||
Topic.any_instance.expects(:set_auto_close).with(nil, anything)
|
||||
xhr :put, :autoclose, topic_id: @topic.id, auto_close_time: nil, auto_close_based_on_last_post: false, timezone_offset: -240
|
||||
end
|
||||
|
||||
it "will close a topic when the time expires" do
|
||||
topic = Fabricate(:topic)
|
||||
Timecop.freeze(20.hours.ago) do
|
||||
create_post(topic: topic, raw: "This is the body of my cool post in the topic, but it's a bit old now")
|
||||
end
|
||||
topic.save
|
||||
|
||||
Jobs.expects(:enqueue_at).at_least_once
|
||||
xhr :put, :autoclose, topic_id: topic.id, auto_close_time: 24, auto_close_based_on_last_post: true
|
||||
|
||||
topic.reload
|
||||
expect(topic.closed).to eq(false)
|
||||
expect(topic.posts.last.raw).to match(/cool post/)
|
||||
|
||||
Timecop.freeze(5.hours.from_now) do
|
||||
Jobs::CloseTopic.new.execute({topic_id: topic.id, user_id: @admin.id})
|
||||
end
|
||||
|
||||
topic.reload
|
||||
expect(topic.closed).to eq(true)
|
||||
expect(topic.posts.last.raw).to match(/automatically closed/)
|
||||
end
|
||||
|
||||
it "will immediately close if the last post is old enough" do
|
||||
topic = Fabricate(:topic)
|
||||
Timecop.freeze(20.hours.ago) do
|
||||
create_post(topic: topic)
|
||||
end
|
||||
topic.save
|
||||
Topic.reset_highest(topic.id)
|
||||
topic.reload
|
||||
|
||||
xhr :put, :autoclose, topic_id: topic.id, auto_close_time: 10, auto_close_based_on_last_post: true
|
||||
|
||||
topic.reload
|
||||
expect(topic.closed).to eq(true)
|
||||
expect(topic.posts.last.raw).to match(/after the last reply/)
|
||||
expect(topic.posts.last.raw).to match(/10 hours/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'make_banner' do
|
||||
|
||||
it 'needs you to be a staff member' do
|
||||
|
Reference in New Issue
Block a user