discourse/spec/components/score_calculator_spec.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
require 'spec_helper'
require 'score_calculator'
describe ScoreCalculator do
before do
2013-02-25 11:42:20 -05:00
@post = Fabricate(:post, reads: 111)
2013-02-05 14:16:51 -05:00
@topic = @post.topic
end
context 'with weightings' do
before do
ScoreCalculator.new(reads: 3).calculate
@post.reload
end
it 'takes the supplied weightings into effect' do
@post.score.should == 333
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
2013-02-25 11:42:20 -05:00
@topic.reload
2013-02-05 14:16:51 -05:00
@topic.has_best_of.should be_false
end
it "removes the best_of flag if the topic no longer qualifies" do
@topic.update_column(:has_best_of, true)
ScoreCalculator.new(reads: 3).calculate
2013-02-25 11:42:20 -05:00
@topic.reload
2013-02-05 14:16:51 -05:00
@topic.has_best_of.should be_false
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
2013-02-25 11:42:20 -05:00
@topic.reload
2013-02-05 14:16:51 -05:00
@topic.has_best_of.should be_true
end
end
end