More deprecation fun

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4943 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 eb90b94a
...@@ -485,9 +485,19 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc: ...@@ -485,9 +485,19 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
# would have slashed-off the path components after the changed action. # would have slashed-off the path components after the changed action.
def url_for(options = {}, *parameters_for_method_reference) #:doc: def url_for(options = {}, *parameters_for_method_reference) #:doc:
case options case options
when String then options when String
when Symbol then send(options, *parameters_for_method_reference) options
when Hash then @url.rewrite(rewrite_options(options))
when Symbol
ActiveSupport::Deprecation.warn(
"WARNING: You called url_for(:#{options}), which is a deprecated API. Instead you should use the named " +
"route directly, like #{options}(). Using symbols and parameters with url_for will be removed from Rails 2.0."
)
send(options, *parameters_for_method_reference)
when Hash
@url.rewrite(rewrite_options(options))
end end
end end
...@@ -661,12 +671,21 @@ def session_enabled? ...@@ -661,12 +671,21 @@ def session_enabled?
def render(options = nil, deprecated_status = nil, &block) #:doc: def render(options = nil, deprecated_status = nil, &block) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed? raise DoubleRenderError, "Can only render or redirect once per action" if performed?
# Backwards compatibility if options.nil?
unless options.is_a?(Hash) return render_file(default_template_name)
if options == :update else
options = {:update => true} # Backwards compatibility
else unless options.is_a?(Hash)
return render_file(options || default_template_name, deprecated_status, true) if options == :update
options = { :update => true }
else
ActiveSupport::Deprecation.warn(
"WARNING: You called render(#{options}), which is a deprecated API. Instead you use " +
"render :file => #{options}. Calling render with just a string will be removed from Rails 2.0."
)
return render_file(options || default_template_name, deprecated_status, true)
end
end end
end end
...@@ -875,6 +894,7 @@ def redirect_to(options = {}, *parameters_for_method_reference) #:doc: ...@@ -875,6 +894,7 @@ def redirect_to(options = {}, *parameters_for_method_reference) #:doc:
redirect_to(url_for(options)) redirect_to(url_for(options))
response.redirected_to = options response.redirected_to = options
else else
# TOOD: Deprecate me!
redirect_to(url_for(options, *parameters_for_method_reference)) redirect_to(url_for(options, *parameters_for_method_reference))
response.redirected_to, response.redirected_to_method_params = options, parameters_for_method_reference response.redirected_to, response.redirected_to_method_params = options, parameters_for_method_reference
end end
......
require File.dirname(__FILE__) + '/../../abstract_unit'
class DeprecatedBaseMethodsTest < Test::Unit::TestCase
class Target < ActionController::Base
def deprecated_symbol_parameter_to_url_for
redirect_to(url_for(:home_url, "superstars"))
end
def deprecated_render_parameters
# render ""
end
def home_url(greeting)
"http://example.com/#{greeting}"
end
def rescue_action(e) raise e end
end
def setup
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller = Target.new
end
def test_deprecated_symbol_parameter_to_url_for
assert_deprecated("url_for(:home_url)") do
get :deprecated_symbol_parameter_to_url_for
end
assert_redirected_to "http://example.com/superstars"
end
end
...@@ -90,5 +90,4 @@ def test_named_route ...@@ -90,5 +90,4 @@ def test_named_route
ensure ensure
ActionController::Routing::Routes.load! ActionController::Routing::Routes.load!
end end
end end
...@@ -38,9 +38,8 @@ def silence ...@@ -38,9 +38,8 @@ def silence
private private
def deprecation_message(callstack, message = nil) def deprecation_message(callstack, message = nil)
file, line, method = extract_callstack(callstack) file, line, method = extract_callstack(callstack)
message ||= "WARNING: #{method} is deprecated and will be removed from Rails 2.0. " + message ||= "WARNING: #{method} is deprecated and will be removed from Rails 2.0."
"See http://www.rubyonrails.org/deprecation for details." "#{message}. See http://www.rubyonrails.org/deprecation for details. (#{method} at #{file}:#{line})"
"#{message} (#{method} at #{file}:#{line})"
end end
def extract_callstack(callstack) def extract_callstack(callstack)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册