aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-09-03 22:35:31 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-09-03 22:35:31 +0000
commit4bd444c1fe960e757819fb67dada0a5a0bf344e4 (patch)
tree06ca057f21afb01c7d7eae1d95f7f92433a252cc
parenteb90b94afdc4358793647b08d28e29af34d45ff8 (diff)
downloadrails-4bd444c1fe960e757819fb67dada0a5a0bf344e4.tar.gz
rails-4bd444c1fe960e757819fb67dada0a5a0bf344e4.tar.bz2
rails-4bd444c1fe960e757819fb67dada0a5a0bf344e4.zip
More deprecation fun
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4943 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rwxr-xr-xactionpack/lib/action_controller/base.rb38
-rw-r--r--actionpack/test/controller/deprecation/deprecated_base_methods_test.rb32
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb1
-rw-r--r--activesupport/lib/active_support/deprecation.rb5
4 files changed, 63 insertions, 13 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 1ceb58711b..33bdeefe5c 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -485,9 +485,19 @@ module ActionController #:nodoc:
# would have slashed-off the path components after the changed action.
def url_for(options = {}, *parameters_for_method_reference) #:doc:
case options
- when String then options
- when Symbol then send(options, *parameters_for_method_reference)
- when Hash then @url.rewrite(rewrite_options(options))
+ when String
+ 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
@@ -661,12 +671,21 @@ module ActionController #:nodoc:
def render(options = nil, deprecated_status = nil, &block) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed?
- # Backwards compatibility
- unless options.is_a?(Hash)
- if options == :update
- options = {:update => true}
- else
- return render_file(options || default_template_name, deprecated_status, true)
+ if options.nil?
+ return render_file(default_template_name)
+ else
+ # Backwards compatibility
+ unless options.is_a?(Hash)
+ 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
@@ -875,6 +894,7 @@ module ActionController #:nodoc:
redirect_to(url_for(options))
response.redirected_to = options
else
+ # TOOD: Deprecate me!
redirect_to(url_for(options, *parameters_for_method_reference))
response.redirected_to, response.redirected_to_method_params = options, parameters_for_method_reference
end
diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
new file mode 100644
index 0000000000..24b4a5d9f5
--- /dev/null
+++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
@@ -0,0 +1,32 @@
+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
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index 114b0d238f..f71f79db47 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -90,5 +90,4 @@ class UrlWriterTests < Test::Unit::TestCase
ensure
ActionController::Routing::Routes.load!
end
-
end
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb
index 581d131c3a..01e1128af4 100644
--- a/activesupport/lib/active_support/deprecation.rb
+++ b/activesupport/lib/active_support/deprecation.rb
@@ -38,9 +38,8 @@ module ActiveSupport
private
def deprecation_message(callstack, message = nil)
file, line, method = extract_callstack(callstack)
- message ||= "WARNING: #{method} is deprecated and will be removed from Rails 2.0. " +
- "See http://www.rubyonrails.org/deprecation for details."
- "#{message} (#{method} at #{file}:#{line})"
+ message ||= "WARNING: #{method} is deprecated and will be removed from Rails 2.0."
+ "#{message}. See http://www.rubyonrails.org/deprecation for details. (#{method} at #{file}:#{line})"
end
def extract_callstack(callstack)