From e654edf844dea906c570a7dd138fd9e07eee2530 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 16 Aug 2023 11:20:47 +1000 Subject: [PATCH] FEATURE: do not bump topics when retroactively closing (#23115) The category feature that automatically closes topics does it silently This amends it so `rake topics:apply_autoclose` which does retroactive closing will also do so silently. --- lib/tasks/topics.rake | 2 +- spec/tasks/topics_spec.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/tasks/topics_spec.rb diff --git a/lib/tasks/topics.rake b/lib/tasks/topics.rake index ae45db60b9e..030a12d0b75 100644 --- a/lib/tasks/topics.rake +++ b/lib/tasks/topics.rake @@ -20,7 +20,7 @@ def close_old_topics(category) end topics.find_each do |topic| - topic.update_status("closed", true, Discourse.system_user) + topic.update_status("closed", true, Discourse.system_user, { silent: true }) RakeHelpers.print_status_with_label(" closing old topics: ", topics_closed += 1, total) end end diff --git a/spec/tasks/topics_spec.rb b/spec/tasks/topics_spec.rb new file mode 100644 index 00000000000..9e286e2429a --- /dev/null +++ b/spec/tasks/topics_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +RSpec.describe "Post rake tasks" do + fab!(:post) { Fabricate(:post, raw: "The quick brown fox jumps over the lazy dog") } + let(:topic) { post.topic } + let(:category) { topic.category } + + before do + Rake::Task.clear if defined?(Rake::Task) + Discourse::Application.load_tasks + STDOUT.stubs(:write) + end + + describe "topics:apply_autoclose" do + it "should close topics silently" do + category.auto_close_hours = 1 + category.save! + + original_bumped_at = topic.bumped_at + + freeze_time 2.hours.from_now + + Rake::Task["topics:apply_autoclose"].invoke + + topic.reload + + expect(topic.closed).to eq(true) + expect(topic.bumped_at).to eq_time(original_bumped_at) + end + end +end