Skip to content

Commit

Permalink
Fix the multibyte config is not properly configured
Browse files Browse the repository at this point in the history
  • Loading branch information
cynipe committed Jun 27, 2014
1 parent 2ad9dcf commit d78072c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jenkins_api_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions spec/unit_tests/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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>dummy</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
Expand Down

0 comments on commit d78072c

Please sign in to comment.