summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rack/response.rb43
-rw-r--r--test/spec_response.rb13
2 files changed, 36 insertions, 20 deletions
diff --git a/lib/rack/response.rb b/lib/rack/response.rb
index 2b23406f..1fe23a8a 100644
--- a/lib/rack/response.rb
+++ b/lib/rack/response.rb
@@ -115,26 +115,29 @@ module Rack
alias headers header
module Helpers
- def invalid?; status < 100 || status >= 600; end
-
- def informational?; status >= 100 && status < 200; end
- def successful?; status >= 200 && status < 300; end
- def redirection?; status >= 300 && status < 400; end
- def client_error?; status >= 400 && status < 500; end
- def server_error?; status >= 500 && status < 600; end
-
- def ok?; status == 200; end
- def created?; status == 201; end
- def accepted?; status == 202; end
- def bad_request?; status == 400; end
- def unauthorized?; status == 401; end
- def forbidden?; status == 403; end
- def not_found?; status == 404; end
- def method_not_allowed?; status == 405; end
- def i_m_a_teapot?; status == 418; end
- def unprocessable?; status == 422; end
-
- def redirect?; [301, 302, 303, 307].include? status; end
+ def invalid?; status < 100 || status >= 600; end
+
+ def informational?; status >= 100 && status < 200; end
+ def successful?; status >= 200 && status < 300; end
+ def redirection?; status >= 300 && status < 400; end
+ def client_error?; status >= 400 && status < 500; end
+ def server_error?; status >= 500 && status < 600; end
+
+ def ok?; status == 200; end
+ def created?; status == 201; end
+ def accepted?; status == 202; end
+ def no_content?; status == 204; end
+ def moved_permanently?; status == 301; end
+ def bad_request?; status == 400; end
+ def unauthorized?; status == 401; end
+ def forbidden?; status == 403; end
+ def not_found?; status == 404; end
+ def method_not_allowed?; status == 405; end
+ def precondition_failed?; status == 412; end
+ def i_m_a_teapot?; status == 418; end
+ def unprocessable?; status == 422; end
+
+ def redirect?; [301, 302, 303, 307].include? status; end
# Headers
attr_reader :headers, :original_headers
diff --git a/test/spec_response.rb b/test/spec_response.rb
index 6b13c0c9..20a2d0c3 100644
--- a/test/spec_response.rb
+++ b/test/spec_response.rb
@@ -231,6 +231,14 @@ describe Rack::Response do
res.should.be.successful
res.should.be.accepted
+ res.status = 204
+ res.should.be.successful
+ res.should.be.no_content
+
+ res.status = 301
+ res.should.be.redirect
+ res.should.be.moved_permanently
+
res.status = 400
res.should.not.be.successful
res.should.be.client_error
@@ -251,6 +259,11 @@ describe Rack::Response do
res.should.be.client_error
res.should.be.method_not_allowed
+ res.status = 412
+ res.should.not.be.successful
+ res.should.be.client_error
+ res.should.be.precondition_failed
+
res.status = 418
res.should.not.be.successful
res.should.be.client_error