aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-31 09:31:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-31 09:31:11 +0000
commitf9b369487046020bcdb92a3985270c9fb9943382 (patch)
tree0c51bb258ba729abc0cb4d15908b393c80372c82 /activeresource/test
parentc1af2db14be7a5978ee57e6b46f02e1ec8bc14f9 (diff)
downloadrails-f9b369487046020bcdb92a3985270c9fb9943382.tar.gz
rails-f9b369487046020bcdb92a3985270c9fb9943382.tar.bz2
rails-f9b369487046020bcdb92a3985270c9fb9943382.zip
200...400 are valid response codes. PUT and POST request bodies default to ''.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4887 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/connection_test.rb41
1 files changed, 36 insertions, 5 deletions
diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb
index 1c5951ca91..4790c30bed 100644
--- a/activeresource/test/connection_test.rb
+++ b/activeresource/test/connection_test.rb
@@ -1,11 +1,42 @@
require "#{File.dirname(__FILE__)}/abstract_unit"
-require "fixtures/person"
class ConnectionTest < Test::Unit::TestCase
+ Response = Struct.new(:code)
+
def setup
+ @conn = ActiveResource::Connection.new('http://localhost')
end
-
- def test_something
- true
+
+ def test_handle_response
+ # 2xx and 3xx are valid responses.
+ [200, 299, 300, 399].each do |code|
+ expected = Response.new(code)
+ assert_equal expected, @conn.send(:handle_response, expected)
+ end
+
+ # 404 is a missing resource.
+ assert_response_raises ActiveResource::ResourceNotFound, 404
+
+ # 4xx are client errors.
+ [400, 499].each do |code|
+ assert_response_raises ActiveResource::ClientError, code
+ end
+
+ # 5xx are server errors.
+ [500, 599].each do |code|
+ assert_response_raises ActiveResource::ServerError, code
+ end
+
+ # Others are unknown.
+ [199, 600].each do |code|
+ assert_response_raises ActiveResource::ConnectionError, code
+ end
end
-end \ No newline at end of file
+
+ protected
+ def assert_response_raises(klass, code)
+ assert_raise(klass, "Expected response code #{code} to raise #{klass}") do
+ @conn.send(:handle_response, Response.new(code))
+ end
+ end
+end