Skip to content

A platform for community discussion. Free, open, simple.

FIX: ProcessPost job failed for posts that have no user

Gerhard Schlager7b58afe67744
diff --git a/app/jobs/regular/process_post.rb b/app/jobs/regular/process_post.rb
index 8a9cba11bb3..88e340501a4 100644
--- a/app/jobs/regular/process_post.rb
+++ b/app/jobs/regular/process_post.rb
@@ -38,7 +38,7 @@ module Jobs
end
end
- if !post.user.staff? && !post.user.staged
+ if !post.user&.staff? && !post.user&.staged?
s = post.cooked
s << " #{post.topic.title}" if post.post_number == 1
if !args[:bypass_bump] && WordWatcher.new(s).should_flag?
diff --git a/spec/jobs/process_post_spec.rb b/spec/jobs/process_post_spec.rb
index 9c21d4f5fb8..137eb176db9 100644
--- a/spec/jobs/process_post_spec.rb
+++ b/spec/jobs/process_post_spec.rb
@@ -62,6 +62,19 @@ describe Jobs::ProcessPost do
expect { Jobs::ProcessPost.new.execute(post_id: post.id) }.to change { TopicLink.count }.by(2)
end
+ it "works for posts that belong to no existing user" do
+ cooked = post.cooked
+
+ post.update_columns(cooked: "frogs", user_id: nil)
+ Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
+ post.reload
+ expect(post.cooked).to eq(cooked)
+
+ post.update_columns(cooked: "frogs", user_id: User.maximum("id") + 1)
+ Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
+ post.reload
+ expect(post.cooked).to eq(cooked)
+ end
end
end