public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed that ActiveResource#post would post an empty string when it shouldn't be 
posting anything (Paolo Angelini) [#525 state:committed]
dhh (author)
Thu Oct 30 04:47:23 -0700 2008
commit  dffc2e2b64c89fdb0303bd18eccc7351ed0a0a58
tree    71b9429a420c6c8dbb272e4a1236ede773c46b67
parent  ea2545fd8dfcaafcf6eff58c0afe57c55e2c6317
...
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
0
@@ -1,3 +1,8 @@
0
+*2.2.1 [RC2 or 2.2 final]*
0
+
0
+* Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 [Paolo Angelini]
0
+
0
+
0
 *2.2.0 [RC1] (October 24th, 2008)*
0
 
0
 * Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 [Rasik Pandey, Cody Fauser]
...
90
91
92
93
 
94
95
96
...
90
91
92
 
93
94
95
96
0
@@ -90,7 +90,7 @@ module ActiveResource
0
       end
0
 
0
       def post(method_name, options = {}, body = nil)
0
-        request_body = body.nil? ? encode : body
0
+        request_body = body.blank? ? encode : body
0
         if new?
0
           connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)
0
         else
...
81
82
83
 
 
84
85
86
...
81
82
83
84
85
86
87
88
0
@@ -81,6 +81,8 @@ class CustomMethodsTest < Test::Unit::TestCase
0
     # Test POST against a new element URL
0
     ryan = Person.new(:name => 'Ryan')
0
     assert_equal ActiveResource::Response.new(@ryan, 201, {'Location' => '/people/5.xml'}), ryan.post(:register)
0
+    expected_request = ActiveResource::Request.new(:post, '/people/new/register.xml', @ryan)
0
+    assert_equal expected_request.body, ActiveResource::HttpMock.requests.first.body
0
 
0
     # Test POST against a nested collection URL
0
     addy = StreetAddress.new(:street => '123 Test Dr.', :person_id => 1)

Comments

maccman Sun Nov 30 04:09:08 -0800 2008

Um, isn’t that the wrong way round?

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

maccman Sun Nov 30 04:13:12 -0800 2008

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