2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'promotion'
|
|
|
|
|
|
|
|
describe Promotion do
|
|
|
|
|
2014-06-27 12:26:03 -04:00
|
|
|
describe "review" do
|
|
|
|
it "skips regular users" do
|
|
|
|
# Reviewing users at higher trust levels is expensive, so trigger those reviews in a background job.
|
|
|
|
regular = Fabricate.build(:user, trust_level: TrustLevel.levels[:regular])
|
|
|
|
promotion = described_class.new(regular)
|
|
|
|
promotion.expects(:review_regular).never
|
|
|
|
promotion.review
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-17 19:11:13 -04:00
|
|
|
context "newuser" do
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2013-04-17 19:11:13 -04:00
|
|
|
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:newuser])}
|
2013-02-05 14:16:51 -05:00
|
|
|
let(:promotion) { Promotion.new(user) }
|
|
|
|
|
|
|
|
it "doesn't raise an error with a nil user" do
|
|
|
|
-> { Promotion.new(nil).review }.should_not raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'that has done nothing' do
|
|
|
|
let!(:result) { promotion.review }
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
result.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has not changed the user's trust level" do
|
2013-04-17 19:11:13 -04:00
|
|
|
user.trust_level.should == TrustLevel.levels[:newuser]
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "that has done the requisite things" do
|
|
|
|
|
|
|
|
before do
|
2013-10-03 23:28:49 -04:00
|
|
|
stat = user.user_stat
|
|
|
|
stat.topics_entered = SiteSetting.basic_requires_topics_entered
|
|
|
|
stat.posts_read_count = SiteSetting.basic_requires_read_posts
|
|
|
|
stat.time_read = SiteSetting.basic_requires_time_spent_mins * 60
|
2013-02-05 14:16:51 -05:00
|
|
|
@result = promotion.review
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
@result.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has upgraded the user to basic" do
|
2013-03-01 07:07:44 -05:00
|
|
|
user.trust_level.should == TrustLevel.levels[:basic]
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-04-05 00:29:46 -04:00
|
|
|
context "basic" do
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:basic])}
|
|
|
|
let(:promotion) { Promotion.new(user) }
|
|
|
|
|
|
|
|
context 'that has done nothing' do
|
|
|
|
let!(:result) { promotion.review }
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
result.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has not changed the user's trust level" do
|
|
|
|
user.trust_level.should == TrustLevel.levels[:basic]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "that has done the requisite things" do
|
|
|
|
|
|
|
|
before do
|
2013-10-03 23:28:49 -04:00
|
|
|
stat = user.user_stat
|
|
|
|
stat.topics_entered = SiteSetting.regular_requires_topics_entered
|
|
|
|
stat.posts_read_count = SiteSetting.regular_requires_read_posts
|
|
|
|
stat.time_read = SiteSetting.regular_requires_time_spent_mins * 60
|
|
|
|
stat.days_visited = SiteSetting.regular_requires_days_visited * 60
|
|
|
|
stat.likes_received = SiteSetting.regular_requires_likes_received
|
|
|
|
stat.likes_given = SiteSetting.regular_requires_likes_given
|
|
|
|
stat.topic_reply_count = SiteSetting.regular_requires_topic_reply_count
|
2013-04-05 00:29:46 -04:00
|
|
|
|
|
|
|
@result = promotion.review
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
@result.should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has upgraded the user to regular" do
|
|
|
|
user.trust_level.should == TrustLevel.levels[:regular]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2014-06-27 12:26:03 -04:00
|
|
|
context "regular" do
|
|
|
|
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:regular])}
|
|
|
|
let(:promotion) { Promotion.new(user) }
|
|
|
|
|
|
|
|
context "doesn't qualify for promotion" do
|
|
|
|
before do
|
|
|
|
LeaderRequirements.any_instance.expects(:requirements_met?).at_least_once.returns(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "review_regular returns false" do
|
|
|
|
expect {
|
|
|
|
promotion.review_regular.should == false
|
|
|
|
}.to_not change { user.reload.trust_level }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't promote" do
|
|
|
|
expect {
|
|
|
|
promotion.review_regular
|
|
|
|
}.to_not change { user.reload.trust_level }
|
|
|
|
end
|
2014-07-08 17:39:36 -04:00
|
|
|
|
|
|
|
it "doesn't log a trust level change" do
|
|
|
|
expect {
|
|
|
|
promotion.review_regular
|
|
|
|
}.to_not change { UserHistory.count }
|
|
|
|
end
|
2014-06-27 12:26:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "qualifies for promotion" do
|
|
|
|
before do
|
|
|
|
LeaderRequirements.any_instance.expects(:requirements_met?).at_least_once.returns(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "review_regular returns true" do
|
|
|
|
promotion.review_regular.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "promotes to leader" do
|
|
|
|
promotion.review_regular.should == true
|
|
|
|
user.reload.trust_level.should == TrustLevel.levels[:leader]
|
|
|
|
end
|
2014-07-08 17:39:36 -04:00
|
|
|
|
|
|
|
it "logs a trust level change" do
|
|
|
|
expect {
|
|
|
|
promotion.review_regular
|
|
|
|
}.to change { UserHistory.where(action: UserHistory.actions[:auto_trust_level_change]).count }.by(1)
|
|
|
|
end
|
2014-06-27 12:26:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|