FIX: remove likes and other post actions before nuking a user

This commit is contained in:
Neil Lalonde 2014-03-31 14:06:25 -04:00
parent 682b0c4883
commit 379f4a87d5
2 changed files with 18 additions and 0 deletions

View File

@ -31,6 +31,9 @@ class UserDestroyer
end
end
end
user.post_actions.each do |post_action|
post_action.remove_act!(Discourse.system_user)
end
user.destroy.tap do |u|
if u
if opts[:block_email]

View File

@ -264,6 +264,21 @@ describe UserDestroyer do
category.topic.user_id.should == Discourse.system_user.id
end
end
context 'user liked things' do
before do
@topic = Fabricate(:topic, user: Fabricate(:user))
@post = Fabricate(:post, user: @topic.user, topic: @topic)
@like = PostAction.act(@user, @post, PostActionType.types[:like])
end
it 'should destroy the like' do
expect {
UserDestroyer.new(@admin).destroy(@user, {delete_posts: true})
}.to change { PostAction.count }.by(-1)
@post.reload.like_count.should == 0
end
end
end
end