Permalink
Browse files

Fixed that ActiveResource#post would post an empty string when it sho…

…uldn't be posting anything (Paolo Angelini) [#525 state:committed]
  • Loading branch information...
1 parent ea2545f commit dffc2e2b64c89fdb0303bd18eccc7351ed0a0a58 @dhh dhh committed Oct 30, 2008
View
@@ -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]
@@ -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
@@ -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)

2 comments on commit dffc2e2

Contributor

maccman replied Nov 30, 2008

Um, isn’t that the wrong way round?

It should be:
request_body = body.blank? ? body : encode

Contributor

maccman replied Nov 30, 2008

Actually, maybe not. I see that encode actually encodes all the attributes if body is blank. What if I want an empty post?

Please sign in to comment.