From 4cdeef2e54aafaea152304fd67551e1a240d724d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 23 Mar 2015 01:50:03 +0100 Subject: [PATCH] Added Net::HTTPCreated support. --- lib/user_agent.rb | 12 ++++++++++++ test/integration/user_agent_test.rb | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/user_agent.rb b/lib/user_agent.rb index d881f8fbd..3f8a16412 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -314,6 +314,18 @@ returns :success => true, :code => response.code, ) + when Net::HTTPCreated + data = nil + if options[:json] && response.body + data = JSON.parse( response.body ) + end + return Result.new( + :data => data, + :body => response.body, + :content_type => response['Content-Type'], + :success => true, + :code => response.code, + ) end raise "Unable to process http call '#{response.inspect}'" diff --git a/test/integration/user_agent_test.rb b/test/integration/user_agent_test.rb index f720e47e9..a56dec7b8 100644 --- a/test/integration/user_agent_test.rb +++ b/test/integration/user_agent_test.rb @@ -38,7 +38,7 @@ class UserAgentTest < ActiveSupport::TestCase ) assert(result) assert_equal(true, result.success?) - assert_equal('200', result.code) + assert_equal('201', result.code) assert_equal(String, result.body.class) assert(result.body =~ /"post"/) assert(result.body =~ /"some value"/) @@ -151,7 +151,7 @@ class UserAgentTest < ActiveSupport::TestCase ) assert(result) assert_equal(true, result.success?) - assert_equal('200', result.code) + assert_equal('201', result.code) assert_equal(String, result.body.class) assert(result.body =~ /"post"/) assert(result.body =~ /"some value"/) @@ -468,7 +468,7 @@ class UserAgentTest < ActiveSupport::TestCase ) assert(result) assert_equal(true, result.success?) - assert_equal('200', result.code) + assert_equal('201', result.code) assert_equal(String, result.body.class) assert(result.body =~ /"content_type_requested"/) assert(result.body =~ /"application\/json"/)