Skip to content

Commit

Permalink
Fix Dependencies watch_frames collection. [#24 state:resolved]
Browse files Browse the repository at this point in the history
Previously, the code collecting watch_frames could fail leaving
watch_frames defined but nil. The cleanup code checks watch_frames
is defined, but not that it holds a value, raising an undefined method
on NilClass error rather than the original cause.  This can make
debugging the underlying cause a total pain.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
tomafro authored and lifo committed May 20, 2008
1 parent 0892515 commit ebb642f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/dependencies.rb
Expand Up @@ -384,7 +384,7 @@ def new_constants_in(*descs)
return new_constants
ensure
# Remove the stack frames that we added.
if defined?(watch_frames) && ! watch_frames.empty?
if defined?(watch_frames) && ! watch_frames.blank?
frame_ids = watch_frames.collect(&:object_id)
constant_watch_stack.delete_if do |watch_frame|
frame_ids.include? watch_frame.object_id
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/dependencies_test.rb
Expand Up @@ -584,6 +584,12 @@ def test_new_constants_in_with_inherited_constants
assert_equal [], m
end

def test_new_constants_in_with_illegal_module_name_raises_correct_error
assert_raises(NameError) do
Dependencies.new_constants_in("Illegal-Name") {}
end
end

def test_file_with_multiple_constants_and_require_dependency
with_loading 'autoloading_fixtures' do
assert ! defined?(MultipleConstantFile)
Expand Down

0 comments on commit ebb642f

Please sign in to comment.