diff options
author | danielsdeleo <dan@opscode.com> | 2013-11-25 15:18:59 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-11-25 16:48:04 -0800 |
commit | 8f65963c38cd35c9703991e5d8e24ada07902ec4 (patch) | |
tree | 433001ff5dfa3efe8e3627e1287a583fd31453de /chef | |
parent | f32fe0489862c9092aac2b631aba6f318d626a94 (diff) | |
download | chef-8f65963c38cd35c9703991e5d8e24ada07902ec4.tar.gz |
Add regression test for content type mangling issue
Diffstat (limited to 'chef')
-rw-r--r-- | chef/spec/unit/rest_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index 84f81a195c..91c994a816 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -423,6 +423,36 @@ describe Chef::REST do @rest.api_request(:GET, @url, {}).should == {"ohai2u"=>"json_api"} end + context "when sending a request with a body and the content-type isn't JSON" do + + let(:expected_headers) do + @base_headers.merge("content-type" => 'application/x-binary', 'Content-Length' => '13') + end + + let(:request_headers) do + {"content-type" => 'application/x-binary'} + end + + let(:request_body) do + Chef::JSONCompat.to_json({:one=>:two}) + end + + it "should build a new HTTP POST request" do + request = Net::HTTP::Post.new(@url.path) + Net::HTTP::Post.should_receive(:new).with("/?foo=bar", expected_headers).and_return(request) + @rest.raw_http_request(:POST, @url, request_headers, request_body) + request.body.should == '{"one":"two"}' + end + + it "should build a new HTTP PUT request" do + request = Net::HTTP::Put.new(@url.path) + Net::HTTP::Put.should_receive(:new).with("/?foo=bar",expected_headers).and_return(request) + @rest.raw_http_request(:PUT, @url, request_headers, request_body) + request.body.should == '{"one":"two"}' + end + + end + describe "when the server returns a redirect response" do let(:redirected_url) { "https://chef.example.com:8443/foo" } let(:redirected_uri) { URI.parse(redirected_url) } |