From cd1a9ed991e8988dbcc28023b91e76b5ee45f79b Mon Sep 17 00:00:00 2001 From: Lance Ivy Date: Sat, 22 Nov 2008 13:10:12 -0600 Subject: Add TestResponse#client_error? to check for 4xx status codes [#851 state:resolved] Signed-off-by: Joshua Peek --- actionpack/lib/action_controller/test_process.rb | 7 ++++++- actionpack/test/controller/action_pack_assertions_test.rb | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 3aceb20814..cd3914f011 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -200,6 +200,11 @@ module ActionController #:nodoc: alias_method :server_error?, :error? + # Was there a client client? + def client_error? + (400..499).include?(response_code) + end + # Returns the redirection location or nil def redirect_url headers['Location'] @@ -283,7 +288,7 @@ module ActionController #:nodoc: # See AbstractResponse for more information on controller response objects. class TestResponse < AbstractResponse include TestResponseBehavior - + def recycle! headers.delete('ETag') headers.delete('Last-Modified') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 7050000dd8..6cad0e2827 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -366,6 +366,12 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase assert @response.missing? end + # check client errors + def test_client_error_response_code + process :response404 + assert @response.client_error? + end + # check to see if our redirection matches a pattern def test_redirect_url_match process :redirect_external -- cgit v1.2.3