FIX: Allow queued posts from deleted users to be rejected

FIX: Allow queued posts from deleted users to be rejected

diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index b2e1e2f..5b047a1 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -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}",
diff --git a/spec/services/staff_action_logger_spec.rb b/spec/services/staff_action_logger_spec.rb
index f2cfc05..40c5106 100644
--- a/spec/services/staff_action_logger_spec.rb
+++ b/spec/services/staff_action_logger_spec.rb
@@ -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

GitHub sha: 1bce97a5