discourse/spec/components/score_calculator_spec.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
require 'spec_helper'
require 'score_calculator'
describe ScoreCalculator do
let!(:post) { Fabricate(:post, reads: 111) }
let!(:another_post) { Fabricate(:post, topic: post.topic, reads: 222) }
let(:topic) { post.topic }
2013-02-05 14:16:51 -05:00
context 'with weightings' do
before do
ScoreCalculator.new(reads: 3).calculate
post.reload
another_post.reload
2013-02-05 14:16:51 -05:00
end
it 'takes the supplied weightings into effect' do
post.score.should == 333
another_post.score.should == 666
end
it "creates the percent_ranks" do
another_post.percent_rank.should == 0.0
post.percent_rank.should == 1.0
2013-02-05 14:16:51 -05:00
end
end
context 'best_of' do
it "won't update the site settings when the site settings don't match" do
ScoreCalculator.new(reads: 3).calculate
topic.reload
topic.has_best_of.should be_false
2013-02-05 14:16:51 -05:00
end
it "removes the best_of flag if the topic no longer qualifies" do
topic.update_column(:has_best_of, true)
2013-02-05 14:16:51 -05:00
ScoreCalculator.new(reads: 3).calculate
topic.reload
topic.has_best_of.should be_false
2013-02-05 14:16:51 -05:00
end
it "won't update the site settings when the site settings don't match" do
SiteSetting.expects(:best_of_likes_required).returns(0)
SiteSetting.expects(:best_of_posts_required).returns(1)
SiteSetting.expects(:best_of_score_threshold).returns(100)
ScoreCalculator.new(reads: 3).calculate
topic.reload
topic.has_best_of.should be_true
2013-02-05 14:16:51 -05:00
end
end
end