diff options
author | Xavier Noria <fxn@hashref.com> | 2010-02-11 23:41:16 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-02-11 23:41:16 +0100 |
commit | aa82bdf92953824fd35db4a734bf6effa8de3329 (patch) | |
tree | 257c4719fb2b37a21cdb5a5eeba62f1a5023d2b1 /activesupport/test/core_ext/module | |
parent | b8bb54af7ff6652327d99f6a7cf5c96a3f3f876d (diff) | |
download | rails-aa82bdf92953824fd35db4a734bf6effa8de3329.tar.gz rails-aa82bdf92953824fd35db4a734bf6effa8de3329.tar.bz2 rails-aa82bdf92953824fd35db4a734bf6effa8de3329.zip |
moves Class#reachable? to Module#reachable?, bases implementation on anonymous? and constantize, and adds test coverage
Diffstat (limited to 'activesupport/test/core_ext/module')
-rw-r--r-- | activesupport/test/core_ext/module/reachable_test.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module/reachable_test.rb b/activesupport/test/core_ext/module/reachable_test.rb new file mode 100644 index 0000000000..72892b77d5 --- /dev/null +++ b/activesupport/test/core_ext/module/reachable_test.rb @@ -0,0 +1,41 @@ +require 'abstract_unit' +require 'active_support/core_ext/module/reachable' + +class AnonymousTest < ActiveSupport::TestCase + test "an anonymous class or module is not reachable" do + assert !Module.new.reachable? + assert !Class.new.reachable? + end + + test "ordinary named classes or modules are reachable" do + assert Kernel.reachable? + assert Object.reachable? + end + + test "a named class or module whose constant has gone is not reachable" do + c = eval "class C; end; C" + m = eval "module M; end; M" + + self.class.send(:remove_const, :C) + self.class.send(:remove_const, :M) + + assert !c.reachable? + assert !m.reachable? + end + + test "a named class or module whose constants store different objects are not reachable" do + c = eval "class C; end; C" + m = eval "module M; end; M" + + self.class.send(:remove_const, :C) + self.class.send(:remove_const, :M) + + eval "class C; end" + eval "module M; end" + + assert C.reachable? + assert M.reachable? + assert !c.reachable? + assert !m.reachable? + end +end
\ No newline at end of file |