summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-06-19 11:59:01 -0700
committerDaniel DeLeo <dan@opscode.com>2010-06-19 11:59:01 -0700
commitd5a0276a72d3ec675234f8f6b257296628cf3465 (patch)
tree715aed74876b21b5fb570b6e7eba7b1be35cdf51
parent28c62ec25fb7b69ce434e45b47329f320007cb08 (diff)
parent04aad34a6d3d85ea2ad334655b84a36bd5179675 (diff)
downloadchef-d5a0276a72d3ec675234f8f6b257296628cf3465.tar.gz
Merge branch 'CHEF-1361'
-rw-r--r--chef/lib/chef/knife.rb4
-rw-r--r--chef/spec/unit/knife/data_bag_create_spec.rb20
2 files changed, 20 insertions, 4 deletions
diff --git a/chef/lib/chef/knife.rb b/chef/lib/chef/knife.rb
index b06170b187..a0dfdef8a3 100644
--- a/chef/lib/chef/knife.rb
+++ b/chef/lib/chef/knife.rb
@@ -195,7 +195,9 @@ class Chef
config[:attribute].split(".").each do |attr|
if data.respond_to?(:[])
data = data[attr]
- else
+ elsif data.nil?
+ nil # don't get no method error on nil
+ else data.respond_to?(attr.to_sym)
data = data.send(attr.to_sym)
end
end
diff --git a/chef/spec/unit/knife/data_bag_create_spec.rb b/chef/spec/unit/knife/data_bag_create_spec.rb
index 9dae1bbd4e..33e3766182 100644
--- a/chef/spec/unit/knife/data_bag_create_spec.rb
+++ b/chef/spec/unit/knife/data_bag_create_spec.rb
@@ -18,10 +18,24 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+module ChefSpecs
+ class ChefRest
+ attr_reader :args_received
+ def initialize
+ @args_received = []
+ end
+
+ def post_rest(*args)
+ @args_received << args
+ end
+ end
+end
+
+
describe Chef::Knife::DataBagCreate do
before do
@knife = Chef::Knife::DataBagCreate.new
- @rest = mock("Chef::Rest")
+ @rest = ChefSpecs::ChefRest.new
@knife.stub!(:rest).and_return(@rest)
@log = Chef::Log
end
@@ -40,10 +54,10 @@ describe Chef::Knife::DataBagCreate do
@knife.instance_variable_set(:@name_args, ['sudoing_admins', 'ME'])
user_supplied_json = {"login_name" => "alphaomega", "id" => "ME"}.to_json
@knife.should_receive(:create_object).and_yield(user_supplied_json)
- @rest.should_receive(:post_rest).with("data/sudoing_admins", user_supplied_json)
+ @rest.should_receive(:post_rest).with("data", {'name' => 'sudoing_admins'}).ordered
+ @rest.should_receive(:post_rest).with("data/sudoing_admins", user_supplied_json).ordered
@knife.run
-
end
end