From be1f8eb11b817c8484619715cdc06d80f5ba2d6e Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 22 Oct 2024 14:53:01 +0200 Subject: [PATCH] Destroy topic's collection when topic is destroyed --- plugin.rb | 5 ++++- spec/models/topic_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index c422b83..9003fe0 100644 --- a/plugin.rb +++ b/plugin.rb @@ -225,7 +225,10 @@ actors.as_json end - Topic.has_one :activity_pub_object, class_name: "DiscourseActivityPubCollection", as: :model + Topic.has_one :activity_pub_object, + class_name: "DiscourseActivityPubCollection", + as: :model, + dependent: :destroy Topic.include DiscourseActivityPub::AP::ModelHelpers add_to_class(:topic, :activity_pub_taxonomies) do diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 3e899f5..b568093 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -41,6 +41,13 @@ end end + describe "#destroy!" do + it "destroys associated collections" do + topic1.destroy! + expect(DiscourseActivityPubCollection.exists?(collection1.id)).to eq(false) + end + end + describe "move_posts" do before { toggle_activity_pub(category1, publication_type: "full_topic") }