1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Recognize and raise an exception on 405 Method Not Allowed responses. Closes #7692.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6864 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-05-26 20:57:08 +00:00
parent 404a357013
commit 849038ee51
3 changed files with 24 additions and 0 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Recognize and raise an exception on 405 Method Not Allowed responses. #7692 [Josh Peek]
* Handle string and symbol param keys when splitting params into prefix params and query params.
Comment.find(:all, :params => { :article_id => 5, :page => 2 }) or Comment.find(:all, :params => { 'article_id' => 5, :page => 2 })

View file

@ -24,6 +24,13 @@ module ActiveResource
class ServerError < ConnectionError; end # 5xx Server Error
# 405 Method Not Allowed
class MethodNotAllowed < ClientError
def allowed_methods
@response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
end
end
# Class to handle connections to remote services.
class Connection
attr_reader :site
@ -99,6 +106,8 @@ module ActiveResource
response
when 404
raise(ResourceNotFound.new(response))
when 405
raise(MethodNotAllowed.new(response))
when 409
raise(ResourceConflict.new(response))
when 422

View file

@ -41,6 +41,9 @@ class ConnectionTest < Test::Unit::TestCase
# 404 is a missing resource.
assert_response_raises ActiveResource::ResourceNotFound, 404
# 405 is a missing not allowed error
assert_response_raises ActiveResource::MethodNotAllowed, 405
# 409 is an optimistic locking error
assert_response_raises ActiveResource::ResourceConflict, 409
@ -63,6 +66,16 @@ class ConnectionTest < Test::Unit::TestCase
end
end
ResponseHeaderStub = Struct.new(:code, 'Allow')
def test_should_return_allowed_methods_for_method_no_allowed_exception
begin
handle_response ResponseHeaderStub.new(405, "GET, POST")
rescue ActiveResource::MethodNotAllowed => e
assert_equal "Failed with 405", e.message
assert_equal [:get, :post], e.allowed_methods
end
end
def test_initialize_raises_argument_error_on_missing_site
assert_raise(ArgumentError) { ActiveResource::Connection.new(nil) }
end