Skip to content

Commit

Permalink
Fixed that ActiveResource#post would post an empty string when it sho…
Browse files Browse the repository at this point in the history
…uldn't be posting anything (Paolo Angelini) [#525 state:committed]
  • Loading branch information
dhh committed Oct 30, 2008
1 parent ea2545f commit dffc2e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions 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]
Expand Down
2 changes: 1 addition & 1 deletion activeresource/lib/active_resource/custom_methods.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions activeresource/test/base/custom_methods_test.rb
Expand Up @@ -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)
Expand Down

2 comments on commit dffc2e2

@maccman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, isn’t that the wrong way round?

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

@maccman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.