FIX: log post deletion even if user is deleted.

This commit is contained in:
Sam 2015-08-14 13:57:02 +10:00
parent 7d86d23eec
commit 5ee4d3ba8c
2 changed files with 11 additions and 1 deletions

View file

@ -42,10 +42,13 @@ class StaffActionLogger
topic = deleted_post.topic || Topic.with_deleted.find(deleted_post.topic_id)
username = deleted_post.user.try(:username) || "unknown"
name = deleted_post.user.try(:name) || "unknown"
details = [
"id: #{deleted_post.id}",
"created_at: #{deleted_post.created_at}",
"user: #{deleted_post.user.username} (#{deleted_post.user.name})",
"user: #{username} (#{name})",
"topic: #{topic.title}",
"post_number: #{deleted_post.post_number}",
"raw: #{deleted_post.raw}"

View file

@ -63,6 +63,13 @@ describe StaffActionLogger do
it 'creates a new UserHistory record' do
expect { log_post_deletion }.to change { UserHistory.count }.by(1)
end
it 'does not explode if post does not have a user' do
expect {
deleted_post.update_columns(user_id: nil)
log_post_deletion
}.to change { UserHistory.count }.by(1)
end
end
describe 'log_topic_deletion' do