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

Changeset 1125

Show
Ignore:
Timestamp:
04/10/05 15:01:35 (3 years ago)
Author:
david
Message:

Fixed that in some circumstances controllers outside of modules may have hidden ones inside modules. For example, admin/content might have been hidden by /content. #1075 [Nicholas Seckar]

Files:

Legend:

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

    r1108 r1125  
    11*SVN* 
     2 
     3* Fixed that in some circumstances controllers outside of modules may have hidden ones inside modules. For example, admin/content might have been hidden by /content. #1075 [Nicholas Seckar] 
    24 
    35* Added JavascriptHelper#periodically_call_remote in order to create areas of a page that update automatically at a set interval #945 [Jon Tirsen] 
  • trunk/actionpack/lib/action_controller/routing.rb

    r984 r1125  
    163163            return nil, nil unless /^[A-Z][_a-zA-Z\d]*$/ =~ name 
    164164            controller_name = name + "Controller" 
    165             return mod.const_get(controller_name), path[length..-1] if mod.const_available? controller_name 
     165            return eval("mod::#{controller_name}"), path[length..-1] if mod.const_available? controller_name 
    166166            return nil, nil unless mod.const_available? name 
    167167            [mod.const_get(name), length + 1] 
  • trunk/activesupport/CHANGELOG

    r1101 r1125  
    11*SVN* 
     2 
     3* Fixed that in some circumstances controllers outside of modules may have hidden ones inside modules. For example, admin/content might have been hidden by /content. #1075 [Nicholas Seckar] 
    24 
    35* Fixed inflection of perspectives and similar words #1045 [thijs@vandervossen.net] 
  • trunk/activesupport/lib/active_support/dependencies.rb

    r1057 r1125  
    5656      RootLoadingModule.new(*load_paths) 
    5757    end 
    58              
     58     
    5959    def initialize(root, path=[]) 
    6060      @path = path.clone.freeze 
     
    8282          self.const_set name, new_module 
    8383          if self.root? 
    84             raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \ 
    85               if Object.const_defined?(name) 
    86             Object.const_set(name, new_module)  
     84            if Object.const_defined?(name) 
     85              msg = "Cannot load module #{name}: Object::#{name} is set to #{Object.const_get(name).inspect}" 
     86              raise NameError, msg 
     87            end 
     88            Object.const_set(name, new_module) 
    8789          end 
    8890          break 
     
    9597        end 
    9698      end 
    97  
     99       
    98100      return self.const_defined?(name) 
    99101    end 
     
    125127    def clear! 
    126128      constants.each do |name| 
    127         Object.send(:remove_const, name) if Object.const_defined?(name) 
     129        Object.send(:remove_const, name) if Object.const_defined?(name) && Object.const_get(name).object_id == self.const_get(name).object_id 
    128130        self.send(:remove_const, name) 
    129131      end 
  • trunk/activesupport/test/loading_module_tests.rb

    r711 r1125  
    99  def setup 
    1010    @loading_module = Dependencies::LoadingModule.root(STAGING_DIRECTORY) 
     11    Object.send(:remove_const, :Controllers) if Object.const_defined?(:Controllers) 
    1112    Object.const_set(:Controllers, @loading_module) 
    1213  end 
    1314  def teardown 
    14     @loading_module.clear 
    1515    Object.send :remove_const, :Controllers 
     16    @loading_module.clear! 
     17    Dependencies.clear 
    1618  end 
    1719   
     
    3032  end 
    3133   
     34  def test_nested_const_available 
     35    assert @loading_module::Admin.const_available?(:AccessController) 
     36    assert @loading_module::Admin.const_available?(:UserController) 
     37    assert @loading_module::Admin.const_available?(:ContentController) 
     38    assert ! @loading_module::Admin.const_available?(:ResourceController) 
     39  end 
     40   
     41  def test_nested_module_export 
     42    @loading_module::Admin 
     43    assert_equal @loading_module::Admin.object_id, Object::Admin.object_id 
     44    assert_equal @loading_module::Admin.object_id, Controllers::Admin.object_id 
     45  end 
     46   
    3247  def test_const_load_module 
    3348    assert @loading_module.const_load!(:Admin) 
     
    4358  def test_const_load_nested_controller 
    4459    assert @loading_module.const_load!(:Admin) 
     60    assert_kind_of Dependencies::LoadingModule, @loading_module::Admin 
    4561    assert @loading_module::Admin.const_available?(:UserController) 
    46     assert @loading_module::Admin.const_load!(:UserController) 
    4762    assert_kind_of Class, @loading_module::Admin::UserController 
    4863  end 
     
    6277    assert_raises(NameError) {@loading_module::Admin::FishController} 
    6378  end 
     79   
     80  def test_name_clash 
     81    assert ! @loading_module::const_defined?(:ContentController) 
     82    assert_equal :outer, @loading_module::ContentController.new.identifier 
     83    assert ! @loading_module::Admin.const_defined?(:ContentController) 
     84    assert_equal :inner, @loading_module::Admin::ContentController.new.identifier 
     85    assert @loading_module::ContentController.object_id != @loading_module::Admin::ContentController.object_id 
     86  end 
     87 
     88  def test_name_clash_other_way 
     89    assert ! @loading_module::Admin.const_defined?(:ContentController) 
     90    assert_equal :inner, @loading_module::Admin::ContentController.new.identifier 
     91    assert ! @loading_module::const_defined?(:ContentController) 
     92    assert_equal :outer, @loading_module::ContentController.new.identifier 
     93    assert @loading_module::ContentController.object_id != @loading_module::Admin::ContentController.object_id 
     94  end 
    6495end 
    6596 
     
    70101  end 
    71102  def teardown 
    72     @loading_module.clear 
    73103    Object.send :remove_const, :Controllers 
     104    @loading_module.clear! 
     105    Dependencies.clear 
    74106  end 
    75107   
     
    82114    assert_kind_of Module, @loading_module::List 
    83115    assert_kind_of Dependencies::LoadingModule, @loading_module::List 
    84     assert @loading_module::List.const_load! :ListController 
     116    assert @loading_module::List.const_load!(:ListController) 
    85117    assert_kind_of Class, @loading_module::List::ListController 
    86118  end 
  • trunk/activesupport/test/loading_module/content_controller.rb

    r617 r1125  
    11class ContentController 
     2  def identifier() :outer end 
    23end