Skip to content

Commit

Permalink
Let polymorphic_path treat an array contains single name as without a…
Browse files Browse the repository at this point in the history
…rray [#1386 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
hiroshi authored and dhh committed Nov 19, 2008
1 parent f451f0e commit 291d199
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_controller/polymorphic_routes.rb
Expand Up @@ -74,6 +74,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.compact
record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
end

record = extract_record(record_or_hash_or_array)
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/polymorphic_routes_test.rb
Expand Up @@ -179,6 +179,12 @@ def test_with_array_containing_single_object
polymorphic_url([nil, @article])
end

def test_with_array_containing_single_name
@article.save
expects(:articles_url)
polymorphic_url([:articles])
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

0 comments on commit 291d199

Please sign in to comment.