From d78072c9d254f6c6125c52311e94ab81da01902a Mon Sep 17 00:00:00 2001 From: cynipe Date: Fri, 27 Jun 2014 13:52:35 +0900 Subject: [PATCH] Fix the multibyte config is not properly configured --- lib/jenkins_api_client/client.rb | 4 ++-- spec/unit_tests/client_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 855f2ba0..fb7cfa38 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -403,11 +403,11 @@ def get_config(url_prefix) # @return [String] Response code returned from Jenkins # def post_config(url_prefix, xml) - post_data(url_prefix, xml, 'application/xml') + post_data(url_prefix, xml, 'application/xml;charset=UTF-8') end def post_json(url_prefix, json) - post_data(url_prefix, json, 'application/json') + post_data(url_prefix, json, 'application/json;charset=UTF-8') end def post_data(url_prefix, data, content_type) diff --git a/spec/unit_tests/client_spec.rb b/spec/unit_tests/client_spec.rb index 223e4045..da7db896 100644 --- a/spec/unit_tests/client_spec.rb +++ b/spec/unit_tests/client_spec.rb @@ -195,6 +195,31 @@ @client.respond_to?(:post_config).should be_true @client.method(:post_config).parameters.size.should == 2 end + + it "sets the content type with charset as UTF-8 for the multi-byte content" do + url_prefix = '/prefix' + xml = 'dummy' + content_type = 'application/xml;charset=UTF-8' + + expect(@client).to receive(:post_data).with(url_prefix, xml, content_type) + @client.post_config(url_prefix, xml) + end + end + + describe "#post_json" do + it "is defined and should accept url_prefix and json" do + @client.respond_to?(:post_json).should be_true + @client.method(:post_json).parameters.size.should == 2 + end + + it "sets the content type with charset as UTF-8 for the multi-byte content" do + url_prefix = '/prefix' + json = '{ "dummy": "dummy" }' + content_type = 'application/json;charset=UTF-8' + + expect(@client).to receive(:post_data).with(url_prefix, json, content_type) + @client.post_json(url_prefix, json) + end end describe "#get_jenkins_version" do