A platform for community discussion. Free, open, simple.
FIX: Update topic route id param (#16166)
Blake Erickson02fa04e333ed
diff --git a/config/routes.rb b/config/routes.rbindex d11419c4c5e..b658b7f1ca8 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -767,7 +767,7 @@ Discourse::Application.routes.draw do# Topics resourceget "t/:id" => "topics#show"- put "t/:id" => "topics#update"+ put "t/:topic_id" => "topics#update", constraints: { topic_id: /\d+/ }delete "t/:id" => "topics#destroy"put "t/:id/archive-message" => "topics#archive_message"put "t/:id/move-to-inbox" => "topics#move_to_inbox"diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex ed2cb355663..1be67ed2b99 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1317,6 +1317,27 @@ RSpec.describe TopicsController doexpect(payload["title"]).to eq('This is a new title for the topic')end+ it 'allows update on short non-slug url' do+ put "/t/#{topic.id}.json", params: {+ title: 'This is a new title for the topic'+ }++ topic.reload+ expect(topic.title).to eq('This is a new title for the topic')+ end++ it 'only allows update on digit ids' do+ non_digit_id = "asdf"+ original_title = topic.title+ put "/t/#{non_digit_id}.json", params: {+ title: 'This is a new title for the topic'+ }++ topic.reload+ expect(topic.title).to eq(original_title)+ expect(response.status).to eq(404)+ end+it 'allows a change of then updating the OP' dotopic.update(user: user)topic.first_post.update(user: user)