summary refs log tree commit
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2013-06-28 15:48:03 -0400
committerPrem Sichanugrist <s@sikac.hu>2013-06-28 15:48:03 -0400
commitcf13f31a74c46eb79032428d5efd176c4c35187c (patch)
treed3dd708eb302966beff65a852e2e99b5697c9456
parentb33032395de77ec15237c28d603a3962d5c481f2 (diff)
downloadrack-cf13f31a74c46eb79032428d5efd176c4c35187c.tar.gz
Add Response#unauthorized? helper
This helper should come in handy when you want to test the authorization
in your application.
-rw-r--r--lib/rack/response.rb1
-rw-r--r--test/spec_response.rb5
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/rack/response.rb b/lib/rack/response.rb
index 2beba7a8..2076aff0 100644
--- a/lib/rack/response.rb
+++ b/lib/rack/response.rb
@@ -122,6 +122,7 @@ module Rack
 
       def ok?;                 status == 200;                        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
diff --git a/test/spec_response.rb b/test/spec_response.rb
index 7ba1e0e1..0ba17b15 100644
--- a/test/spec_response.rb
+++ b/test/spec_response.rb
@@ -216,6 +216,11 @@ describe Rack::Response do
     res.should.be.client_error
     res.should.be.bad_request
 
+    res.status = 401
+    res.should.not.be.successful
+    res.should.be.client_error
+    res.should.be.unauthorized
+
     res.status = 404
     res.should.not.be.successful
     res.should.be.client_error