public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Make polymorphic_url compact given array [#1317 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
hiroshi (author)
Sun Nov 02 21:09:07 -0800 2008
dhh (committer)
Fri Nov 14 03:07:52 -0800 2008
commit  94d6716324126028b89dde886f160474049b1b0c
tree    c40c86bb253900d68717684d0fbae89bc1936406
parent  ff4ccb8334e4f5b5bdccbd5dc6876b4e43d9565e
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.2.1 [RC2 or 2.2 final]*
0
 
0
+* Fixed that polymorphic_url should compact given array #1317 [hiroshi]
0
+
0
 * Fixed the sanitize helper to avoid double escaping already properly escaped entities #683 [antonmos/Ryan McGeary]
0
 
0
 * Fixed that FormTagHelper generated illegal html if name contained square brackets #1238 [Vladimir Dobriakov]
...
73
74
75
76
 
77
78
79
...
73
74
75
 
76
77
78
79
0
@@ -73,7 +73,7 @@ module ActionController
0
     #
0
     def polymorphic_url(record_or_hash_or_array, options = {})
0
       if record_or_hash_or_array.kind_of?(Array)
0
-        record_or_hash_or_array = record_or_hash_or_array.dup
0
+        record_or_hash_or_array = record_or_hash_or_array.compact
0
       end
0
 
0
       record    = extract_record(record_or_hash_or_array)
...
169
170
171
 
 
 
 
 
 
 
 
 
 
 
172
173
174
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
0
@@ -169,6 +169,17 @@ uses_mocha 'polymorphic URL helpers' do
0
       polymorphic_url([@article, :response, @tag], :format => :pdf)
0
     end
0
 
0
+    def test_nesting_with_array_containing_nil
0
+      expects(:article_response_url).with(@article)
0
+      polymorphic_url([@article, nil, :response])
0
+    end
0
+
0
+    def test_with_array_containing_single_object
0
+      @article.save
0
+      expects(:article_url).with(@article)
0
+      polymorphic_url([nil, @article])
0
+    end
0
+
0
     # TODO: Needs to be updated to correctly know about whether the object is in a hash or not
0
     def xtest_with_hash
0
       expects(:article_url).with(@article)

Comments

tekin Fri Nov 14 09:17:21 -0800 2008

Such a simple tweak, but it makes me happy!