Skip to content

Commit

Permalink
Add TestResponse#client_error? to check for 4xx status codes [#851 st…
Browse files Browse the repository at this point in the history
…ate:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
cainlevy authored and josh committed Nov 22, 2008
1 parent f42c77f commit cd1a9ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion actionpack/lib/action_controller/test_process.rb
Expand Up @@ -200,6 +200,11 @@ def error?

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']
Expand Down Expand Up @@ -283,7 +288,7 @@ def binary_content
# See AbstractResponse for more information on controller response objects.
class TestResponse < AbstractResponse
include TestResponseBehavior

def recycle!
headers.delete('ETag')
headers.delete('Last-Modified')
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/action_pack_assertions_test.rb
Expand Up @@ -366,6 +366,12 @@ def test_missing_response_code
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
Expand Down

0 comments on commit cd1a9ed

Please sign in to comment.