FEATURE: Automatically disable slow mode. (#11461)

Staff and TL4 users can decide the slow mode duration. We'll internally set a topic timer to disable it.
This commit is contained in:
Roman Rizzi
2020-12-14 14:06:50 -03:00
committed by GitHub
parent 773c51a633
commit c7b9f044a4
10 changed files with 115 additions and 6 deletions

View File

@ -3227,6 +3227,54 @@ RSpec.describe TopicsController do
expect(topic.slow_mode_seconds).to eq(3600)
end
end
context 'auto-disable slow mode' do
before { sign_in(admin) }
let(:timestamp) { 1.week.from_now.to_formatted_s(:iso8601) }
it 'sets a topic timer to clear the slow mode automatically' do
put "/t/#{topic.id}/slow_mode.json", params: {
seconds: '3600', enabled_until: timestamp
}
created_timer = TopicTimer.find_by(topic: topic)
execute_at = created_timer.execute_at.to_formatted_s(:iso8601)
expect(execute_at).to eq(timestamp)
end
it 'deletes the topic timer' do
put "/t/#{topic.id}/slow_mode.json", params: {
seconds: '3600', enabled_until: timestamp
}
put "/t/#{topic.id}/slow_mode.json", params: {
seconds: '0', enabled_until: timestamp
}
created_timer = TopicTimer.find_by(topic: topic)
expect(created_timer).to be_nil
end
it 'updates the existing timer' do
put "/t/#{topic.id}/slow_mode.json", params: {
seconds: '3600', enabled_until: timestamp
}
updated_timestamp = 1.hour.from_now.to_formatted_s(:iso8601)
put "/t/#{topic.id}/slow_mode.json", params: {
seconds: '3600', enabled_until: updated_timestamp
}
created_timer = TopicTimer.find_by(topic: topic)
execute_at = created_timer.execute_at.to_formatted_s(:iso8601)
expect(execute_at).to eq(updated_timestamp)
end
end
end
describe '#invite' do