summaryrefslogtreecommitdiff
path: root/spec/unit/api_client_spec.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-12-11 19:45:00 -0800
committerdanielsdeleo <dan@opscode.com>2012-12-12 13:26:16 -0800
commitbda8bbf38241c5a1dd75cd28ad9dcb89bcf808cc (patch)
treeda638269644d1e1830b658dac6056fcb31fb91da /spec/unit/api_client_spec.rb
parenta9a083f7622b9675faa9112008af321533c0e16d (diff)
downloadchef-bda8bbf38241c5a1dd75cd28ad9dcb89bcf808cc.tar.gz
[CHEF-3662] ApiClient can set a private key from JSON
Without this change it's not possible to fix CHEF-3662 on the client without modifying Chef::REST to ignore json_class. Previously the behavior was explicitly defined to be the opposite, but the reasoning behind this decision wasn't documented; I suspect it may have been for server-side behavior that's no longer necessary.
Diffstat (limited to 'spec/unit/api_client_spec.rb')
-rw-r--r--spec/unit/api_client_spec.rb39
1 files changed, 22 insertions, 17 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index 3c4cccf503..6b41f1b211 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -130,31 +130,36 @@ describe Chef::ApiClient do
end
end
- describe "deserialize" do
+ describe "when deserializing from JSON" do
before(:each) do
- @client.name("black")
- @client.public_key("crowes")
- @client.private_key("monkeypants")
- @client.admin(true)
- @deserial = Chef::JSONCompat.from_json(@client.to_json)
+ client = {
+ "name" => "black",
+ "public_key" => "crowes",
+ "private_key" => "monkeypants",
+ "admin" => true,
+ "json_class" => "Chef::ApiClient"
+ }
+ @client = Chef::JSONCompat.from_json(client.to_json)
end
it "should deserialize to a Chef::ApiClient object" do
- @deserial.should be_a_kind_of(Chef::ApiClient)
+ @client.should be_a_kind_of(Chef::ApiClient)
end
- %w{
- name
- public_key
- admin
- }.each do |t|
- it "should match '#{t}'" do
- @deserial.send(t.to_sym).should == @client.send(t.to_sym)
- end
+ it "preserves the name" do
+ @client.name.should == "black"
end
- it "should not include the private key" do
- @deserial.private_key.should == nil
+ it "preserves the public key" do
+ @client.public_key.should == "crowes"
+ end
+
+ it "preserves the admin status" do
+ @client.admin.should be_true
+ end
+
+ it "includes the private key if present" do
+ @client.private_key.should == "monkeypants"
end
end