Move math around parenthases in score_experience_level (#6569) [deploy]

* Move math around parenthases in score_experience_level

* Clean up tests

* Remove flash notice from comments form
This commit is contained in:
Ben Halpern 2020-03-10 14:14:08 -04:00 committed by GitHub
parent 9c3868a33e
commit 923afed4e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View file

@ -139,7 +139,7 @@ module Articles
end
def score_experience_level(article)
- ((article.experience_level_rating - (@user&.experience_level || 5).abs) / 2)
- ((article.experience_level_rating - (@user&.experience_level || 5)).abs / 2)
end
def score_comments(article)

View file

@ -350,21 +350,34 @@ RSpec.describe Articles::Feed, type: :service do
end
describe "#score_experience_level" do
let(:article) { create(:article, experience_level_rating: 9) }
let(:article) { create(:article, experience_level_rating: 7) }
context "when user has an experience level" do
let(:user) { create(:user, experience_level: 3) }
context "when user has a further experience level" do
let(:user) { create(:user, experience_level: 1) }
it "returns negative of (absolute value of the difference between article and user experience) divided by 2" do
expect(feed.score_experience_level(article)).to eq(-3)
end
it "returns proper negative when fractional" do
article.experience_level_rating = 8
expect(feed.score_experience_level(article)).to eq(-3.5)
end
end
context "when user has a closer experience level" do
let(:user) { create(:user, experience_level: 9) }
it "returns negative of (absolute value of the difference between article and user experience) divided by 2" do
expect(feed.score_experience_level(article)).to eq(-1)
end
end
context "when the user does not have an experience level set" do
let(:user) { create(:user, experience_level: nil) }
it "uses a value of 5 for user experience level" do
expect(feed.score_experience_level(article)).to eq(-2)
expect(feed.score_experience_level(article)).to eq(-1)
end
end
end