From dffc2e2b64c89fdb0303bd18eccc7351ed0a0a58 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 30 Oct 2008 12:47:23 +0100 Subject: [PATCH] Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything (Paolo Angelini) [#525 state:committed] --- activeresource/CHANGELOG | 5 +++++ activeresource/lib/active_resource/custom_methods.rb | 2 +- activeresource/test/base/custom_methods_test.rb | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index 74ca71f65afd6..114a63c4153fb 100644 --- a/activeresource/CHANGELOG +++ b/activeresource/CHANGELOG @@ -1,3 +1,8 @@ +*2.2.1 [RC2 or 2.2 final]* + +* Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 [Paolo Angelini] + + *2.2.0 [RC1] (October 24th, 2008)* * Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 [Rasik Pandey, Cody Fauser] diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index 24306f251de9c..4647e8342c206 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -90,7 +90,7 @@ def get(method_name, options = {}) end def post(method_name, options = {}, body = nil) - request_body = body.nil? ? encode : body + request_body = body.blank? ? encode : body if new? connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers) else diff --git a/activeresource/test/base/custom_methods_test.rb b/activeresource/test/base/custom_methods_test.rb index ba5799edfbbf0..61887f4ec7f83 100644 --- a/activeresource/test/base/custom_methods_test.rb +++ b/activeresource/test/base/custom_methods_test.rb @@ -81,6 +81,8 @@ def test_custom_new_element_method # Test POST against a new element URL ryan = Person.new(:name => 'Ryan') assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register) + expected_request = ActiveResource::Request.new(:post, '/people/new/register.xml', @ryan) + assert_equal expected_request.body, ActiveResource::HttpMock.requests.first.body # Test POST against a nested collection URL addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1)