From fea6ceaf96d52391410aeb89aab45d354bcc833a Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:16:43 -0300 Subject: [PATCH] Delete `ExplainerItem` when `ProjectMedia` is destroyed. (#1995) Fixes an issue reported by Sentry. Fixes: CV2-5099. --- app/models/concerns/project_media_associations.rb | 2 +- test/models/explainer_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/project_media_associations.rb b/app/models/concerns/project_media_associations.rb index ca52f8f980..40378101ab 100644 --- a/app/models/concerns/project_media_associations.rb +++ b/app/models/concerns/project_media_associations.rb @@ -21,7 +21,7 @@ module ProjectMediaAssociations has_one :claim_description, dependent: :destroy belongs_to :source, optional: true has_many :tipline_requests, as: :associated - has_many :explainer_items + has_many :explainer_items, dependent: :destroy has_many :explainers, through: :explainer_items has_annotations end diff --git a/test/models/explainer_test.rb b/test/models/explainer_test.rb index cce9645166..a902379b6c 100644 --- a/test/models/explainer_test.rb +++ b/test/models/explainer_test.rb @@ -110,4 +110,14 @@ def setup ex.description = 'Now this is the only paragraph' ex.save! end + + test "should destroy explainer items when project media is destroyed" do + t = create_team + ex = create_explainer team: t + pm = create_project_media team: t + pm.explainers << ex + assert_difference 'ExplainerItem.count', -1 do + pm.destroy! + end + end end