spec/unit/ridley/resources/client_resource_spec.rb in ridley-0.10.2 vs spec/unit/ridley/resources/client_resource_spec.rb in ridley-0.11.0.rc1
- old
+ new
@@ -1,47 +1,32 @@
require 'spec_helper'
describe Ridley::ClientResource do
- it_behaves_like "a Ridley Resource", Ridley::ClientResource
+ subject { described_class.new(double('registry')) }
- let(:connection) { double('connection') }
+ describe "#regenerate_key" do
+ let(:client_id) { "rspec-client" }
+ before { subject.stub(find: nil) }
- describe "ClassMethods" do
- subject { Ridley::ClientResource }
+ context "when a client with the given ID exists" do
+ let(:client) { double('chef-client') }
+ before { subject.should_receive(:find).with(client_id).and_return(client) }
- describe "::regenerate_key" do
- let(:client) { double('client', name: "ridley-test") }
+ it "sets the private key to true and updates the client" do
+ client.should_receive(:private_key=).with(true)
+ subject.should_receive(:update).with(client)
- it "finds the given client and regenerates it's key" do
- client.should_receive(:regenerate_key)
- subject.should_receive(:find!).with(connection, "ridley-test").and_return(client)
-
- subject.regenerate_key(connection, "ridley-test")
+ subject.regenerate_key(client_id)
end
-
- it "returns the updated client" do
- client.should_receive(:regenerate_key)
- subject.should_receive(:find!).with(connection, "ridley-test").and_return(client)
-
- subject.regenerate_key(connection, "ridley-test").should eql(client)
- end
end
- end
- subject do
- Ridley::ClientResource.new(connection, name: "ridley-test", admin: false)
- end
+ context "when a client with the given ID does not exist" do
+ before { subject.should_receive(:find).with(client_id).and_return(nil) }
- describe "#regenerate_key" do
- it "returns true if successful" do
- subject.should_receive(:save).and_return(true)
-
- subject.regenerate_key.should be_true
- end
-
- it "returns false if not successful" do
- subject.should_receive(:save).and_return(false)
-
- subject.regenerate_key.should be_false
+ it "raises a ResourceNotFound error" do
+ expect {
+ subject.regenerate_key(client_id)
+ }.to raise_error(Ridley::Errors::ResourceNotFound)
+ end
end
end
end