Skip to content

Commit 0dc5fe6

Browse files
committed
Allow to use either :unprocessable_entity or :unprocessable_content
There is just so much code out there referencing the old status that it's unreasoable to ask Rails users to migrate, especially since there is 0 gain from the rename. It's even more problematic because there are many gems and such, so they all need to be updated to check the Rack version to know which symbol to emit.
1 parent b0ff636 commit 0dc5fe6

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

actionpack/lib/action_controller/metal/redirecting.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ def _allow_other_host
249249

250250
def _extract_redirect_to_status(options, response_options)
251251
if options.is_a?(Hash) && options.key?(:status)
252-
Rack::Utils.status_code(options.delete(:status))
252+
ActionDispatch::Response.rack_status_code(options.delete(:status))
253253
elsif response_options.key?(:status)
254-
Rack::Utils.status_code(response_options[:status])
254+
ActionDispatch::Response.rack_status_code(response_options[:status])
255255
else
256256
302
257257
end

actionpack/lib/action_controller/metal/rendering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _normalize_options(options)
238238
end
239239

240240
if options[:status]
241-
options[:status] = Rack::Utils.status_code(options[:status])
241+
options[:status] = ActionDispatch::Response.rack_status_code(options[:status])
242242
end
243243

244244
super

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ class Response
4646
Headers = ::Rack::Utils::HeaderHash
4747
end
4848

49+
class << self
50+
if ActionDispatch::Constants::UNPROCESSABLE_CONTENT == :unprocessable_content
51+
def rack_status_code(status) # :nodoc:
52+
status = :unprocessable_content if status == :unprocessable_entity
53+
Rack::Utils.status_code(status)
54+
end
55+
else
56+
def rack_status_code(status) # :nodoc:
57+
status = :unprocessable_entity if status == :unprocessable_content
58+
Rack::Utils.status_code(status)
59+
end
60+
end
61+
end
62+
4963
# To be deprecated:
5064
Header = Headers
5165

@@ -257,7 +271,7 @@ def sent?; synchronize { @sent }; end
257271

258272
# Sets the HTTP status code.
259273
def status=(status)
260-
@status = Rack::Utils.status_code(status)
274+
@status = Response.rack_status_code(status)
261275
end
262276

263277
# Sets the HTTP response's content MIME type. For example, in the controller you

actionpack/lib/action_dispatch/middleware/exception_wrapper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def traces
178178
end
179179

180180
def self.status_code_for_exception(class_name)
181-
Rack::Utils.status_code(@@rescue_responses[class_name])
181+
ActionDispatch::Response.rack_status_code(@@rescue_responses[class_name])
182182
end
183183

184184
def show?(request)

actionpack/lib/action_dispatch/testing/assertion_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def code_and_name
3838

3939
private
4040
def code_from_name(name)
41-
GENERIC_RESPONSE_CODES[name] || Rack::Utils.status_code(name)
41+
GENERIC_RESPONSE_CODES[name] || ActionDispatch::Response.rack_status_code(name)
4242
end
4343

4444
def name_from_code(code)

0 commit comments

Comments
 (0)