summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/indirector/rest.rb9
-rwxr-xr-xspec/unit/indirector/rest.rb6
-rwxr-xr-xspec/unit/network/http/handler.rb14
3 files changed, 28 insertions, 1 deletions
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index 86d4d4291..b307e3cab 100755
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -138,6 +138,9 @@ describe Puppet::Indirector::REST do
@model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
@mock_model.stubs(:search).returns @model_instances
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
@mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
end
@@ -354,6 +357,10 @@ describe Puppet::Indirector::REST do
describe "when matching model instances can be found" do
before :each do
@model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
@mock_model.stubs(:search).returns @model_instances
@mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
end
@@ -390,7 +397,7 @@ describe Puppet::Indirector::REST do
end
it "should return nil" do
- Puppet::TestIndirectedFoo.search('bar').should be_nil
+ Puppet::TestIndirectedFoo.search('bar').should == []
end
end
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 801e8888e..28ceb693a 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -187,6 +187,12 @@ describe Puppet::Indirector::REST do
@searcher.search(@request)
end
+ it "should return an empty array if serialization returns nil" do
+ @model.stubs(:convert_from_multiple).returns nil
+
+ @searcher.search(@request).should == []
+ end
+
it "should generate an error when result data deserializes fails" do
@searcher.expects(:deserialize).raises(ArgumentError)
lambda { @searcher.search(@request) }.should raise_error(ArgumentError)
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 1ed816d97..816c0ea2e 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -330,6 +330,20 @@ describe Puppet::Network::HTTP::Handler do
@handler.expects(:set_response).with { |response, data| data == "my rendered instances" }
@handler.do_search(@request, @response)
end
+
+ it "should return a 404 when searching returns an empty array" do
+ @model_class.stubs(:name).returns "my name"
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
+ @model_class.stubs(:search).returns([])
+ @handler.do_search(@request, @response)
+ end
+
+ it "should return a 404 when searching returns nil" do
+ @model_class.stubs(:name).returns "my name"
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
+ @model_class.stubs(:search).returns([])
+ @handler.do_search(@request, @response)
+ end
end
describe "when destroying a model instance" do