Permalink
Browse files

Remove ActionController::Base#view_controller_internals

Get rid of ActionController::Base#view_controller_internals flag and
use @@protected_view_variables for storing the list of controller
specific instance variables which should be inaccessible inside views.
  • Loading branch information...
1 parent caa03a5 commit 2b69840e5efba885c8ec6281d5b8a56fcabff283 @lifo lifo committed Apr 21, 2008
View
@@ -1,5 +1,7 @@
*SVN*
+* Remove ActionController::Base#view_controller_internals flag. [Pratik]
+
* Add conditional options to caches_page method. [Paul Horsfall]
* Move missing template logic to ActionView. [Pratik]
@@ -253,16 +253,11 @@ class Base
DEFAULT_RENDER_STATUS_CODE = "200 OK"
include StatusCodes
-
- # Determines whether the view has access to controller internals @request, @response, @session, and @template.
- # By default, it does.
- @@view_controller_internals = true
- cattr_accessor :view_controller_internals
-
- # Protected instance variable cache
- @@protected_variables_cache = nil
- cattr_accessor :protected_variables_cache
-
+
+ # Controller specific instance variables which will not be accessible inside views.
+ @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
+ @action_name @before_filter_chain_aborted @action_cache_path)
+
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
# and images to a dedicated asset server away from the main web server. Example:
# ActionController::Base.asset_host = "http://assets.example.com"
@@ -1207,24 +1202,11 @@ def reset_variables_added_to_assigns
end
def add_instance_variables_to_assigns
- @@protected_variables_cache ||= Set.new(protected_instance_variables)
- instance_variable_names.each do |var|
- next if @@protected_variables_cache.include?(var)
+ (instance_variable_names - @@protected_view_variables).each do |var|
@assigns[var[1..-1]] = instance_variable_get(var)
end
end
- def protected_instance_variables
- if view_controller_internals
- %w(@assigns @performed_redirect @performed_render)
- else
- %w(@assigns @performed_redirect @performed_render
- @_request @request @_response @response @_params @params
- @_session @session @_cookies @cookies
- @template @request_origin @parent_controller)
- end
- end
-
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
@@ -41,7 +41,6 @@ def self.included(base) #:nodoc:
base.extend(ClassMethods)
base.class_eval do
attr_accessor :rendered_action_cache, :action_cache_path
- alias_method_chain :protected_instance_variables, :action_caching
end
end
@@ -55,10 +54,6 @@ def caches_action(*actions)
end
protected
- def protected_instance_variables_with_action_caching
- protected_instance_variables_without_action_caching + %w(@action_cache_path)
- end
-
def expire_action(options = {})
return unless cache_configured?
@@ -529,26 +529,10 @@ def test_private_methods
end
def test_access_to_request_in_view
- view_internals_old_value = ActionController::Base.view_controller_internals
-
- ActionController::Base.view_controller_internals = false
- ActionController::Base.protected_variables_cache = nil
-
- get :hello_world
- assert !assigns.include?('_request'), '_request should not be in assigns'
- assert !assigns.include?('request'), 'request should not be in assigns'
-
- ActionController::Base.view_controller_internals = true
- ActionController::Base.protected_variables_cache = nil
-
get :hello_world
assert !assigns.include?('request'), 'request should not be in assigns'
assert_kind_of ActionController::AbstractRequest, assigns['_request']
assert_kind_of ActionController::AbstractRequest, @response.template.request
-
- ensure
- ActionController::Base.view_controller_internals = view_internals_old_value
- ActionController::Base.protected_variables_cache = nil
end
def test_render_xml

0 comments on commit 2b69840

Please sign in to comment.