From 4e24fec42ae3b47857c7a0554559606e7f49bf64 Mon Sep 17 00:00:00 2001 From: Hiroshi Saito Date: Sun, 16 Nov 2008 17:51:39 +0900 Subject: [PATCH] Let polymorphic_path treat an array contains single name as without array. --- .../lib/action_controller/polymorphic_routes.rb | 1 + .../test/controller/polymorphic_routes_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index 2644c7f..28722c9 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -74,6 +74,7 @@ module ActionController 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) diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb index efa3c44..42dbea3 100644 --- a/actionpack/test/controller/polymorphic_routes_test.rb +++ b/actionpack/test/controller/polymorphic_routes_test.rb @@ -179,6 +179,12 @@ uses_mocha 'polymorphic URL helpers' do 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) -- 1.5.4.5