FIX: Allow queued posts from deleted users to be rejected

This commit is contained in:
Robin Ward 2019-04-03 11:40:32 -04:00
parent bb2005d466
commit 1bce97a596
2 changed files with 13 additions and 2 deletions

View File

@ -566,8 +566,8 @@ class StaffActionLogger
topic = reviewable.topic || Topic.with_deleted.find_by(id: reviewable.topic_id)
topic_title = topic&.title || I18n.t('staff_action_logs.not_found')
username = reviewable.created_by.username || I18n.t('staff_action_logs.unknown')
name = reviewable.created_by.name || I18n.t('staff_action_logs.unknown')
username = reviewable.created_by&.username || I18n.t('staff_action_logs.unknown')
name = reviewable.created_by&.name || I18n.t('staff_action_logs.unknown')
details = [
"created_at: #{reviewable.created_at}",

View File

@ -505,5 +505,16 @@ describe StaffActionLogger do
expect(user_history.action).to eq(UserHistory.actions[:post_rejected])
expect(user_history.details).to include(reviewable.payload['raw'])
end
it "works if the user was destroyed" do
reviewable.created_by.destroy
reviewable.reload
expect { log_post_rejected }.to change { UserHistory.count }.by(1)
user_history = UserHistory.last
expect(user_history.action).to eq(UserHistory.actions[:post_rejected])
expect(user_history.details).to include(reviewable.payload['raw'])
end
end
end