mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #34004 from simonc/constraints-call-matches-edge-case
Fixing an edge case when using objects as constraints
This commit is contained in:
commit
6a73faa5c4
2 changed files with 28 additions and 1 deletions
|
@ -50,7 +50,19 @@ module ActionDispatch
|
|||
|
||||
private
|
||||
def constraint_args(constraint, request)
|
||||
constraint.arity == 1 ? [request] : [request.path_parameters, request]
|
||||
arity = if constraint.respond_to?(:arity)
|
||||
constraint.arity
|
||||
else
|
||||
constraint.method(:call).arity
|
||||
end
|
||||
|
||||
if arity < 1
|
||||
[]
|
||||
elsif arity == 1
|
||||
[request]
|
||||
else
|
||||
[request.path_parameters, request]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -115,6 +115,21 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
|||
assert_equal 301, status
|
||||
end
|
||||
|
||||
def test_accepts_a_constraint_object_responding_to_call
|
||||
constraint = Class.new do
|
||||
def call(*); true; end
|
||||
def matches?(*); false; end
|
||||
end
|
||||
|
||||
draw do
|
||||
get "/", to: "home#show", constraints: constraint.new
|
||||
end
|
||||
|
||||
assert_nothing_raised do
|
||||
get "/"
|
||||
end
|
||||
end
|
||||
|
||||
def test_namespace_with_controller_segment
|
||||
assert_raise(ArgumentError) do
|
||||
draw do
|
||||
|
|
Loading…
Reference in a new issue