Topic can have null user_id when user was nuked

This commit is contained in:
Neil Lalonde
2013-09-04 15:35:10 -04:00
parent 117fc8db58
commit d76486a48b
4 changed files with 37 additions and 5 deletions

View File

@@ -87,7 +87,10 @@ describe UserDestroyer do
end
context 'user has posts' do
let!(:post) { Fabricate(:post, user: @user) }
let!(:topic_starter) { Fabricate(:user) }
let!(:topic) { Fabricate(:topic, user: topic_starter) }
let!(:first_post) { Fabricate(:post, user: topic_starter, topic: topic) }
let!(:post) { Fabricate(:post, user: @user, topic: topic) }
context "delete_posts is false" do
subject(:destroy) { UserDestroyer.new(@admin).destroy(@user) }
@@ -123,6 +126,20 @@ describe UserDestroyer do
post.reload.deleted_at.should_not be_nil
post.user_id.should be_nil
end
it "does not delete topics started by others in which the user has replies" do
destroy
topic.reload.deleted_at.should be_nil
topic.user_id.should_not be_nil
end
it "deletes topics started by the deleted user" do
spammer_topic = Fabricate(:topic, user: @user)
spammer_post = Fabricate(:post, user: @user, topic: spammer_topic)
destroy
spammer_topic.reload.deleted_at.should_not be_nil
spammer_topic.user_id.should be_nil
end
end
end