Skip to content

Commit

Permalink
Merge pull request #1205 from EventideSystems/fix_setting_check
Browse files Browse the repository at this point in the history
Safer setting check
  • Loading branch information
CloCkWeRX authored Dec 5, 2023
2 parents 7c13e93 + a49724b commit 65aa303
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/models/setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down

0 comments on commit 65aa303

Please sign in to comment.