FIX: ProcessPost job failed for posts that have no user

This commit is contained in:
Gerhard Schlager 2017-12-21 14:45:59 +01:00
parent 727a45185d
commit 7b58afe677
2 changed files with 14 additions and 1 deletions

View File

@ -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?

View File

@ -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