mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure url_for(nil) falls back to url_for({}). [#472 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
parent
2b4eb586ef
commit
96708af6a5
3 changed files with 14 additions and 6 deletions
|
@ -613,7 +613,8 @@ module ActionController #:nodoc:
|
|||
#
|
||||
# This takes the current URL as is and only exchanges the action. In contrast, <tt>url_for :action => 'print'</tt>
|
||||
# would have slashed-off the path components after the changed action.
|
||||
def url_for(options = {}) #:doc:
|
||||
def url_for(options = {})
|
||||
options ||= {}
|
||||
case options
|
||||
when String
|
||||
options
|
||||
|
|
|
@ -63,17 +63,15 @@ module ActionView
|
|||
# # calls @workshop.to_s
|
||||
# # => /workshops/5
|
||||
def url_for(options = {})
|
||||
options ||= {}
|
||||
case options
|
||||
when Hash
|
||||
show_path = options[:host].nil? ? true : false
|
||||
options = { :only_path => show_path }.update(options.symbolize_keys)
|
||||
options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
|
||||
escape = options.key?(:escape) ? options.delete(:escape) : true
|
||||
url = @controller.send(:url_for, options)
|
||||
when String
|
||||
escape = true
|
||||
url = options
|
||||
when NilClass
|
||||
url = @controller.send(:url_for, nil)
|
||||
else
|
||||
escape = false
|
||||
url = polymorphic_path(options)
|
||||
|
|
|
@ -313,6 +313,10 @@ class UrlHelperWithControllerTest < ActionView::TestCase
|
|||
render :inline => "<%= show_named_route_#{params[:kind]} %>"
|
||||
end
|
||||
|
||||
def nil_url_for
|
||||
render :inline => '<%= url_for(nil) %>'
|
||||
end
|
||||
|
||||
def rescue_action(e) raise e end
|
||||
end
|
||||
|
||||
|
@ -329,7 +333,7 @@ class UrlHelperWithControllerTest < ActionView::TestCase
|
|||
assert_equal '/url_helper_with_controller/show_url_for', @response.body
|
||||
end
|
||||
|
||||
def test_named_route_shows_host_and_path
|
||||
def test_named_route_url_shows_host_and_path
|
||||
with_url_helper_routing do
|
||||
get :show_named_route, :kind => 'url'
|
||||
assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
|
||||
|
@ -343,6 +347,11 @@ class UrlHelperWithControllerTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_url_for_nil_returns_current_path
|
||||
get :nil_url_for
|
||||
assert_equal '/url_helper_with_controller/nil_url_for', @response.body
|
||||
end
|
||||
|
||||
protected
|
||||
def with_url_helper_routing
|
||||
with_routing do |set|
|
||||
|
|
Loading…
Reference in a new issue