Skip to content
Browse files

Active Resource recognizes 410 as Resource Gone now [#2316 state:reso…

…lved] [Jordan Brough, Jatinder Singh]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 1af9bd5 commit 916b18adeb0a1ae09fdaff21dda8d0bc8ed4ffa9 Jordan Brough committed with lifo
View
2 activeresource/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Recognizes 410 as Resource Gone. #2316 [Jordan Brough, Jatinder Singh]
+
* More thorough SSL support. #2370 [Roy Nicholson]
* HTTP proxy support. #2133 [Marshall Huss, Sébastien Dabet]
View
3 activeresource/lib/active_resource/base.rb
@@ -164,6 +164,7 @@ module ActiveResource
# * 404 - ActiveResource::ResourceNotFound
# * 405 - ActiveResource::MethodNotAllowed
# * 409 - ActiveResource::ResourceConflict
+ # * 410 - ActiveResource::ResourceGone
# * 422 - ActiveResource::ResourceInvalid (rescued by save as validation errors)
# * 401..499 - ActiveResource::ClientError
# * 500..599 - ActiveResource::ServerError
@@ -626,7 +627,7 @@ def exists?(id, options = {})
response.code.to_i == 200
end
# id && !find_single(id, options).nil?
- rescue ActiveResource::ResourceNotFound
+ rescue ActiveResource::ResourceNotFound, ActiveResource::ResourceGone
false
end
View
2 activeresource/lib/active_resource/connection.rb
@@ -131,6 +131,8 @@ def handle_response(response)
raise(MethodNotAllowed.new(response))
when 409
raise(ResourceConflict.new(response))
+ when 410
+ raise(ResourceGone.new(response))
when 422
raise(ResourceInvalid.new(response))
when 401...500
View
3 activeresource/lib/active_resource/exceptions.rb
@@ -51,6 +51,9 @@ class ResourceNotFound < ClientError; end # :nodoc:
# 409 Conflict
class ResourceConflict < ClientError; end # :nodoc:
+ # 410 Gone
+ class ResourceGone < ClientError; end # :nodoc:
+
# 5xx Server Error
class ServerError < ConnectionError; end # :nodoc:
View
24 activeresource/test/base_test.rb
@@ -899,6 +899,14 @@ def test_destroy_with_custom_prefix
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
end
+ def test_destroy_with_410_gone
+ assert Person.find(1).destroy
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/1.xml", {}, nil, 410
+ end
+ assert_raise(ActiveResource::ResourceGone) { Person.find(1).destroy }
+ end
+
def test_delete
assert Person.delete(1)
ActiveResource::HttpMock.respond_to do |mock|
@@ -914,6 +922,14 @@ def test_delete_with_custom_prefix
end
assert_raise(ActiveResource::ResourceNotFound) { StreetAddress.find(1, :params => { :person_id => 1 }) }
end
+
+ def test_delete_with_410_gone
+ assert Person.delete(1)
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.get "/people/1.xml", {}, nil, 410
+ end
+ assert_raise(ActiveResource::ResourceGone) { Person.find(1) }
+ end
def test_exists
# Class method.
@@ -974,6 +990,14 @@ def test_exists_without_http_mock
assert Person.exists?('not-mocked')
end
+ def test_exists_with_410_gone
+ ActiveResource::HttpMock.respond_to do |mock|
+ mock.head "/people/1.xml", {}, nil, 410
+ end
+
+ assert !Person.exists?(1)
+ end
+
def test_to_xml
matz = Person.find(1)
xml = matz.encode
View
3 activeresource/test/connection_test.rb
@@ -56,6 +56,9 @@ def test_handle_response
# 409 is an optimistic locking error
assert_response_raises ActiveResource::ResourceConflict, 409
+ # 410 is a removed resource
+ assert_response_raises ActiveResource::ResourceGone, 410
+
# 422 is a validation error
assert_response_raises ActiveResource::ResourceInvalid, 422

0 comments on commit 916b18a

Please sign in to comment.
Something went wrong with that request. Please try again.