From a49724b1b9048038d59713acafb61a24f28c12a8 Mon Sep 17 00:00:00 2001 From: Tom Tuddenham Date: Tue, 5 Dec 2023 18:29:57 +1030 Subject: [PATCH] replace not nil check on nil value replace not nil check on nil value replace not nil check on nil value replace not nil check on nil value --- app/models/setting.rb | 4 ++-- spec/models/setting_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index 3032c90dfb..1af7299fcc 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -58,9 +58,9 @@ def [](name) return cache[name] if cache.key?(name) # Check database - if database_and_table_exists? && setting = find_by_name(name.to_s) && !setting.value.nil? + if database_and_table_exists? && (setting = find_by_name(name.to_s))&.value.present? return cache[name] = setting.value - end + end # Check YAML settings return cache[name] = yaml_settings[name] if yaml_settings.key?(name) end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index abf4f14da1..5b66c3e73e 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -54,6 +54,11 @@ expect(Setting.hello).to eq(false) end + it "should return nil if setting is missing and no default value is provided by YAML" do + expect(Setting[:missing]).to eq(nil) + expect(Setting.missing).to eq(nil) + end + describe "#dig" do it "should dig into nested hashes" do Setting[:hello] = { foo: { bar: 3 } }