summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http/handler.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-24 21:17:15 -0500
committerLuke Kanies <luke@madstop.com>2008-08-26 22:40:41 -0700
commit151a54ff7ac69aa2fa1708188ad75e444158e8a2 (patch)
tree5cfe9c206a819a2131fa146e1e04b9423b0f20b4 /spec/unit/network/http/handler.rb
parentdeda6465f50b582f3b8c77204965db331ba81faa (diff)
downloadpuppet-151a54ff7ac69aa2fa1708188ad75e444158e8a2.tar.gz
puppet-151a54ff7ac69aa2fa1708188ad75e444158e8a2.tar.xz
puppet-151a54ff7ac69aa2fa1708188ad75e444158e8a2.zip
Causing format selection to fail intelligently if no suitable format can be picked.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/network/http/handler.rb')
-rwxr-xr-xspec/unit/network/http/handler.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 6fc932091..ed0f25121 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -224,6 +224,9 @@ describe Puppet::Network::HTTP::Handler do
@handler.stubs(:singular?).returns(true)
@handler.stubs(:request_key).returns('key')
@model_class.stubs(:find).returns @result
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should fail to find model if key is not specified" do
@@ -246,6 +249,28 @@ describe Puppet::Network::HTTP::Handler do
@handler.do_find(@request, @response)
end
+ it "should fail if no accept header is provided" do
+ @handler.expects(:accept_header).with(@request).returns nil
+ lambda { @handler.do_find(@request, @response) }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if the accept header does not contain a valid format" do
+ @handler.expects(:accept_header).with(@request).returns ""
+ lambda { @handler.do_find(@request, @response) }.should raise_error(RuntimeError)
+ end
+
+ it "should not use an unsuitable format" do
+ @handler.expects(:accept_header).with(@request).returns "foo,bar"
+ foo = mock 'foo', :suitable? => false
+ bar = mock 'bar', :suitable? => true
+ Puppet::Network::FormatHandler.expects(:format).with("foo").returns foo
+ Puppet::Network::FormatHandler.expects(:format).with("bar").returns bar
+
+ @handler.expects(:set_content_type).with(@response, "bar") # the suitable one
+
+ @handler.do_find(@request, @response)
+ end
+
it "should render the result using the first format specified in the accept header" do
@handler.expects(:accept_header).with(@request).returns "one,two"
@result.expects(:render).with("one")
@@ -298,6 +323,9 @@ describe Puppet::Network::HTTP::Handler do
@result = [@result1, @result2]
@model_class.stubs(:render_multiple).returns "my rendered instances"
@model_class.stubs(:search).returns(@result)
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should use a common method for determining the request parameters" do
@@ -409,6 +437,9 @@ describe Puppet::Network::HTTP::Handler do
@model_instance = stub('indirected model instance', :save => true)
@model_class.stubs(:convert_from).returns(@model_instance)
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should use the 'body' hook to retrieve the body of the request" do