summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Ball <tyleraball@gmail.com>2015-02-13 09:39:54 -0800
committerTyler Ball <tyleraball@gmail.com>2015-02-13 09:39:54 -0800
commit139503e42d8db84ed8f620a44fe8810e0d1742ff (patch)
treec6c91fdd2c9c1787bd8fe8946b051d18d519bde7
parent9e48d56d76f1f45eb348e720c670bb13d708dcbe (diff)
parent29554013c62ee754e426f7a63a38ed62e10a6f2b (diff)
downloadchef-139503e42d8db84ed8f620a44fe8810e0d1742ff.tar.gz
Merge pull request #2893 from chef/tball/complete-2338
Finishing tests for https://github.com/chef/chef/pull/2338
-rw-r--r--lib/chef/knife/core/generic_presenter.rb7
-rw-r--r--spec/unit/knife/core/ui_spec.rb12
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/chef/knife/core/generic_presenter.rb b/lib/chef/knife/core/generic_presenter.rb
index a1aeadb0f3..f3ea0f0d6c 100644
--- a/lib/chef/knife/core/generic_presenter.rb
+++ b/lib/chef/knife/core/generic_presenter.rb
@@ -178,10 +178,13 @@ class Chef
nested_value_spec.split(".").each do |attr|
if data.nil?
nil # don't get no method error on nil
- elsif data.respond_to?(attr.to_sym)
- data = data.send(attr.to_sym)
+ # Must check :[] before attr because spec can include
+ # `keys` - want the key named `keys`, not a list of
+ # available keys.
elsif data.respond_to?(:[])
data = data[attr]
+ elsif data.respond_to?(attr.to_sym)
+ data = data.send(attr.to_sym)
else
data = begin
data.send(attr.to_sym)
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index 83fff4c082..ac42ad6dd6 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -356,6 +356,18 @@ EOM
@ui.config[:attribute] = ["gi", "hi"]
expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "gi" => "go", "hi"=> "ho" } })
end
+
+ it "should handle attributes named the same as methods" do
+ input = { "keys" => "values", "hi" => "ho", "id" => "sample-data-bag-item" }
+ @ui.config[:attribute] = "keys"
+ expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "keys" => "values" } })
+ end
+
+ it "should handle nested attributes named the same as methods" do
+ input = { "keys" => {"keys" => "values"}, "hi" => "ho", "id" => "sample-data-bag-item" }
+ @ui.config[:attribute] = "keys.keys"
+ expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "keys.keys" => "values" } })
+ end
end
describe "with --run-list passed" do