Skip to content

Commit

Permalink
Make polymorphic_url compact given array [#1317 state:committed]
Browse files Browse the repository at this point in the history
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
hiroshi authored and dhh committed Nov 14, 2008
1 parent ff4ccb8 commit 94d6716
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*2.2.1 [RC2 or 2.2 final]*

* Fixed that polymorphic_url should compact given array #1317 [hiroshi]

* Fixed the sanitize helper to avoid double escaping already properly escaped entities #683 [antonmos/Ryan McGeary]

* Fixed that FormTagHelper generated illegal html if name contained square brackets #1238 [Vladimir Dobriakov]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/polymorphic_routes.rb
Expand Up @@ -73,7 +73,7 @@ module PolymorphicRoutes
#
def polymorphic_url(record_or_hash_or_array, options = {})
if record_or_hash_or_array.kind_of?(Array)
record_or_hash_or_array = record_or_hash_or_array.dup
record_or_hash_or_array = record_or_hash_or_array.compact
end

record = extract_record(record_or_hash_or_array)
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/controller/polymorphic_routes_test.rb
Expand Up @@ -169,6 +169,17 @@ def test_nesting_with_array_containing_singleton_resource_and_format_option
polymorphic_url([@article, :response, @tag], :format => :pdf)
end

def test_nesting_with_array_containing_nil
expects(:article_response_url).with(@article)
polymorphic_url([@article, nil, :response])
end

def test_with_array_containing_single_object
@article.save
expects(:article_url).with(@article)
polymorphic_url([nil, @article])
end

# TODO: Needs to be updated to correctly know about whether the object is in a hash or not
def xtest_with_hash
expects(:article_url).with(@article)
Expand Down

1 comment on commit 94d6716

@tekin
Copy link
Contributor

@tekin tekin commented on 94d6716 Nov 14, 2008

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a simple tweak, but it makes me happy!

Please sign in to comment.