FIX: Delete PostUploads on Post deletion (#10090)

FIX: Delete PostUploads on Post deletion (#10090)

Related uploads will then be removed by Jobs::CleanUpUploads

diff --git a/app/models/post.rb b/app/models/post.rb
index 9f0b520..fefb43d 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -38,7 +38,7 @@ class Post < ActiveRecord::Base
   has_many :topic_links
   has_many :group_mentions, dependent: :destroy
 
-  has_many :post_uploads
+  has_many :post_uploads, dependent: :delete_all
   has_many :uploads, through: :post_uploads
 
   has_one :post_stat
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index fe4fe1a..24c8930 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1375,6 +1375,16 @@ describe Post do
 
     let(:post) { Fabricate(:post, raw: raw_multiple) }
 
+    it "removes post uploads on destroy" do
+      post.link_post_uploads
+
+      post.trash!
+      expect(PostUpload.count).to eq(6)
+
+      post.destroy!
+      expect(PostUpload.count).to eq(0)
+    end
+
     context "#link_post_uploads" do
       it "finds all the uploads in the post" do
         post.custom_fields[Post::DOWNLOADED_IMAGES] = {

GitHub sha: 58a5293d

This commit appears in #10090 which was approved by eviltrout. It was merged by CvX.