aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/loading_module_tests.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/loading_module_tests.rb')
-rw-r--r--activesupport/test/loading_module_tests.rb40
1 files changed, 36 insertions, 4 deletions
diff --git a/activesupport/test/loading_module_tests.rb b/activesupport/test/loading_module_tests.rb
index b6587d48ed..01361fae1e 100644
--- a/activesupport/test/loading_module_tests.rb
+++ b/activesupport/test/loading_module_tests.rb
@@ -8,11 +8,13 @@ COMPONENTS_DIRECTORY = File.join(File.dirname(__FILE__), 'loading_module_compone
class LoadingModuleTests < Test::Unit::TestCase
def setup
@loading_module = Dependencies::LoadingModule.root(STAGING_DIRECTORY)
+ Object.send(:remove_const, :Controllers) if Object.const_defined?(:Controllers)
Object.const_set(:Controllers, @loading_module)
end
def teardown
- @loading_module.clear
Object.send :remove_const, :Controllers
+ @loading_module.clear!
+ Dependencies.clear
end
def test_setup
@@ -29,6 +31,19 @@ class LoadingModuleTests < Test::Unit::TestCase
assert_equal false, @loading_module.const_available?(:RandomName)
end
+ def test_nested_const_available
+ assert @loading_module::Admin.const_available?(:AccessController)
+ assert @loading_module::Admin.const_available?(:UserController)
+ assert @loading_module::Admin.const_available?(:ContentController)
+ assert ! @loading_module::Admin.const_available?(:ResourceController)
+ end
+
+ def test_nested_module_export
+ @loading_module::Admin
+ assert_equal @loading_module::Admin.object_id, Object::Admin.object_id
+ assert_equal @loading_module::Admin.object_id, Controllers::Admin.object_id
+ end
+
def test_const_load_module
assert @loading_module.const_load!(:Admin)
assert_kind_of Module, @loading_module::Admin
@@ -42,8 +57,8 @@ class LoadingModuleTests < Test::Unit::TestCase
def test_const_load_nested_controller
assert @loading_module.const_load!(:Admin)
+ assert_kind_of Dependencies::LoadingModule, @loading_module::Admin
assert @loading_module::Admin.const_available?(:UserController)
- assert @loading_module::Admin.const_load!(:UserController)
assert_kind_of Class, @loading_module::Admin::UserController
end
@@ -61,6 +76,22 @@ class LoadingModuleTests < Test::Unit::TestCase
assert_raises(NameError) {@loading_module::PersonController}
assert_raises(NameError) {@loading_module::Admin::FishController}
end
+
+ def test_name_clash
+ assert ! @loading_module::const_defined?(:ContentController)
+ assert_equal :outer, @loading_module::ContentController.new.identifier
+ assert ! @loading_module::Admin.const_defined?(:ContentController)
+ assert_equal :inner, @loading_module::Admin::ContentController.new.identifier
+ assert @loading_module::ContentController.object_id != @loading_module::Admin::ContentController.object_id
+ end
+
+ def test_name_clash_other_way
+ assert ! @loading_module::Admin.const_defined?(:ContentController)
+ assert_equal :inner, @loading_module::Admin::ContentController.new.identifier
+ assert ! @loading_module::const_defined?(:ContentController)
+ assert_equal :outer, @loading_module::ContentController.new.identifier
+ assert @loading_module::ContentController.object_id != @loading_module::Admin::ContentController.object_id
+ end
end
class LoadingModuleMultiPathTests < Test::Unit::TestCase
@@ -69,8 +100,9 @@ class LoadingModuleMultiPathTests < Test::Unit::TestCase
Object.const_set(:Controllers, @loading_module)
end
def teardown
- @loading_module.clear
Object.send :remove_const, :Controllers
+ @loading_module.clear!
+ Dependencies.clear
end
def test_access_from_first
@@ -81,7 +113,7 @@ class LoadingModuleMultiPathTests < Test::Unit::TestCase
def test_access_from_second
assert_kind_of Module, @loading_module::List
assert_kind_of Dependencies::LoadingModule, @loading_module::List
- assert @loading_module::List.const_load! :ListController
+ assert @loading_module::List.const_load!(:ListController)
assert_kind_of Class, @loading_module::List::ListController
end
end \ No newline at end of file