diff options
| author | Rick Bradley <rick@rickbradley.com> | 2008-04-02 00:48:54 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:10:39 -0500 |
| commit | f28f20b675737741a98b1b87b4791f736a996d40 (patch) | |
| tree | b67032811412f78980fe0fd0d3efa96964e3df58 /spec/unit | |
| parent | 07974401178a8b46314971bc7a9858cff1d9797b (diff) | |
Added support for destroy/DELETE over REST (including units & integrations on both webrick & mongrel).
Added pending specs for the trivialities in the REST network_fetch and network_delete methods.
Refactored YAML exception detection out into a private helper method.
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/indirector/rest.rb | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb index 37c0480ed..fb3790e0c 100755 --- a/spec/unit/indirector/rest.rb +++ b/spec/unit/indirector/rest.rb @@ -19,6 +19,28 @@ describe Puppet::Indirector::REST do @searcher = @rest_class.new end + + describe "when doing a network fetch" do + it "should escape the provided path" + it "should look up the appropriate remote server" + it "should look up the appropriate remote port" + it "should use the GET http method" + it "should use the appropriate remote server" + it "should use the appropriate remote port" + it "should use the escaped provided path" + it "should return the results of the GET request" + end + + describe "when doing a network delete" do + it "should escape the provided path" + it "should look up the appropriate remote server" + it "should look up the appropriate remote port" + it "should use the delete http method" + it "should use the appropriate remote server" + it "should use the appropriate remote port" + it "should use the escaped provided path" + it "should return the results of the DELETE request" + end describe "when doing a find" do before :each do @@ -106,9 +128,40 @@ describe Puppet::Indirector::REST do end describe "when doing a destroy" do - it "should deserialize result data into a boolean" - it "should generate an error when result data deserializes improperly" - it "should generate an error when result data specifies an error" + before :each do + @result = true.to_yaml + @searcher.stubs(:network_delete).returns(@result) # neuter the network connection + @model.stubs(:from_yaml).returns(@instance) + end + + it "should look up the model instance over the network" do + @searcher.expects(:network_delete).returns(@result) + @searcher.destroy('foo') + end + + it "should look up the model instance using the named indirection" do + @searcher.expects(:network_delete).with {|path| path =~ %r{^#{@indirection.name.to_s}/} }.returns(@result) + @searcher.destroy('foo') + end + + it "should look up the model instance using the provided key" do + @searcher.expects(:network_delete).with {|path| path =~ %r{/foo$} }.returns(@result) + @searcher.destroy('foo') + end + + it "should deserialize result data" do + YAML.expects(:load).with(@result) + @searcher.destroy('foo') + end + + it "should return deserialized result data" do + @searcher.destroy('foo').should == true + end + + it "should generate an error when result data specifies an error" do + @searcher.stubs(:network_delete).returns(RuntimeError.new("bogus").to_yaml) + lambda { @searcher.destroy('foo') }.should raise_error(RuntimeError) + end end describe "when doing a save" do |
