summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-07-02 14:05:55 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2018-07-02 14:05:55 -0700
commit10cabb8470e350f1a15e787dd18f4ba3a35f9548 (patch)
tree1498ce076ee0d4b0f8f967c62071675ffbc34c4a
parentcb61e322573e339e53319d63d4120ed75681fbe7 (diff)
downloadmixlib-config-10cabb8470e350f1a15e787dd18f4ba3a35f9548.tar.gz
key? and has_key? should find subcontexts
when we have: config[:knife][:whatever] then: config.key?(:knife) should be true, not false. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/mixlib/config.rb2
-rw-r--r--spec/mixlib/config_spec.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb
index ce4d185..6a935ae 100644
--- a/lib/mixlib/config.rb
+++ b/lib/mixlib/config.rb
@@ -153,7 +153,7 @@ module Mixlib
# <True>:: If the config option exists
# <False>:: If the config option does not exist
def key?(key)
- configuration.has_key?(key.to_sym)
+ configuration.has_key?(key.to_sym) || config_contexts.has_key?(key.to_sym)
end
alias_method :has_key?, :key?
diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb
index 6bc31b0..c664ceb 100644
--- a/spec/mixlib/config_spec.rb
+++ b/spec/mixlib/config_spec.rb
@@ -935,6 +935,14 @@ describe Mixlib::Config do
end
end
+ it "has_key? finds the subcontext" do
+ expect(@klass.has_key?(:blah)).to be true
+ end
+
+ it "key? finds the subcontext" do
+ expect(@klass.key?(:blah)).to be true
+ end
+
it "save does not save the hash for the config_context" do
expect(@klass.save).to eql({})
end