forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request consuldemocracy#3678 from consul/fix_nan_score
Fix Infinity exceptions in hot score calculator
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 |