Files
grecia/spec/lib/score_calculator_spec.rb
Javi Martín 53abc57578 Fix Infinity exceptions in hot score calculator
There was a rare case we've found on some Travis builds where the system
time suddenly moved back to the past a couple of tenths of a second,
meaning `Time.current - resource.created_at` returned a negative number,
which lead to a division by zero.
2019-09-10 16:00:21 +02:00

30 lines
703 B
Ruby

require "rails_helper"
describe ScoreCalculator do
describe ".hot_score" do
let(:resource) { create(:debate) }
before do
resource.vote_by(voter: create(:user), vote: "yes")
end
it "ignores small time leaps", :with_frozen_time do
resource.created_at = Time.current + 0.01
expect(ScoreCalculator.hot_score(resource)).to eq 1
end
it "ignores setting with negative value " do
Setting["hot_score_period_in_days"] = -1
expect(ScoreCalculator.hot_score(resource)).to eq 1
end
it "ignores setting with zero value" do
Setting["hot_score_period_in_days"] = 0
expect(ScoreCalculator.hot_score(resource)).to eq 1
end
end
end