From 599979902e9250f55dcd4ea0ae30ca80a1a05af4 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:28:10 -0500 Subject: [PATCH] FIX: Error when trying to bump a topic with no category (#21207) When revising a post, if the topic that post belonged to did not have a category attached it would error with > NoMethodError (undefined method `read_restricted' for nil:NilClass) --- app/models/topic_tracking_state.rb | 2 ++ spec/lib/post_revisor_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 82e6b0cd3e1..5ad72d45474 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -579,6 +579,8 @@ class TopicTrackingState def self.secure_category_group_ids(topic) category = topic.category + return [Group::AUTO_GROUPS[:admins]] if category.nil? + if category.read_restricted ids = [Group::AUTO_GROUPS[:admins]] ids.push(*category.secure_group_ids) diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb index 473f688da53..4000c389d0d 100644 --- a/spec/lib/post_revisor_spec.rb +++ b/spec/lib/post_revisor_spec.rb @@ -422,6 +422,20 @@ RSpec.describe PostRevisor do }.to change { post.topic.bumped_at } end + it "should bump topic when no topic category" do + topic_with_no_category = Fabricate(:topic, category_id: nil) + post_from_topic_with_no_category = Fabricate(:post, topic: topic_with_no_category) + expect { + result = + subject.revise!( + Fabricate(:admin), + raw: post_from_topic_with_no_category.raw, + tags: ["foo"], + ) + expect(result).to eq(true) + }.to change { topic.reload.bumped_at } + end + it "should send muted and latest message" do TopicUser.create!(topic: post.topic, user: post.user, notification_level: 0) messages =