A platform for community discussion. Free, open, simple.
FIX: Check if post.topic exists before publishing topic updates (#11900)
Bianca Nenciuf4db1675f3b0
diff --git a/app/jobs/regular/post_update_topic_tracking_state.rb b/app/jobs/regular/post_update_topic_tracking_state.rbindex c68a67b8a28..6eaaeb288b4 100644--- a/app/jobs/regular/post_update_topic_tracking_state.rb+++ b/app/jobs/regular/post_update_topic_tracking_state.rb@@ -6,7 +6,7 @@ module Jobsdef execute(args)post = Post.find_by(id: args[:post_id])- if post+ if post && post.topicTopicTrackingState.publish_unmuted(post.topic)if post.post_number > 1TopicTrackingState.publish_muted(post.topic)diff --git a/spec/jobs/post_update_topic_tracking_state_spec.rb b/spec/jobs/post_update_topic_tracking_state_spec.rbnew file mode 100644index 00000000000..f69c1631523--- /dev/null+++ b/spec/jobs/post_update_topic_tracking_state_spec.rb@@ -0,0 +1,18 @@+# frozen_string_literal: true++require 'rails_helper'++RSpec.describe Jobs::PostUpdateTopicTrackingState do+ fab!(:post) { Fabricate(:post) }++ it 'should publish messages' do+ messages = MessageBus.track_publish { subject.execute({ post_id: post.id }) }+ expect(messages.size).not_to eq(0)+ end++ it 'should not publish messages for deleted topics' do+ post.topic.trash!+ messages = MessageBus.track_publish { subject.execute({ post_id: post.id }) }+ expect(messages.size).to eq(0)+ end+end