Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4780

Show
Ignore:
Timestamp:
08/17/06 03:35:36 (2 years ago)
Author:
ulysses
Message:

Detect missing_constants calls from removed modules and fail accordingly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r4774 r4780  
    11*SVN* 
     2 
     3* Detect missing_constants calls from removed modules and fail accordingly. [Nicholas Seckar] 
    24 
    35* Stop using defined? in Dependencies.qualified_const_defined? since defined? may invoke const_missing. [Nicholas Seckar] 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r4779 r4780  
    182182    # If we have an anonymous module, all we can do is attempt to load from Object. 
    183183    from_mod = Object if from_mod.name.empty? 
     184     
     185    unless qualified_const_defined?(from_mod.name) && from_mod.name.constantize.object_id == from_mod.object_id 
     186      raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!" 
     187    end 
    184188     
    185189    raise ArgumentError, "Expected #{from_mod} is not missing constant #{const_name}!" if from_mod.const_defined?(const_name) 
  • trunk/activesupport/test/dependencies_test.rb

    r4779 r4780  
    373373  end 
    374374   
     375  def test_removal_from_tree_should_be_detected 
     376    with_loading 'dependencies' do 
     377      root = Dependencies.autoload_paths.first 
     378      c = ServiceOne 
     379      Dependencies.clear 
     380      assert ! defined?(ServiceOne) 
     381      begin 
     382        Dependencies.load_missing_constant(c, :FakeMissing) 
     383        flunk "Expected exception" 
     384      rescue ArgumentError => e 
     385        assert_match %r{ServiceOne has been removed from the module tree}i, e.message 
     386      end 
     387    end 
     388  end 
     389   
    375390end