From 5e48c40f888feac048adbedaea6fd551d74222eb Mon Sep 17 00:00:00 2001 From: Sean O'Brien Date: Sat, 15 Nov 2008 22:06:23 -0800 Subject: [PATCH] Added support for passing a symbol as the record to polymorphic_url --- .../lib/action_controller/polymorphic_routes.rb | 3 ++- .../test/controller/polymorphic_routes_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index 2644c7f..2f33c67 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -181,13 +181,14 @@ module ActionController end end - # Remove the first symbols from the array and return the url prefix + # Remove all but the last symbols from the array and return the url prefix # implied by those symbols. def extract_namespace(record_or_hash_or_array) return "" unless record_or_hash_or_array.is_a?(Array) namespace_keys = [] while (key = record_or_hash_or_array.first) && key.is_a?(String) || key.is_a?(Symbol) + break if record_or_hash_or_array.size == 1 && key.is_a?(Symbol) namespace_keys << record_or_hash_or_array.shift end diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb index efa3c44..a974f98 100644 --- a/actionpack/test/controller/polymorphic_routes_test.rb +++ b/actionpack/test/controller/polymorphic_routes_test.rb @@ -173,6 +173,11 @@ uses_mocha 'polymorphic URL helpers' do polymorphic_url([@article, nil, :response]) end + def test_with_array_containing_symbols + expects(:new_article_url).with() + polymorphic_url([:new, :article]) + end + def test_with_array_containing_single_object @article.save expects(:article_url).with(@article) -- 1.6.0.2