2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::EnableBootstrapMode do
|
2022-07-27 18:21:10 +08:00
|
|
|
describe ".execute" do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:admin)
|
2016-04-27 01:08:19 +08:00
|
|
|
|
|
|
|
before { SiteSetting.bootstrap_mode_enabled = false }
|
|
|
|
|
|
|
|
it "raises an error when user_id is missing" do
|
|
|
|
expect { Jobs::EnableBootstrapMode.new.execute({}) }.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not execute if bootstrap mode is already enabled" do
|
|
|
|
SiteSetting.bootstrap_mode_enabled = true
|
|
|
|
StaffActionLogger.any_instance.expects(:log_site_setting_change).never
|
|
|
|
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not turn on bootstrap mode if first admin already exists" do
|
|
|
|
first_admin = Fabricate(:admin)
|
|
|
|
StaffActionLogger.any_instance.expects(:log_site_setting_change).never
|
|
|
|
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
|
|
|
|
end
|
|
|
|
|
2016-05-04 19:05:54 +08:00
|
|
|
it "does not amend setting that is not in default state" do
|
|
|
|
SiteSetting.default_trust_level = TrustLevel[3]
|
2024-04-10 23:29:03 +08:00
|
|
|
StaffActionLogger.any_instance.expects(:log_site_setting_change).times(3)
|
2016-05-04 19:05:54 +08:00
|
|
|
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
|
|
|
|
end
|
|
|
|
|
2016-04-27 01:08:19 +08:00
|
|
|
it "successfully turns on bootstrap mode" do
|
2024-04-10 23:29:03 +08:00
|
|
|
StaffActionLogger.any_instance.expects(:log_site_setting_change).times(4)
|
2016-04-27 01:08:19 +08:00
|
|
|
Jobs::EnableBootstrapMode.new.execute(user_id: admin.id)
|
2024-04-10 23:29:03 +08:00
|
|
|
expect(admin.reload.moderator).to be_truthy
|
2024-04-24 02:50:14 +08:00
|
|
|
expect(Jobs::SendSystemMessage.jobs.size).to eq(0)
|
2016-04-27 01:08:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|