Skip to content

Commit ece7201

Browse files
authored
Merge pull request rails#53383 from Earlopain/rack-3.2-deprecation
Handle Rack 3.2 `unprocessable_{entity,content}`
2 parents 589fe8a + 0dc5fe6 commit ece7201

File tree

21 files changed

+49
-34
lines changed

21 files changed

+49
-34
lines changed

actionmailbox/app/controllers/action_mailbox/ingresses/mandrill/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def create
2222
head :ok
2323
rescue JSON::ParserError => error
2424
logger.error error.message
25-
head :unprocessable_entity
25+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
2626
end
2727

2828
def health_check

actionmailbox/app/controllers/action_mailbox/ingresses/postmark/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create
5757
When configuring your Postmark inbound webhook, be sure to check the box
5858
labeled "Include raw email content in JSON payload".
5959
MESSAGE
60-
head :unprocessable_entity
60+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
6161
end
6262

6363
private

actionmailbox/app/controllers/action_mailbox/ingresses/relay/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create
5555
if request.body
5656
ActionMailbox::InboundEmail.create_and_extract_message_id! request.body.read
5757
else
58-
head :unprocessable_entity
58+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5959
end
6060
end
6161

actionmailbox/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def create
5252
ActionMailbox::InboundEmail.create_and_extract_message_id! mail
5353
rescue JSON::ParserError => error
5454
logger.error error.message
55-
head :unprocessable_entity
55+
head ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5656
end
5757

5858
private

actionmailbox/test/controllers/ingresses/postmark/inbound_emails_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ActionMailbox::Ingresses::Postmark::InboundEmailsControllerTest < ActionDi
5353
headers: { authorization: credentials }, params: { From: "[email protected]" }
5454
end
5555

56-
assert_response :unprocessable_entity
56+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
5757
end
5858

5959
test "rejecting an unauthorized inbound email from Postmark" do

actionmailbox/test/controllers/ingresses/relay/inbound_emails_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ActionMailbox::Ingresses::Relay::InboundEmailsControllerTest < ActionDispa
3737
env: { "rack.input" => nil }
3838
end
3939

40-
assert_response :unprocessable_entity
40+
assert_response ActionDispatch::Constants::UNPROCESSABLE_CONTENT
4141
end
4242

4343
test "rejecting an unauthorized inbound email" do

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/constants.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ module Constants
3030
SERVER_TIMING = "server-timing"
3131
STRICT_TRANSPORT_SECURITY = "strict-transport-security"
3232
end
33+
34+
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
35+
UNPROCESSABLE_CONTENT = :unprocessable_entity
36+
else
37+
UNPROCESSABLE_CONTENT = :unprocessable_content
38+
end
3339
end
3440
end

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

0 commit comments

Comments
 (0)