aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test/cases
diff options
context:
space:
mode:
authorJohn Mileham <jmileham@gmail.com>2011-08-24 15:18:55 -0400
committerJohn Mileham <jmileham@gmail.com>2011-09-09 19:05:26 -0400
commitf776661fd2d93f9a8c01f97a4c4bc3ca97c3718d (patch)
treecd5ab4f4ee166fc58c1802abd0b613514256296c /activeresource/test/cases
parent5aa86f793f4df75f8a5780626269abc3511c61a0 (diff)
downloadrails-f776661fd2d93f9a8c01f97a4c4bc3ca97c3718d.tar.gz
rails-f776661fd2d93f9a8c01f97a4c4bc3ca97c3718d.tar.bz2
rails-f776661fd2d93f9a8c01f97a4c4bc3ca97c3718d.zip
Failing test: ActiveResource shouldn't rely on the presence of Content-Length
Diffstat (limited to 'activeresource/test/cases')
-rw-r--r--activeresource/test/cases/base_test.rb30
1 files changed, 27 insertions, 3 deletions
diff --git a/activeresource/test/cases/base_test.rb b/activeresource/test/cases/base_test.rb
index f45652d988..d4063fa299 100644
--- a/activeresource/test/cases/base_test.rb
+++ b/activeresource/test/cases/base_test.rb
@@ -636,13 +636,37 @@ class BaseTest < Test::Unit::TestCase
assert_nil p.__send__(:id_from_response, resp)
end
- def test_load_attributes_from_response
- p = Person.new
+ def test_not_persisted_with_no_body_and_positive_content_length
resp = ActiveResource::Response.new(nil)
resp['Content-Length'] = "100"
- assert_nil p.__send__(:load_attributes_from_response, resp)
+ Person.connection.expects(:post).returns(resp)
+ assert !Person.create.persisted?
+ end
+
+ def test_not_persisted_with_body_and_zero_content_length
+ resp = ActiveResource::Response.new(@rick)
+ resp['Content-Length'] = "0"
+ Person.connection.expects(:post).returns(resp)
+ assert !Person.create.persisted?
end
+ # These response codes aren't allowed to have bodies per HTTP spec
+ def test_not_persisted_with_empty_response_codes
+ [100,101,204,304].each do |status_code|
+ resp = ActiveResource::Response.new(@rick, status_code)
+ Person.connection.expects(:post).returns(resp)
+ assert !Person.create.persisted?
+ end
+ end
+
+ # Content-Length is not required by HTTP 1.1, so we should read
+ # the body anyway in its absence.
+ def test_persisted_with_no_content_length
+ resp = ActiveResource::Response.new(@rick)
+ resp['Content-Length'] = nil
+ Person.connection.expects(:post).returns(resp)
+ assert Person.create.persisted?
+ end
def test_create_with_custom_prefix
matzs_house = StreetAddress.new(:person_id => 1)