Permalink
Browse files

Ruby 1.9 compat: introduce instance_variable_names. Closes #10630 [Fr…

…ederick Cheung]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8499 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 16558f6 commit 7555073803ffb455715b74664a0cfb48c271fe89 @jeremy jeremy committed Dec 28, 2007
@@ -16,7 +16,7 @@ def adv_attr_accessor(*names)
define_method(name) do |*parameters|
raise ArgumentError, "expected 0 or 1 parameters" unless parameters.length <= 1
if parameters.empty?
- if instance_variables.include?(ivar)
+ if instance_variable_names.include?(ivar)
instance_variable_get(ivar)
end
else
@@ -1210,7 +1210,7 @@ def reset_variables_added_to_assigns
def add_instance_variables_to_assigns
@@protected_variables_cache ||= Set.new(protected_instance_variables)
- instance_variables.each do |var|
+ instance_variable_names.each do |var|
next if @@protected_variables_cache.include?(var)
@assigns[var[1..-1]] = instance_variable_get(var)
end
@@ -373,7 +373,7 @@ def process(action, parameters = nil, session = nil, flash = nil)
# Sanity check for required instance variables so we can give an
# understandable error message.
%w(@controller @request @response).each do |iv_name|
- if !(instance_variables.include?(iv_name) || instance_variables.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
+ if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
end
end
@@ -495,6 +495,7 @@ def test_access_to_request_in_view
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
@@ -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.find(:all, :select => 'authors.*', :joins => :posts)
assert !authors.empty?, "expected authors to be non-empty"
- assert authors.all? {|a| !a.send(:instance_variables).include?("@posts")}, "expected no authors to have the @posts association loaded"
+ assert authors.all? {|a| !a.send(:instance_variable_names).include?("@posts")}, "expected no authors to have the @posts association loaded"
end
def test_count_honors_implicit_inner_joins
@@ -13,6 +13,10 @@ def instance_values #:nodoc:
end
end
+ def instance_variable_names
+ instance_variables.map(&:to_s)
+ end
+
def copy_instance_variables_from(object, exclude = []) #:nodoc:
exclude += object.protected_instance_variables if object.respond_to? :protected_instance_variables
@@ -182,6 +182,10 @@ def setup
@source.instance_variable_set(:@baz, 'baz')
end
+ def test_instance_variable_names
+ assert_equal %w(@bar @baz), @source.instance_variable_names.sort
+ end
+
def test_instance_variable_defined
assert @source.instance_variable_defined?('@bar')
assert @source.instance_variable_defined?(:@bar)

0 comments on commit 7555073

Please sign in to comment.