mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-04 21:01:27 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
71 lines
2.3 KiB
Ruby
71 lines
2.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Jobs::Tl3Promotions do
|
|
|
|
subject(:run_job) { described_class.new.execute({}) }
|
|
|
|
it "promotes tl2 user who qualifies for tl3" do
|
|
_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
|
|
run_job
|
|
end
|
|
|
|
it "doesn't promote tl1 and tl0 users who have met tl3 requirements" do
|
|
_tl1_user = Fabricate(:user, trust_level: TrustLevel[1])
|
|
_tl0_user = Fabricate(:user, trust_level: TrustLevel[0])
|
|
TrustLevel3Requirements.any_instance.expects(:requirements_met?).never
|
|
Promotion.any_instance.expects(:change_trust_level!).never
|
|
run_job
|
|
end
|
|
|
|
context "tl3 user who doesn't qualify for tl3 anymore" do
|
|
def create_leader_user
|
|
user = Fabricate(:user, trust_level: TrustLevel[2])
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
|
expect(Promotion.new(user).review_tl2).to eq(true)
|
|
user
|
|
end
|
|
|
|
before do
|
|
SiteSetting.tl3_promotion_min_duration = 3
|
|
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
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
|
run_job
|
|
expect(user.reload.trust_level).to eq(TrustLevel[2])
|
|
end
|
|
|
|
it "doesn't demote if user was promoted recently" do
|
|
user = nil
|
|
Timecop.freeze(1.day.ago) do
|
|
user = create_leader_user
|
|
end
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
|
run_job
|
|
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
|
end
|
|
|
|
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
|
|
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
|
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(false)
|
|
run_job
|
|
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
|
end
|
|
|
|
end
|
|
end
|