From b8bb5f44c8ba02786ed42d04f66641f236ef42c3 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 11 Oct 2011 21:01:11 -0700 Subject: Treat 303 See Other as a redirect response, too --- activeresource/test/cases/connection_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'activeresource/test/cases/connection_test.rb') diff --git a/activeresource/test/cases/connection_test.rb b/activeresource/test/cases/connection_test.rb index 6f33023832..535107aeef 100644 --- a/activeresource/test/cases/connection_test.rb +++ b/activeresource/test/cases/connection_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' class ConnectionTest < Test::Unit::TestCase ResponseCodeStub = Struct.new(:code) + RedirectResponseStub = Struct.new(:code, :Location) def setup @conn = ActiveResource::Connection.new('http://localhost') @@ -39,13 +40,16 @@ class ConnectionTest < Test::Unit::TestCase end # 301 is moved permanently (redirect) - assert_response_raises ActiveResource::Redirection, 301 + assert_redirect_raises 301 # 302 is found (redirect) - assert_response_raises ActiveResource::Redirection, 302 + assert_redirect_raises 302 + + # 303 is see other (redirect) + assert_redirect_raises 303 # 307 is temporary redirect - assert_response_raises ActiveResource::Redirection, 307 + assert_redirect_raises 307 # 400 is a bad request (e.g. malformed URI or missing request parameter) assert_response_raises ActiveResource::BadRequest, 400 @@ -256,6 +260,12 @@ class ConnectionTest < Test::Unit::TestCase end end + def assert_redirect_raises(code) + assert_raise(ActiveResource::Redirection, "Expected response code #{code} to raise ActiveResource::Redirection") do + handle_response RedirectResponseStub.new(code, 'http://example.com/') + end + end + def handle_response(response) @conn.__send__(:handle_response, response) end -- cgit v1.2.3