A platform for community discussion. Free, open, simple.
FIX: log for CleanUpTags job (#23964)
Krzysztof Kotlarek8c355d9e9941
diff --git a/app/jobs/scheduled/clean_up_tags.rb b/app/jobs/scheduled/clean_up_tags.rbindex 835ae8d689b..68cff5a4541 100644--- a/app/jobs/scheduled/clean_up_tags.rb+++ b/app/jobs/scheduled/clean_up_tags.rb@@ -8,7 +8,14 @@ module Jobsdef execute(args)return unless SiteSetting.automatically_clean_unused_tags- Tag.unused.where("tags.created_at < ?", GRACE_PERIOD_MINUTES.minutes.ago).destroy_all+ Tag.transaction do+ tags = Tag.unused.where("tags.created_at < ?", GRACE_PERIOD_MINUTES.minutes.ago)+ StaffActionLogger.new(Discourse.system_user).log_custom(+ "deleted_unused_tags",+ tags: tags.pluck(:name),+ )+ tags.destroy_all+ endendendenddiff --git a/spec/jobs/clean_up_tags_spec.rb b/spec/jobs/clean_up_tags_spec.rbindex 34f48ef29b3..ac6dc9b8d1e 100644--- a/spec/jobs/clean_up_tags_spec.rb+++ b/spec/jobs/clean_up_tags_spec.rb@@ -43,6 +43,16 @@ describe Jobs::CleanUpTags docreated_at: 10.minutes.ago,)end+ fab!(:unused_tag_2) do+ Fabricate(+ :tag,+ name: "unused2",+ staff_topic_count: 0,+ public_topic_count: 0,+ pm_topic_count: 0,+ created_at: 10.minutes.ago,+ )+ endfab!(:tag_in_group) doFabricate(@@ -57,8 +67,17 @@ describe Jobs::CleanUpTags doit "deletes unused tags" doSiteSetting.automatically_clean_unused_tags = true- expect { job.execute({}) }.to change { Tag.count }.by(-1)+ expect { job.execute({}) }.to change { Tag.count }.by(-2)expect { unused_tag.reload }.to raise_error(ActiveRecord::RecordNotFound)+ expect { unused_tag_2.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end++ it "logs action" do+ SiteSetting.automatically_clean_unused_tags = true+ expect { job.execute({}) }.to change { UserHistory.count }.by(1)+ log = UserHistory.last+ expect(log.acting_user_id).to eq(-1)+ expect(log.details).to eq('tags: ["unused1", "unused2"]')endit "does nothing when site setting is disabled by default" do