Remove Articles::ScoreCalcJob and spec (#5898)
This commit is contained in:
parent
aa7bc6b7b2
commit
15b4565ac8
2 changed files with 0 additions and 60 deletions
|
|
@ -1,16 +0,0 @@
|
|||
module Articles
|
||||
class ScoreCalcJob < ApplicationJob
|
||||
queue_as :articles_score_calc
|
||||
|
||||
def perform(article_id)
|
||||
article = Article.find_by(id: article_id)
|
||||
return unless article
|
||||
|
||||
article.update_columns(score: article.reactions.sum(:points),
|
||||
comment_score: article.comments.sum(:score),
|
||||
hotness_score: BlackBox.article_hotness_score(article),
|
||||
spaminess_rating: BlackBox.calculate_spaminess(article))
|
||||
article.index!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe Articles::ScoreCalcJob, type: :job do
|
||||
include_examples "#enqueues_job", "articles_score_calc", 1
|
||||
|
||||
describe "#perform_now" do
|
||||
before do
|
||||
allow(BlackBox).to receive(:article_hotness_score).and_return(373)
|
||||
allow(BlackBox).to receive(:calculate_spaminess).and_return(2)
|
||||
end
|
||||
|
||||
context "with article" do
|
||||
let_it_be(:article) { create(:article) }
|
||||
let_it_be(:comment) { create(:comment, commentable: article, score: 5) }
|
||||
let_it_be(:second_comment) { create(:comment, commentable: article, score: 7) }
|
||||
|
||||
it "updates article scores", :aggregate_failures do
|
||||
allow(Article).to receive(:find_by).and_return(article)
|
||||
allow(article.reactions).to receive(:sum).and_return(7)
|
||||
|
||||
described_class.perform_now(article.id)
|
||||
article.reload
|
||||
|
||||
expect(article.score).to be(7)
|
||||
expect(article.comment_score).to be(12)
|
||||
expect(article.hotness_score).to be(373)
|
||||
expect(article.spaminess_rating).to be(2)
|
||||
end
|
||||
end
|
||||
|
||||
context "without article" do
|
||||
it "does not error" do
|
||||
expect { described_class.perform_now(nil) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "does not calculate scores", :aggregate_failures do
|
||||
described_class.perform_now(nil)
|
||||
|
||||
expect(BlackBox).not_to have_received(:article_hotness_score)
|
||||
expect(BlackBox).not_to have_received(:calculate_spaminess)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue