When updating article scores, use new score for blackbox (#13009)
Fixes #13008 Add a test case for blackbox stability This failed as expected on master and passed on this branch, when a reaction (which would change the article's calculated score during update) is added, the hotness should be stable, and not modified during the second call to `#update_score`.
This commit is contained in:
parent
fdf91eb5f2
commit
d6b4e83190
2 changed files with 11 additions and 2 deletions
|
|
@ -375,8 +375,8 @@ class Article < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_score
|
||||
new_score = reactions.sum(:points) + Reaction.where(reactable_id: user_id, reactable_type: "User").sum(:points)
|
||||
update_columns(score: new_score,
|
||||
self.score = reactions.sum(:points) + Reaction.where(reactable_id: user_id, reactable_type: "User").sum(:points)
|
||||
update_columns(score: score,
|
||||
comment_score: comments.sum(:score),
|
||||
hotness_score: BlackBox.article_hotness_score(self),
|
||||
spaminess_rating: BlackBox.calculate_spaminess(self))
|
||||
|
|
|
|||
|
|
@ -1008,4 +1008,13 @@ RSpec.describe Article, type: :model do
|
|||
expect(article.plain_html).not_to include("highlight__panel")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update_score" do
|
||||
it "stably sets the correct blackbox values" do
|
||||
create(:reaction, reactable: article, points: 1)
|
||||
|
||||
article.update_score
|
||||
expect { article.update_score }.not_to change { article.reload.hotness_score }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue