1
0
Fork 0
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:
Rafael Mendonça França 2018-09-27 16:36:49 -04:00
commit 6a73faa5c4
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 28 additions and 1 deletions

View file

@ -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

View file

@ -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