From 94f05a40de601c97d7c2ec10ccfc6a28a5569651 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 24 Aug 2015 16:05:08 +1000 Subject: [PATCH] FIX: when destroying users we were leaving drafts behind --- app/services/user_destroyer.rb | 1 + spec/services/user_destroyer_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb index 2b70d181ca2..edf842f9f6c 100644 --- a/app/services/user_destroyer.rb +++ b/app/services/user_destroyer.rb @@ -20,6 +20,7 @@ class UserDestroyer User.transaction do + Draft.where(user_id: user.id).delete_all QueuedPost.where(user_id: user.id).delete_all if opts[:delete_posts] diff --git a/spec/services/user_destroyer_spec.rb b/spec/services/user_destroyer_spec.rb index d8507aaef64..5e023d30cd8 100644 --- a/spec/services/user_destroyer_spec.rb +++ b/spec/services/user_destroyer_spec.rb @@ -85,6 +85,17 @@ describe UserDestroyer do end + context "with a draft" do + let(:user) { Fabricate(:user) } + let(:admin) { Fabricate(:admin) } + let!(:draft) { Draft.set(user, 'test', 1, 'test') } + + it "removed the draft" do + UserDestroyer.new(admin).destroy(user) + expect(Draft.where(user_id: user.id).count).to eq(0) + end + end + context 'user has posts' do let!(:topic_starter) { Fabricate(:user) } let!(:topic) { Fabricate(:topic, user: topic_starter) }