Skip to content

Commit 66ca55e

Browse files
committed
Attempt to fix OPTIONS bug possible only in Rails 8.1.
1 parent db37e11 commit 66ca55e

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/rest_framework/utils.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def self.get_skipped_builtin_actions(controller_class, singular)
5656

5757
# Get the first route pattern which matches the given request.
5858
def self.get_request_route(application_routes, request)
59+
# Prefer the route already resolved by the router, since `recognize` may fail for non-anchored
60+
# routes (e.g., OPTIONS) whose `path_info` has been modified during dispatch.
61+
if route = request.env["action_dispatch.route"]
62+
return route
63+
end
64+
5965
application_routes.router.recognize(request) { |route, _| return route }
6066
end
6167

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "test_helper"
2+
3+
class Api::OptionsTest < ActionDispatch::IntegrationTest
4+
def test_api_options
5+
options "/api"
6+
assert_response(:success)
7+
end
8+
9+
def test_plain_api_options
10+
options "/api/plain"
11+
assert_response(:success)
12+
13+
options "/api/plain", as: :json
14+
assert_response(:success)
15+
16+
options "/api/plain", as: :xml
17+
assert_response(:success)
18+
end
19+
20+
def test_demo_api_options
21+
options "/api/demo"
22+
assert_response(:success)
23+
end
24+
25+
def test_test_api_options
26+
options "/api/test"
27+
assert_response(:success)
28+
29+
options "/api/test/users"
30+
assert_response(:success)
31+
end
32+
end

0 commit comments

Comments
 (0)