2023-12-26 14:39:18 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
RSpec.describe SiteSettings::DeprecatedSettings do
|
2023-12-26 14:39:18 +08:00
|
|
|
describe "when not overriding deprecated settings" do
|
2025-01-04 19:55:22 +08:00
|
|
|
it "does not act as a proxy to the new methods" do
|
|
|
|
stub_deprecated_settings!(override: false) do
|
|
|
|
SiteSetting.old_one = true
|
2023-12-26 14:39:18 +08:00
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
expect(SiteSetting.new_one).to eq(false)
|
|
|
|
expect(SiteSetting.new_one?).to eq(false)
|
2023-12-26 14:39:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
it "logs warnings when deprecated settings are called" do
|
|
|
|
stub_deprecated_settings!(override: false) do
|
|
|
|
logger =
|
|
|
|
track_log_messages do
|
|
|
|
expect(SiteSetting.old_one).to eq(false)
|
|
|
|
expect(SiteSetting.old_one?).to eq(false)
|
|
|
|
end
|
|
|
|
expect(logger.warnings.count).to eq(3)
|
2023-12-26 14:39:18 +08:00
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
logger = track_log_messages { SiteSetting.old_one(warn: false) }
|
|
|
|
expect(logger.warnings.count).to eq(0)
|
2023-12-26 14:39:18 +08:00
|
|
|
end
|
|
|
|
end
|
2025-01-04 19:55:22 +08:00
|
|
|
end
|
2023-12-26 14:39:18 +08:00
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
describe "when overriding deprecated settings" do
|
|
|
|
it "acts as a proxy to the new methods" do
|
|
|
|
stub_deprecated_settings!(override: true) do
|
|
|
|
SiteSetting.old_one = true
|
2023-12-26 14:39:18 +08:00
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
expect(SiteSetting.new_one).to eq(true)
|
|
|
|
expect(SiteSetting.new_one?).to eq(true)
|
2023-12-26 14:39:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
it "logs warnings when deprecated settings are called" do
|
|
|
|
stub_deprecated_settings!(override: true) do
|
|
|
|
logger =
|
|
|
|
track_log_messages do
|
|
|
|
expect(SiteSetting.old_one).to eq(false)
|
|
|
|
expect(SiteSetting.old_one?).to eq(false)
|
|
|
|
end
|
|
|
|
expect(logger.warnings.count).to eq(2)
|
2023-12-26 14:39:18 +08:00
|
|
|
|
2025-01-04 19:55:22 +08:00
|
|
|
logger = track_log_messages { SiteSetting.old_one(warn: false) }
|
|
|
|
expect(logger.warnings.count).to eq(0)
|
2023-12-26 14:39:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|