From 96700d55a45a81d399b01b36fcd79585262b9b89 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:08:00 -0500 Subject: [PATCH] FIX: Safely return from missing post on `check_dont_feed_the_trolls` (#21238) --- lib/composer_messages_finder.rb | 2 +- spec/lib/composer_messages_finder_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/composer_messages_finder.rb b/lib/composer_messages_finder.rb index 78841a91385..4bba013a5c0 100644 --- a/lib/composer_messages_finder.rb +++ b/lib/composer_messages_finder.rb @@ -233,7 +233,7 @@ class ComposerMessagesFinder if @details[:post_id] Post.find_by(id: @details[:post_id]) else - @topic.first_post + @topic&.first_post end return if post.blank? diff --git a/spec/lib/composer_messages_finder_spec.rb b/spec/lib/composer_messages_finder_spec.rb index a95370e86a2..b6ab99a1acd 100644 --- a/spec/lib/composer_messages_finder_spec.rb +++ b/spec/lib/composer_messages_finder_spec.rb @@ -395,6 +395,11 @@ RSpec.describe ComposerMessagesFinder do ) expect(finder.check_dont_feed_the_trolls).to be_present end + + it "safely returns from not finding a post" do + finder = ComposerMessagesFinder.new(user, composer_action: "reply", topic_id: nil) + expect(finder.check_dont_feed_the_trolls).to be_blank + end end describe ".check_get_a_room" do