Skip to content

Commit

Permalink
Fix env specific var bug
Browse files Browse the repository at this point in the history
Fixes a bug which caused env specific vars to always return nil if the
same var wasn't also defined at the top level.
  • Loading branch information
pelargir authored and gma committed Apr 4, 2024
1 parent 8bcb2cf commit 38affd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/nesta/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def fetch(setting, *default)
setting = setting.to_s
self.config ||= read_config_file(setting)
env_config = config.fetch(Nesta::App.environment.to_s, {})
env_config.fetch(
setting,
config.fetch(setting) { raise NotDefined.new(setting) }
)
env_config.fetch(setting) do
config.fetch(setting) do
raise NotDefined.new(setting)
end
end
rescue NotDefined
default.empty? && raise || (return default.first)
end
Expand Down
6 changes: 6 additions & 0 deletions test/unit/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
end
end

it 'returns environment specific settings' do
stub_config('test' => { 'content' => 'rack_env_specific/path'}) do
assert_equal 'rack_env_specific/path', Nesta::Config.content
end
end

it 'overrides top level settings with environment specific settings' do
config = {
'content' => 'general/path',
Expand Down

0 comments on commit 38affd6

Please sign in to comment.