Skip rescoring draft articles (#17379)
* Skip rescoring draft articles * add spec for worker
This commit is contained in:
parent
de1e1ea7b8
commit
6bf3e2aea9
2 changed files with 35 additions and 1 deletions
|
|
@ -8,7 +8,7 @@ module Moderator
|
|||
user = User.find_by(id: user_id)
|
||||
return unless user
|
||||
|
||||
Article.where(user: user).each(&:update_score)
|
||||
Article.published.where(user: user).each(&:update_score)
|
||||
rescue StandardError => e
|
||||
ForemStatsClient.count("moderators.sink", 1, tags: ["action:failed", "user_id:#{user.id}"])
|
||||
Honeybadger.notify(e)
|
||||
|
|
|
|||
34
spec/workers/moderator/sink_articles_worker_spec.rb
Normal file
34
spec/workers/moderator/sink_articles_worker_spec.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Moderator::SinkArticlesWorker, type: :worker do
|
||||
include_examples "#enqueues_on_correct_queue", "medium_priority", 1
|
||||
|
||||
describe "#perform" do
|
||||
it "returns early when user not found" do
|
||||
expect { described_class.new.perform(nil) }.not_to raise_error
|
||||
expect(described_class.new.perform(nil)).to be_nil
|
||||
end
|
||||
|
||||
it "updates score for user's articles" do
|
||||
article = create(:article, score: 20.0)
|
||||
# flagging a user is the normal route to sink articles,
|
||||
# and ensures score changes in an observable manner
|
||||
create(:vomit_reaction, reactable: article.user)
|
||||
allow(BlackBox).to receive(:article_hotness_score).and_call_original
|
||||
|
||||
described_class.new.perform(article.user_id)
|
||||
|
||||
expect(BlackBox).to have_received(:article_hotness_score)
|
||||
expect(article.reload.score).not_to eq(20)
|
||||
end
|
||||
|
||||
it "skips draft articles" do
|
||||
article = create(:article, published: false)
|
||||
allow(BlackBox).to receive(:article_hotness_score).and_call_original
|
||||
|
||||
described_class.new.perform(article.user_id)
|
||||
|
||||
expect(BlackBox).not_to have_received(:article_hotness_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue