diff options
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/indirector/rest.rb | 11 | ||||
| -rwxr-xr-x | spec/unit/network/format_handler.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/network/http/handler.rb | 10 |
3 files changed, 26 insertions, 0 deletions
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb index 696af9ae7..a352f2a2a 100755 --- a/spec/unit/indirector/rest.rb +++ b/spec/unit/indirector/rest.rb @@ -121,6 +121,17 @@ describe Puppet::Indirector::REST do @searcher.deserialize(response, true).should == "myobjects" end + + it "should strip the content-type header to keep only the mime-type" do + @model.expects(:convert_from).with("text/plain", "mydata").returns "myobject" + + response = mock 'response' + response.stubs(:[]).with("content-type").returns "text/plain; charset=utf-8" + response.stubs(:body).returns "mydata" + response.stubs(:code).returns "200" + + @searcher.deserialize(response) + end end describe "when creating an HTTP client" do diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb index 604ae1be3..8a79a58b3 100755 --- a/spec/unit/network/format_handler.rb +++ b/spec/unit/network/format_handler.rb @@ -87,6 +87,11 @@ describe Puppet::Network::FormatHandler do lambda { Puppet::Network::FormatHandler.protected_format(:myformat).render("foo") }.should raise_error(Puppet::Network::FormatHandler::FormatError) end + it "should raise an error if we couldn't find a format by name or mime-type" do + Puppet::Network::FormatHandler.stubs(:format).with(:myformat).returns nil + lambda { Puppet::Network::FormatHandler.protected_format(:myformat) }.should raise_error + end + describe "when using formats" do before do @format = mock 'format' diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb index a0c817361..1addb5890 100755 --- a/spec/unit/network/http/handler.rb +++ b/spec/unit/network/http/handler.rb @@ -129,6 +129,16 @@ describe Puppet::Network::HTTP::Handler do @handler.do_exception(@response, "A test", 404) end + it "should raise an error if the request is formatted in an unknown format" do + @handler.stubs(:content_type_header).returns "unknown format" + lambda { @handler.request_format(@request) }.should raise_error + end + + it "should still find the correct format if content type contains charset information" do + @handler.stubs(:content_type_header).returns "text/plain; charset=UTF-8" + @handler.request_format(@request).should == "s" + end + describe "when finding a model instance" do before do @irequest = stub 'indirection_request', :method => :find, :indirection_name => "my_handler", :to_hash => {}, :key => "my_result", :model => @model_class |
