discourse/spec/components/score_calculator_spec.rb

65 lines
1.6 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
it "gives the topic a score" do
topic.score.should be_present
end
it "gives the topic a percent_rank" do
topic.percent_rank.should_not == 1.0
end
2013-02-05 14:16:51 -05:00
end
2013-11-18 12:48:26 -05:00
context 'summary' do
2013-02-05 14:16:51 -05:00
it "won't update the site settings when the site settings don't match" do
ScoreCalculator.new(reads: 3).calculate
topic.reload
2013-11-18 12:48:26 -05:00
topic.has_summary.should be_false
2013-02-05 14:16:51 -05:00
end
2013-11-18 12:48:26 -05:00
it "removes the summary flag if the topic no longer qualifies" do
topic.update_column(:has_summary, true)
2013-02-05 14:16:51 -05:00
ScoreCalculator.new(reads: 3).calculate
topic.reload
2013-11-18 12:48:26 -05:00
topic.has_summary.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
2013-11-18 12:48:26 -05:00
SiteSetting.expects(:summary_likes_required).returns(0)
SiteSetting.expects(:summary_posts_required).returns(1)
SiteSetting.expects(:summary_score_threshold).returns(100)
2013-02-05 14:16:51 -05:00
ScoreCalculator.new(reads: 3).calculate
topic.reload
2013-11-18 12:48:26 -05:00
topic.has_summary.should be_true
2013-02-05 14:16:51 -05:00
end
end
end