public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure url_for(nil) falls back to url_for({}). [#472 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
chuyeow (author)
Mon Jun 23 05:51:38 -0700 2008
lifo (committer)
Wed Jul 09 05:02:14 -0700 2008
commit  96708af6a58a48c2324a3bf8d34232bc29b398c9
tree    48a7259154f5349d57ee73b06fadcd1dd25aaf91
parent  2b4eb586efa240dd985d8b5fe918084ab17fae2b
...
613
614
615
616
 
 
617
618
619
...
613
614
615
 
616
617
618
619
620
0
@@ -613,7 +613,8 @@ module ActionController #:nodoc:
0
       #
0
       # This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action => 'print'</tt>
0
       # would have slashed-off the path components after the changed action.
0
-      def url_for(options = {}) #:doc:
0
+      def url_for(options = {})
0
+        options ||= {}
0
         case options
0
           when String
0
             options
...
63
64
65
 
66
67
68
69
 
70
71
72
73
74
75
76
77
78
79
...
63
64
65
66
67
68
 
 
69
70
71
72
73
74
 
 
75
76
77
0
@@ -63,17 +63,15 @@ module ActionView
0
       #   # calls @workshop.to_s
0
       #   # => /workshops/5
0
       def url_for(options = {})
0
+        options ||= {}
0
         case options
0
         when Hash
0
-          show_path =  options[:host].nil? ? true : false
0
-          options = { :only_path => show_path }.update(options.symbolize_keys)
0
+          options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
0
           escape  = options.key?(:escape) ? options.delete(:escape) : true
0
           url     = @controller.send(:url_for, options)
0
         when String
0
           escape = true
0
           url    = options
0
-        when NilClass
0
-          url = @controller.send(:url_for, nil)
0
         else
0
           escape = false
0
           url    = polymorphic_path(options)
...
313
314
315
 
 
 
 
316
317
318
...
329
330
331
332
 
333
334
335
...
343
344
345
 
 
 
 
 
346
347
348
...
313
314
315
316
317
318
319
320
321
322
...
333
334
335
 
336
337
338
339
...
347
348
349
350
351
352
353
354
355
356
357
0
@@ -313,6 +313,10 @@ class UrlHelperWithControllerTest < ActionView::TestCase
0
       render :inline => "<%= show_named_route_#{params[:kind]} %>"
0
     end
0
 
0
+    def nil_url_for
0
+      render :inline => '<%= url_for(nil) %>'
0
+    end
0
+
0
     def rescue_action(e) raise e end
0
   end
0
 
0
@@ -329,7 +333,7 @@ class UrlHelperWithControllerTest < ActionView::TestCase
0
     assert_equal '/url_helper_with_controller/show_url_for', @response.body
0
   end
0
 
0
-  def test_named_route_shows_host_and_path
0
+  def test_named_route_url_shows_host_and_path
0
     with_url_helper_routing do
0
       get :show_named_route, :kind => 'url'
0
       assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
0
@@ -343,6 +347,11 @@ class UrlHelperWithControllerTest < ActionView::TestCase
0
     end
0
   end
0
 
0
+  def test_url_for_nil_returns_current_path
0
+    get :nil_url_for
0
+    assert_equal '/url_helper_with_controller/nil_url_for', @response.body
0
+  end
0
+
0
   protected
0
     def with_url_helper_routing
0
       with_routing do |set|

Comments