2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2014-06-27 11:26:03 -05:00
|
|
|
|
2014-09-27 18:38:00 -05:00
|
|
|
describe Jobs::Tl3Promotions do
|
2014-06-27 11:26:03 -05:00
|
|
|
|
|
|
|
subject(:run_job) { described_class.new.execute({}) }
|
|
|
|
|
|
|
|
it "promotes tl2 user who qualifies for tl3" do
|
2014-09-05 00:20:39 -05:00
|
|
|
_tl2_user = Fabricate(:user, trust_level: TrustLevel[2])
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
|
|
|
Promotion.any_instance.expects(:change_trust_level!).with(TrustLevel[3], anything).once
|
2014-06-27 11:26:03 -05:00
|
|
|
run_job
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do
|
2014-09-05 00:20:39 -05:00
|
|
|
_tl1_user = Fabricate(:user, trust_level: TrustLevel[1])
|
|
|
|
_tl0_user = Fabricate(:user, trust_level: TrustLevel[0])
|
|
|
|
TrustLevel3Requirements.any_instance.expects(:requirements_met?).never
|
2014-06-27 11:26:03 -05:00
|
|
|
Promotion.any_instance.expects(:change_trust_level!).never
|
|
|
|
run_job
|
|
|
|
end
|
|
|
|
|
2014-07-08 16:39:36 -05:00
|
|
|
context "tl3 user who doesn't qualify for tl3 anymore" do
|
|
|
|
def create_leader_user
|
2014-09-05 00:20:39 -05:00
|
|
|
user = Fabricate(:user, trust_level: TrustLevel[2])
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(Promotion.new(user).review_tl2).to eq(true)
|
2014-07-08 16:39:36 -05:00
|
|
|
user
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2014-09-05 01:55:25 -05:00
|
|
|
SiteSetting.tl3_promotion_min_duration = 3
|
2014-07-08 16:39:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "demotes if was promoted more than X days ago" do
|
|
|
|
user = nil
|
|
|
|
Timecop.freeze(4.days.ago) do
|
|
|
|
user = create_leader_user
|
|
|
|
end
|
|
|
|
|
2014-09-05 00:20:39 -05:00
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
2014-07-08 16:39:36 -05:00
|
|
|
run_job
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(user.reload.trust_level).to eq(TrustLevel[2])
|
2014-07-08 16:39:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't demote if user was promoted recently" do
|
|
|
|
user = nil
|
|
|
|
Timecop.freeze(1.day.ago) do
|
|
|
|
user = create_leader_user
|
|
|
|
end
|
|
|
|
|
2014-09-05 00:20:39 -05:00
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
2014-07-08 16:39:36 -05:00
|
|
|
run_job
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
2014-07-08 16:39:36 -05:00
|
|
|
end
|
2014-07-28 01:42:38 -05:00
|
|
|
|
|
|
|
it "doesn't demote if user hasn't lost requirements (low water mark)" do
|
|
|
|
user = nil
|
|
|
|
Timecop.freeze(4.days.ago) do
|
|
|
|
user = create_leader_user
|
|
|
|
end
|
|
|
|
|
2014-09-05 00:20:39 -05:00
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(false)
|
2014-07-28 01:42:38 -05:00
|
|
|
run_job
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
2014-07-28 01:42:38 -05:00
|
|
|
end
|
|
|
|
|
2014-06-27 11:26:03 -05:00
|
|
|
end
|
|
|
|
end
|