FIX: allows to remove a topic timer with delete_replies as type (#9800)

This commit is contained in:
Joffrey JAFFEUX 2020-05-18 11:47:08 +02:00 committed by GitHub
parent d01c336899
commit 918bd75909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -445,7 +445,7 @@ class TopicsController < ApplicationController
invalid_param(:status_type)
end
based_on_last_post = params[:based_on_last_post]
params.require(:duration) if based_on_last_post || TopicTimer.types[:delete_replies] == status_type
params.require(:duration) if based_on_last_post
topic = Topic.find_by(id: params[:topic_id])
guardian.ensure_can_moderate!(topic)

View File

@ -2709,6 +2709,24 @@ RSpec.describe TopicsController do
expect(json['duration']).to eq(topic_status_update.duration)
end
it 'should be able to delete a topic status update for delete_replies type' do
Fabricate(:topic_timer, topic: topic, status_type: TopicTimer.types[:delete_replies])
post "/t/#{topic.id}/timer.json", params: {
time: nil,
status_type: TopicTimer.types[7]
}
expect(response.status).to eq(200)
expect(topic.reload.public_topic_timer).to eq(nil)
json = response.parsed_body
expect(json['execute_at']).to eq(nil)
expect(json['duration']).to eq(nil)
expect(json['closed']).to eq(topic.closed)
end
describe 'publishing topic to category in the future' do
it 'should be able to create the topic status update' do
post "/t/#{topic.id}/timer.json", params: {