Navigation Menu

Skip to content

Commit

Permalink
Add deprecation warning for overwrite_params and remove rdoc
Browse files Browse the repository at this point in the history
[#4073 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
rubys authored and jeremy committed Mar 11, 2010
1 parent abb8fbd commit cbc0201
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
9 changes: 0 additions & 9 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -616,15 +616,6 @@ def send_response
# displayed on:
#
# url_for :controller => 'posts', :action => nil
#
# If you explicitly want to create a URL that's almost the same as the current URL, you can do so using the
# <tt>:overwrite_params</tt> options. Say for your posts you have different views for showing and printing them.
# Then, in the show view, you get the URL for the print view like this
#
# url_for :overwrite_params => { :action => 'print' }
#
# 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 = {})
options ||= {}
case options
Expand Down
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/url_rewriter.rb
Expand Up @@ -159,6 +159,9 @@ def initialize(request, parameters)
end

def rewrite(options = {})
if options.include?(:overwrite_params)
ActiveSupport::Deprecation.warn 'The :overwrite_params option is deprecated. Specify all the necessary parameters instead', caller
end
rewrite_url(options)
end

Expand Down Expand Up @@ -194,7 +197,7 @@ def rewrite_path(options)
options = options.symbolize_keys
options.update(options[:params].symbolize_keys) if options[:params]

if (overwrite = options.delete(:overwrite_params))
if overwrite = options.delete(:overwrite_params)
options.update(@parameters.symbolize_keys)
options.update(overwrite.symbolize_keys)
end
Expand Down
16 changes: 10 additions & 6 deletions actionpack/test/controller/url_rewriter_test.rb
Expand Up @@ -65,19 +65,23 @@ def test_overwrite_params
@params[:action] = 'bye'
@params[:id] = '2'

assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'})
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'})
assert_match %r(/hi/hi/2$), u
assert_deprecated /overwrite_params/ do
assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'})
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'})
assert_match %r(/hi/hi/2$), u
end
end

def test_overwrite_removes_original
@params[:controller] = 'search'
@params[:action] = 'list'
@params[:list_page] = 1

assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2})
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
assert_equal 'http://test.host/search/list?list_page=2', u
assert_deprecated /overwrite_params/ do
assert_equal '/search/list?list_page=2', @rewriter.rewrite(:only_path => true, :overwrite_params => {"list_page" => 2})
u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:list_page => 2})
assert_equal 'http://test.host/search/list?list_page=2', u
end
end

def test_to_str
Expand Down

1 comment on commit cbc0201

@samerbuna
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why was this deprecated?

Please sign in to comment.