Skip to content
This repository
Browse code

Added that Array#to_param calls to_param on all it's elements (closes #…

…10473) [brandon]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8384 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 7a224356a88f104b6bf012e930721efb2274c2b1 1 parent 3aa54c5
David Heinemeier Hansson authored December 14, 2007
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added that Array#to_param calls to_param on all it's elements #10473 [brandon]
  4
+
3 5
 * Ensure asset cache directories are automatically created.  #10337 [Josh Peek, Chu Yeow]
4 6
 
5 7
 * render :xml and :json preserve custom content types.  #10388 [jmettraux, Chu Yeow]
4  activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -24,9 +24,9 @@ def to_sentence(options = {})
24 24
           end
25 25
         end
26 26
 
27  
-        # When an array is given to url_for, it is converted to a slash separated string.
  27
+        # Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack. 
28 28
         def to_param
29  
-          join '/'
  29
+          map(&:to_param).join '/'
30 30
         end
31 31
 
32 32
         # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
10  activesupport/test/core_ext/array_ext_test.rb
@@ -16,6 +16,12 @@ def test_to
16 16
 end
17 17
 
18 18
 class ArrayExtToParamTests < Test::Unit::TestCase
  19
+  class ToParam < String
  20
+    def to_param
  21
+      "#{self}1"
  22
+    end
  23
+  end
  24
+  
19 25
   def test_string_array
20 26
     assert_equal '', %w().to_param
21 27
     assert_equal 'hello/world', %w(hello world).to_param
@@ -25,6 +31,10 @@ def test_string_array
25 31
   def test_number_array
26 32
     assert_equal '10/20', [10, 20].to_param
27 33
   end
  34
+  
  35
+  def test_to_param_array
  36
+    assert_equal 'custom1/param1', [ToParam.new('custom'), ToParam.new('param')].to_param
  37
+  end
28 38
 end
29 39
 
30 40
 class ArrayExtToSentenceTests < Test::Unit::TestCase

0 notes on commit 7a22435

Please sign in to comment.
Something went wrong with that request. Please try again.