Skip to content

Commit

Permalink
Merge pull request rails#4377 from lest/instance-variables-1-9
Browse files Browse the repository at this point in the history
get rid of using instance_variable_names method from AS
  • Loading branch information
josevalim committed Jan 7, 2012
2 parents ba168e8 + 7d86235 commit 0c1846e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Expand Up @@ -332,7 +332,7 @@ class Base < AbstractController::Base
include AbstractController::Translation
include AbstractController::AssetPaths

self.protected_instance_variables = %w(@_action_has_layout)
self.protected_instance_variables = [:@_action_has_layout]

helper ActionMailer::MailHelper

Expand Down
11 changes: 5 additions & 6 deletions actionpack/lib/abstract_controller/rendering.rb
@@ -1,6 +1,5 @@
require "abstract_controller/base"
require "action_view"
require "active_support/core_ext/object/instance_variables"

module AbstractController
class DoubleRenderError < Error
Expand Down Expand Up @@ -109,17 +108,17 @@ def _render_template(options) #:nodoc:
view_renderer.render(view_context, options)
end

DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
@_action_name @_response_body @_formats @_prefixes @_config
@_view_context_class @_view_renderer @_lookup_context
)
DEFAULT_PROTECTED_INSTANCE_VARIABLES = [
:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config,
:@_view_context_class, :@_view_renderer, :@_lookup_context
]

# This method should return a hash with assigns.
# You can overwrite this configuration per controller.
# :api: public
def view_assigns
hash = {}
variables = instance_variable_names
variables = instance_variables
variables -= protected_instance_variables
variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }
Expand Down
8 changes: 4 additions & 4 deletions actionpack/lib/action_controller/metal/compatibility.rb
Expand Up @@ -18,10 +18,10 @@ class << self
delegate :default_charset=, :to => "ActionDispatch::Response"
end

self.protected_instance_variables = %w(
@_status @_headers @_params @_env @_response @_request
@_view_runtime @_stream @_url_options @_action_has_layout
)
self.protected_instance_variables = [
:@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
:@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout
]

def rescue_action(env)
raise env["action_dispatch.rescue.exception"]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -506,8 +506,8 @@ def rescue_action_in_public!
def check_required_ivars
# Sanity check for required instance variables so we can give an
# understandable error message.
%w(@routes @controller @request @response).each do |iv_name|
if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
[:@routes, :@controller, :@request, :@response].each do |iv_name|
if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil?
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/filters_test.rb
Expand Up @@ -16,7 +16,7 @@ def before_filters

def assigns(key = nil)
assigns = {}
instance_variable_names.each do |ivar|
instance_variables.each do |ivar|
next if ActionController::Base.protected_instance_variables.include?(ivar)
assigns[ivar[1..-1]] = instance_variable_get(ivar)
end
Expand Down
Expand Up @@ -67,7 +67,7 @@ def test_find_with_implicit_inner_joins_honors_readonly_false
def test_find_with_implicit_inner_joins_does_not_set_associations
authors = Author.joins(:posts).select('authors.*')
assert !authors.empty?, "expected authors to be non-empty"
assert authors.all? {|a| !a.send(:instance_variable_names).include?("@posts")}, "expected no authors to have the @posts association loaded"
assert authors.all? { |a| !a.instance_variable_defined?(:@posts) }, "expected no authors to have the @posts association loaded"
end

def test_count_honors_implicit_inner_joins
Expand Down

0 comments on commit 0c1846e

Please sign in to comment.