From c97244ca115c6e8d287d9c4e6033bf3e1d084f70 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Sat, 21 Mar 2020 07:33:10 -0600 Subject: [PATCH] FIX: post edited webhook does not reflect updated topic title This fix ensures that when a topic title is edited the new title shows up in the post webhook instead of the old title. Rather than passing in the old topic object to the PostRevisor the PostRevisor initializer will load the updated topic object inside of the initializer if you don't pass it in. This will allow the post_edited webhook to have the correct topic values. Original bug reported at: https://meta.discourse.org/t/post-edited-webhook-does-not-reflect-updated-topic-title/144722 --- app/controllers/topics_controller.rb | 2 +- spec/requests/topics_controller_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 0deb6b2efd..99ff5fb625 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -366,7 +366,7 @@ class TopicsController < ApplicationController if changes.length > 0 first_post = topic.ordered_posts.first - success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false) + success = PostRevisor.new(first_post).revise!(current_user, changes, validate_post: false) end # this is used to return the title to the client as it may have been changed by "TextCleaner" diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 0f0a921e9e..947d244971 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -946,6 +946,9 @@ RSpec.describe TopicsController do end describe 'with permission' do + fab!(:post_hook) { Fabricate(:post_web_hook) } + fab!(:topic_hook) { Fabricate(:topic_web_hook) } + it 'succeeds' do put "/t/#{topic.slug}/#{topic.id}.json" @@ -971,6 +974,13 @@ RSpec.describe TopicsController do topic.reload expect(topic.title).to eq('This is a new title for the topic') + + expect(Jobs::EmitWebHookEvent.jobs.length).to eq(2) + job_args = Jobs::EmitWebHookEvent.jobs[0]["args"].first + + expect(job_args["event_name"]).to eq("post_edited") + payload = JSON.parse(job_args["payload"]) + expect(payload["topic_title"]).to eq('This is a new title for the topic') end it "returns errors with invalid titles" do