From 06bcfc587c7478c5d9c164a43cd36604ede38261 Mon Sep 17 00:00:00 2001 From: David Battersby Date: Tue, 18 Feb 2025 11:09:05 +0400 Subject: [PATCH] FIX: skip notifications when topic is not found --- lib/discourse_assign/create_notification.rb | 1 + .../discourse_assign/create_notification_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/discourse_assign/create_notification.rb b/lib/discourse_assign/create_notification.rb index 171195b..a645067 100644 --- a/lib/discourse_assign/create_notification.rb +++ b/lib/discourse_assign/create_notification.rb @@ -68,6 +68,7 @@ module DiscourseAssign end def call + return if topic.nil? Assigner.publish_topic_tracking_state(topic, user.id) unless mark_as_read? PostAlerter.new(post).create_notification_alert( diff --git a/spec/lib/discourse_assign/create_notification_spec.rb b/spec/lib/discourse_assign/create_notification_spec.rb index 3010251..3225a36 100644 --- a/spec/lib/discourse_assign/create_notification_spec.rb +++ b/spec/lib/discourse_assign/create_notification_spec.rb @@ -24,6 +24,20 @@ RSpec.describe DiscourseAssign::CreateNotification do create_notification end + context "when topic is not found" do + before { assignment.topic = nil } + + it "does not publish topic tracking state" do + Assigner.expects(:publish_topic_tracking_state).never + create_notification + end + + it "does not create a notification alert" do + alerter.expects(:create_notification_alert).never + create_notification + end + end + context "when `mark_as_read` is false" do let(:excerpt) do I18n.t(