Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fail fast on unknown upcoming change keys (#39800)

Loïc Guitaut9772faa370d5
diff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rb
index 125df273419..37589f4c9ac 100644
--- a/lib/upcoming_changes.rb
+++ b/lib/upcoming_changes.rb
@@ -117,6 +117,10 @@ module UpcomingChanges
def self.enabled?(change_setting_name)
change_setting_name = change_setting_name.to_sym
+ if !exists?(change_setting_name)
+ raise ArgumentError, "Unknown upcoming change: #{change_setting_name}"
+ end
+
# An admin has modified the setting and a value is stored
# in the database, since the default for upcoming changes
# is false.
diff --git a/spec/lib/upcoming_changes_spec.rb b/spec/lib/upcoming_changes_spec.rb
index f7df342b889..dcf8e2b1591 100644
--- a/spec/lib/upcoming_changes_spec.rb
+++ b/spec/lib/upcoming_changes_spec.rb
@@ -392,6 +392,15 @@ RSpec.describe UpcomingChanges do
UpcomingChanges.clear_caches!
end
+ context "when the change is not registered" do
+ it "raises ArgumentError" do
+ expect { described_class.enabled?(:not_an_upcoming_change) }.to raise_error(
+ ArgumentError,
+ /Unknown upcoming change/,
+ )
+ end
+ end
+
context "when the setting has no row in the database (admin has not saved it)" do
before { SiteSetting.remove_override!(setting_name) }