From 916b18adeb0a1ae09fdaff21dda8d0bc8ed4ffa9 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Sun, 9 Aug 2009 22:53:04 +0100 Subject: Active Resource recognizes 410 as Resource Gone now [#2316 state:resolved] [Jordan Brough, Jatinder Singh] Signed-off-by: Pratik Naik --- activeresource/test/base_test.rb | 24 ++++++++++++++++++++++++ activeresource/test/connection_test.rb | 3 +++ 2 files changed, 27 insertions(+) (limited to 'activeresource/test') diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index cba675177a..9c236bc893 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -899,6 +899,14 @@ class BaseTest < Test::Unit::TestCase 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 @@ class BaseTest < Test::Unit::TestCase 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 @@ class BaseTest < Test::Unit::TestCase 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 diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index b482f2dd0e..d7466c65b4 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -56,6 +56,9 @@ class ConnectionTest < Test::Unit::TestCase # 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 -- cgit v1.2.3