mirror of https://github.com/rails/rails
Ruby 1.9 compat: introduce instance_variable_names. Closes #10630 [Frederick Cheung]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8499 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
16558f6dd8
commit
7555073803
|
@ -16,7 +16,7 @@ module ActionMailer
|
|||
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 @@ module ActionController #:nodoc:
|
|||
|
||||
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 @@ module ActionController #:nodoc:
|
|||
# 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 @@ class NewRenderTest < Test::Unit::TestCase
|
|||
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 @@ class InnerJoinAssociationTest < Test::Unit::TestCase
|
|||
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 @@ class Object
|
|||
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 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase
|
|||
@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)
|
||||
|
|
Loading…
Reference in New Issue