summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-09-02 09:18:56 +0100
committerGitHub <noreply@github.com>2016-09-02 09:18:56 +0100
commitcf1bd5c35e975874b774a62553c211235be896a2 (patch)
tree796db26e97b20e05038fac7665625149a539f878
parentcf2fdac9c64c5778354b5681ebbf06fcd084b884 (diff)
parent61008c33ab6de5dc21fe1de15ce08996f000dc9f (diff)
downloadmixlib-config-cf1bd5c35e975874b774a62553c211235be896a2.tar.gz
Merge pull request #42 from chef/hash
Allow a config context to be set from another config context
-rw-r--r--lib/mixlib/config.rb3
-rw-r--r--spec/mixlib/config_spec.rb10
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb
index f5ab5e5..b992773 100644
--- a/lib/mixlib/config.rb
+++ b/lib/mixlib/config.rb
@@ -174,6 +174,7 @@ module Mixlib
end
result
end
+ alias :to_hash :save
# Restore non-default values from the given hash.
#
@@ -416,7 +417,7 @@ module Mixlib
if configurables.has_key?(symbol)
configurables[symbol].set(self.configuration, value)
elsif config_contexts.has_key?(symbol)
- config_contexts[symbol].restore(value)
+ config_contexts[symbol].restore(value.to_hash)
else
if config_strict_mode == :warn
Chef::Log.warn("Setting unsupported config value #{symbol}.")
diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb
index 747915c..400d367 100644
--- a/spec/mixlib/config_spec.rb
+++ b/spec/mixlib/config_spec.rb
@@ -868,12 +868,20 @@ describe Mixlib::Config do
expect(@klass.blah.yarr.y).to eql(6)
end
- it "resmoves added properties not included in saved state" do
+ it "removes added properties not included in saved state" do
@klass.blah.yarr.z = 12
@klass.restore( :blah => { :yarr => { :x => 10 } } )
expect(@klass.blah.yarr.x).to eql(10)
expect(@klass.blah.yarr.z).to eql(nil)
end
+
+ it "can set a config context from another context" do
+ @klass.blah.blyme = { :x => 7 }
+ blyme = @klass.blah.blyme
+ @klass.blah.yarr.x = 12
+ @klass.blah.yarr = blyme
+ expect(@klass.blah.yarr.x).to eql(7)
+ end
end
describe "When a config_context with no defaulted values exists" do