diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-02 14:29:08 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-02 14:29:08 -0700 |
commit | c1c6f514f482f8880beb8bf6e7471a201ce8af30 (patch) | |
tree | 5ac7e02c203096cb78b218829e4af793aee97829 | |
parent | 3d87c26845095438b6c946dc4e1029280593fb91 (diff) | |
download | rails-c1c6f514f482f8880beb8bf6e7471a201ce8af30.tar.gz rails-c1c6f514f482f8880beb8bf6e7471a201ce8af30.tar.bz2 rails-c1c6f514f482f8880beb8bf6e7471a201ce8af30.zip |
passing a nil in the polymorphic array is not supported. remove nils before you call the method
-rw-r--r-- | actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 4 | ||||
-rw-r--r-- | actionview/test/activerecord/polymorphic_routes_test.rb | 8 |
2 files changed, 8 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 729b1a0116..cbc4c9d65e 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -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 diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index c1f5a75cd4..1ead18518a 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -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 |