1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Only track new constant definitions when we're reloading dependencies

This commit is contained in:
Jeremy Kemper 2008-11-10 21:39:05 -08:00
parent 278b6cd952
commit cbb38bbdba
2 changed files with 15 additions and 7 deletions

View file

@ -138,14 +138,22 @@ module ActiveSupport #:nodoc:
end
def load_with_new_constant_marking(file, *extras) #:nodoc:
Dependencies.new_constants_in(Object) { load_without_new_constant_marking(file, *extras) }
if Dependencies.load?
Dependencies.new_constants_in(Object) { load_without_new_constant_marking(file, *extras) }
else
load_without_new_constant_marking(file, *extras)
end
rescue Exception => exception # errors from loading file
exception.blame_file! file
raise
end
def require(file, *extras) #:nodoc:
Dependencies.new_constants_in(Object) { super }
if Dependencies.load?
Dependencies.new_constants_in(Object) { super }
else
super
end
rescue Exception => exception # errors from required file
exception.blame_file! file
raise

View file

@ -694,17 +694,17 @@ class DependenciesTest < Test::Unit::TestCase
with_loading 'autoloading_fixtures' do
ActiveSupport::Dependencies.mechanism = :require
2.times do
assert_raise(NameError) {"RaisesNameError".constantize}
assert_raise(NameError) { assert_equal 123, ::RaisesNameError::FooBarBaz }
end
end
end
def test_autoload_doesnt_shadow_name_error
with_loading 'autoloading_fixtures' do
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it hasn't been referenced yet!"
Object.send(:remove_const, :RaisesNameError) if defined?(::RaisesNameError)
2.times do
begin
::RaisesNameError.object_id
::RaisesNameError::FooBarBaz.object_id
flunk 'should have raised NameError when autoloaded file referenced FooBarBaz'
rescue NameError => e
assert_equal 'uninitialized constant RaisesNameError::FooBarBaz', e.message
@ -712,9 +712,9 @@ class DependenciesTest < Test::Unit::TestCase
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"
end
assert !defined?(RaisesNameError)
assert !defined?(::RaisesNameError)
2.times do
assert_raise(NameError) { RaisesNameError }
assert_raise(NameError) { ::RaisesNameError }
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"
end
end