Permalink
Browse files

AD::StatusCodes support is now part of rack

  • Loading branch information...
josh committed Dec 22, 2009
1 parent 17b6053 commit a1bf2f96ce6f086de8519e344ee7e396ae3da9bb
@@ -90,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk)
end
if options[:status]
- options[:status] = ActionDispatch::StatusCodes[options[:status]]
+ options[:status] = Rack::Utils.status_code(options[:status])
end
options[:update] = blk if block_given?
@@ -69,7 +69,7 @@ def location=(url)
end
def status=(status)
- @_status = ActionDispatch::StatusCodes[status]
+ @_status = Rack::Utils.status_code(status)
end
# :api: private
@@ -58,18 +58,18 @@ def redirect_to(options = {}, response_status = {}) #:doc:
logger.info("Redirected to #{location}") if logger && logger.info?
end
-
+
private
def _extract_redirect_to_status(options, response_status)
status = if options.is_a?(Hash) && options.key?(:status)
- ActionDispatch::StatusCodes[options.delete(:status)]
+ Rack::Utils.status_code(options.delete(:status))
elsif response_status.key?(:status)
- ActionDispatch::StatusCodes[response_status[:status]]
+ Rack::Utils.status_code(response_status[:status])
else
302
end
end
-
+
def _compute_redirect_to_location(options)
case options
# The scheme name consist of a letter followed by any combination of
@@ -37,7 +37,6 @@ module ActionDispatch
autoload_under 'http' do
autoload :Request
autoload :Response
- autoload :StatusCodes
end
deferrable do
@@ -60,7 +60,7 @@ def cache_control
end
def status=(status)
- @status = ActionDispatch::StatusCodes[status]
+ @status = Rack::Utils.status_code(status)
end
# The response code of the request
@@ -74,7 +74,7 @@ def code
end
def message
- StatusCodes::STATUS_CODES[@status]
+ Rack::Utils::HTTP_STATUS_CODES[@status]
end
alias_method :status_message, :message
@@ -1,33 +0,0 @@
-require 'active_support/inflector'
-
-module ActionDispatch
- module StatusCodes #:nodoc:
- STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({
- 102 => "Processing",
- 207 => "Multi-Status",
- 226 => "IM Used",
- 422 => "Unprocessable Entity",
- 423 => "Locked",
- 424 => "Failed Dependency",
- 426 => "Upgrade Required",
- 507 => "Insufficient Storage",
- 510 => "Not Extended"
- }).freeze
-
- def self.[](status)
- if status.is_a?(Symbol)
- SYMBOL_TO_STATUS_CODE[status] || 500
- else
- status.to_i
- end
- end
-
- # Provides a symbol-to-fixnum lookup for converting a symbol (like
- # :created or :not_implemented) into its corresponding HTTP status
- # code (like 200 or 501).
- SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)|
- hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
- hash
- }.freeze
- end
-end
@@ -101,7 +101,7 @@ def local_request?(request)
end
def status_code(exception)
- ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]]
+ Rack::Utils.status_code(@@rescue_responses[exception.class.name])
end
def render(status, body)
@@ -28,7 +28,7 @@ def assert_response(type, message = nil)
assert_block("") { true } # to count the assertion
elsif type.is_a?(Fixnum) && @response.response_code == type
assert_block("") { true } # to count the assertion
- elsif type.is_a?(Symbol) && @response.response_code == ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
+ elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
assert_block("") { true } # to count the assertion
else
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
@@ -1125,15 +1125,15 @@ def test_head_with_symbolic_status
assert !@response.headers.include?('Content-Length')
assert_response :no_content
- ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
+ Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |status, code|
get :head_with_symbolic_status, :status => status.to_s
assert_equal code, @response.response_code
assert_response status
end
end
def test_head_with_integer_status
- ActionDispatch::StatusCodes::STATUS_CODES.each do |code, message|
+ Rack::Utils::HTTP_STATUS_CODES.each do |code, message|
get :head_with_integer_status, :status => code.to_s
assert_equal message, @response.message
end

0 comments on commit a1bf2f9

Please sign in to comment.