FIX: Check if post.topic exists before publishing topic updates (#11900)

This commit is contained in:
Bianca Nenciu
2021-02-09 07:41:22 +02:00
committed by GitHub
parent fcdf7ef019
commit f4db1675f3
2 changed files with 19 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ module Jobs
def execute(args)
post = Post.find_by(id: args[:post_id])
if post
if post && post.topic
TopicTrackingState.publish_unmuted(post.topic)
if post.post_number > 1
TopicTrackingState.publish_muted(post.topic)

View File

@@ -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