mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
f9b3694870
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4887 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
require "#{File.dirname(__FILE__)}/abstract_unit"
|
|
|
|
class ConnectionTest < Test::Unit::TestCase
|
|
Response = Struct.new(:code)
|
|
|
|
def setup
|
|
@conn = ActiveResource::Connection.new('http://localhost')
|
|
end
|
|
|
|
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
|
|
|
|
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
|