Permalink
Browse files

passing a nil in the polymorphic array is not supported. remove nils …

…before you call the method
  • Loading branch information...
1 parent 3d87c26 commit c1c6f514f482f8880beb8bf6e7471a201ce8af30 @tenderlove tenderlove committed May 2, 2014
@@ -104,6 +104,10 @@ def polymorphic_url(record_or_hash_or_array, options = {})
recipient = self
if record_or_hash_or_array.kind_of?(Array)
+ if record_or_hash_or_array.any?(&:nil?)
@egilburg

egilburg May 2, 2014

Contributor

record_or_hash_or_array.include?(nil) simpler, no?

+ 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 @@ def test_nesting_with_array_containing_namespace_and_singleton_resource
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 @@ def test_nesting_with_irregular_plurals_and_array_ending_in_singleton_resource
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

0 comments on commit c1c6f51

Please sign in to comment.