Permalink
Browse files

Let polymorphic_path treat an array contains single name as without a…

…rray [#1386 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
1 parent af57ccb commit 591560c641d52f6a8fb12a26c60c3f812735ac0d @hiroshi hiroshi committed with dhh Nov 16, 2008
@@ -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)
@@ -180,6 +180,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)

0 comments on commit 591560c

Please sign in to comment.