From d0dd517f27a9cd259fa5e0da29b763abdc7a2ff9 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 10 Feb 2016 11:54:40 +1100 Subject: [PATCH] FEATURE: blank global settings should not shadow Due to https://github.com/docker/docker/issues/9298 it is a huge pain to remove ENV vars when composing images, allow us to simply treat "blank" as a ENV var that is not being shadowed. In general we always supply a value to ENV vars we are shadowing. --- lib/site_setting_extension.rb | 8 +++++--- spec/components/site_setting_extension_spec.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index 13392a22af5..7eb33e2b8fa 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -121,9 +121,11 @@ module SiteSettingExtension # exists it will be used instead of the setting and the setting will be hidden. # Useful for things like API keys on multisite. if opts[:shadowed_by_global] && GlobalSetting.respond_to?(name) - hidden_settings << name - shadowed_settings << name - current_value = GlobalSetting.send(name) + if (val = GlobalSetting.send(name)).present? + hidden_settings << name + shadowed_settings << name + current_value = val + end end if opts[:refresh] diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rb index 04f3622706b..390c98fa269 100644 --- a/spec/components/site_setting_extension_spec.rb +++ b/spec/components/site_setting_extension_spec.rb @@ -447,6 +447,18 @@ describe SiteSettingExtension do end end + context "with blank global setting" do + before do + GlobalSetting.stubs(:nada).returns('') + settings.setting(:nada, 'nothing', shadowed_by_global: true) + settings.refresh! + end + + it "should return default cause nothing is set" do + expect(settings.nada).to eq('nothing') + end + end + context "with global setting" do before do GlobalSetting.stubs(:trout_api_key).returns('purringcat')