mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
passing a nil in the polymorphic array is not supported. remove nils before you call the method
This commit is contained in:
parent
3d87c26845
commit
c1c6f514f4
2 changed files with 8 additions and 4 deletions
|
@ -104,6 +104,10 @@ module ActionDispatch
|
|||
recipient = self
|
||||
|
||||
if record_or_hash_or_array.kind_of?(Array)
|
||||
if record_or_hash_or_array.any?(&:nil?)
|
||||
raise ArgumentError, "Nil location provided. Can't build URI."
|
||||
end
|
||||
record_or_hash_or_array = record_or_hash_or_array.dup
|
||||
if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy)
|
||||
recipient = record_or_hash_or_array.shift
|
||||
end
|
||||
|
|
|
@ -320,17 +320,17 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_nesting_with_array_containing_nil
|
||||
def test_nesting_with_array
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, nil, :bid])
|
||||
assert_equal "http://example.com/projects/#{@project.id}/bid", polymorphic_url([@project, :bid])
|
||||
end
|
||||
end
|
||||
|
||||
def test_with_array_containing_single_object
|
||||
with_test_routes do
|
||||
@project.save
|
||||
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url([nil, @project])
|
||||
assert_equal "http://example.com/projects/#{@project.id}", polymorphic_url([@project])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -463,7 +463,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
|
|||
def test_with_array_containing_single_irregular_plural_object
|
||||
with_test_routes do
|
||||
@tax.save
|
||||
assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url([nil, @tax])
|
||||
assert_equal "http://example.com/taxes/#{@tax.id}", polymorphic_url([@tax])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue