Skip to content
This repository
Browse code

Make polymorphic_url compact given array [#1317 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
commit 94d6716324126028b89dde886f160474049b1b0c 1 parent ff4ccb8
Hiroshi Saito authored November 03, 2008 dhh committed November 14, 2008
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.2.1 [RC2 or 2.2 final]*
2 2
 
  3
+* Fixed that polymorphic_url should compact given array #1317 [hiroshi]
  4
+
3 5
 * Fixed the sanitize helper to avoid double escaping already properly escaped entities #683 [antonmos/Ryan McGeary]
4 6
 
5 7
 * Fixed that FormTagHelper generated illegal html if name contained square brackets #1238 [Vladimir Dobriakov]
2  actionpack/lib/action_controller/polymorphic_routes.rb
@@ -73,7 +73,7 @@ module PolymorphicRoutes
73 73
     #
74 74
     def polymorphic_url(record_or_hash_or_array, options = {})
75 75
       if record_or_hash_or_array.kind_of?(Array)
76  
-        record_or_hash_or_array = record_or_hash_or_array.dup
  76
+        record_or_hash_or_array = record_or_hash_or_array.compact
77 77
       end
78 78
 
79 79
       record    = extract_record(record_or_hash_or_array)
11  actionpack/test/controller/polymorphic_routes_test.rb
@@ -169,6 +169,17 @@ def test_nesting_with_array_containing_singleton_resource_and_format_option
169 169
       polymorphic_url([@article, :response, @tag], :format => :pdf)
170 170
     end
171 171
 
  172
+    def test_nesting_with_array_containing_nil
  173
+      expects(:article_response_url).with(@article)
  174
+      polymorphic_url([@article, nil, :response])
  175
+    end
  176
+
  177
+    def test_with_array_containing_single_object
  178
+      @article.save
  179
+      expects(:article_url).with(@article)
  180
+      polymorphic_url([nil, @article])
  181
+    end
  182
+
172 183
     # TODO: Needs to be updated to correctly know about whether the object is in a hash or not
173 184
     def xtest_with_hash
174 185
       expects(:article_url).with(@article)

1 note on commit 94d6716

Tekin Suleyman

Such a simple tweak, but it makes me happy!

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