aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-07 21:58:31 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-07 21:58:31 +0000
commitc3cdd3b6595ad59129d7652f6f3274f26509a4dc (patch)
tree399bbb4e1227bad6e18ea6f543e075ec09a1feb0
parentc0657a9084825f7ca7b0277e5f07a7ae26b8a126 (diff)
downloadrails-c3cdd3b6595ad59129d7652f6f3274f26509a4dc.tar.gz
rails-c3cdd3b6595ad59129d7652f6f3274f26509a4dc.tar.bz2
rails-c3cdd3b6595ad59129d7652f6f3274f26509a4dc.zip
Deprecation: check whether instance variables have been monkeyed with before assigning them to deprecation proxies. Raises a RuntimeError if so.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4717 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/base.rb16
-rw-r--r--actionpack/test/controller/deprecated_instance_variables_test.rb15
3 files changed, 29 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index d8e390c9d4..faf5228dee 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Deprecation: check whether instance variables have been monkeyed with before assigning them to deprecation proxies. Raises a RuntimeError if so. [Jeremy Kemper]
+
* Add support for the param_name parameter to the auto_complete_field helper. #5026 [david.a.williams@gmail.com]
* Deprecation! @params, @session, @flash will be removed after 1.2. Use the corresponding instance methods instead. You'll get printed warnings during tests and logged warnings in dev mode when you access either instance variable directly. [Jeremy Kemper]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 8823076fcc..2125637192 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -400,7 +400,6 @@ module ActionController #:nodoc:
def process(request, response, method = :perform_action, *arguments) #:nodoc:
initialize_template_class(response)
assign_shortcuts(request, response)
- assign_deprecated_shortcuts(request, response)
initialize_current_url
assign_names
forget_variables_added_to_assigns
@@ -942,6 +941,8 @@ module ActionController #:nodoc:
@assigns = @response.template.assigns
@headers = @response.headers
+
+ assign_deprecated_shortcuts(request, response)
end
@@ -950,8 +951,15 @@ module ActionController #:nodoc:
# Gone after 1.2.
def assign_deprecated_shortcuts(request, response)
- DEPRECATED_INSTANCE_VARIABLES.each do |var|
- instance_variable_set "@#{var}", ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, var)
+ DEPRECATED_INSTANCE_VARIABLES.each do |method|
+ var = "@#{method}"
+ if instance_variables.include?(var)
+ value = instance_variable_get(var)
+ unless ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy === value
+ raise "Deprecating #{var}, but it's already set to #{value.inspect}! Use the #{method}= writer method instead of setting #{var} directly."
+ end
+ end
+ instance_variable_set var, ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, method)
end
end
@@ -1011,7 +1019,7 @@ module ActionController #:nodoc:
end
def add_instance_variables_to_assigns
- @@protected_variables_cache ||= protected_instance_variables.inject({}) { |h, k| h[k] = true; h }
+ @@protected_variables_cache ||= Set.new(protected_instance_variables)
instance_variables.each do |var|
next if @@protected_variables_cache.include?(var)
@assigns[var[1..-1]] = instance_variable_get(var)
diff --git a/actionpack/test/controller/deprecated_instance_variables_test.rb b/actionpack/test/controller/deprecated_instance_variables_test.rb
index 81e7ba1324..edfd8b7d02 100644
--- a/actionpack/test/controller/deprecated_instance_variables_test.rb
+++ b/actionpack/test/controller/deprecated_instance_variables_test.rb
@@ -2,6 +2,15 @@ require File.dirname(__FILE__) + '/../abstract_unit'
class DeprecatedInstanceVariablesTest < Test::Unit::TestCase
class Target < ActionController::Base
+ def initialize(run = nil)
+ instance_eval(run) if run
+ super()
+ end
+
+ def noop
+ render :nothing => true
+ end
+
ActionController::Base::DEPRECATED_INSTANCE_VARIABLES.each do |var|
class_eval "def old_#{var}; render :text => @#{var}.inspect end"
class_eval "def new_#{var}; render :text => #{var}.inspect end"
@@ -28,6 +37,12 @@ class DeprecatedInstanceVariablesTest < Test::Unit::TestCase
def test_internal_#{var}_isnt_deprecated
assert_not_deprecated { get :internal_#{var} }
end
+ def test_#{var}_raises_if_already_set
+ assert_raise(RuntimeError) do
+ @controller = Target.new '@#{var} = Object.new'
+ get :noop
+ end
+ end
end_eval
end
end