aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb4
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb10
3 files changed, 14 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 76b7e44ced..2a5bbee72f 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added that Array#to_param calls to_param on all it's elements #10473 [brandon]
+
* Ensure asset cache directories are automatically created. #10337 [Josh Peek, Chu Yeow]
* render :xml and :json preserve custom content types. #10388 [jmettraux, Chu Yeow]
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index c828e84112..7574dc13cd 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -24,9 +24,9 @@ module ActiveSupport #:nodoc:
end
end
- # When an array is given to url_for, it is converted to a slash separated string.
+ # Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
def to_param
- join '/'
+ map(&:to_param).join '/'
end
# Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index d8ec45b62a..840a4c81d1 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -16,6 +16,12 @@ class ArrayExtAccessTests < Test::Unit::TestCase
end
class ArrayExtToParamTests < Test::Unit::TestCase
+ class ToParam < String
+ def to_param
+ "#{self}1"
+ end
+ end
+
def test_string_array
assert_equal '', %w().to_param
assert_equal 'hello/world', %w(hello world).to_param
@@ -25,6 +31,10 @@ class ArrayExtToParamTests < Test::Unit::TestCase
def test_number_array
assert_equal '10/20', [10, 20].to_param
end
+
+ def test_to_param_array
+ assert_equal 'custom1/param1', [ToParam.new('custom'), ToParam.new('param')].to_param
+ end
end
class ArrayExtToSentenceTests < Test::Unit::TestCase