2011-03-01 20:20:10 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'active_support/dependencies'
|
|
|
|
|
|
|
|
module ActiveSupport
|
|
|
|
module Dependencies
|
|
|
|
class ClassCacheTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cache = ClassCache.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty?
|
|
|
|
assert @cache.empty?
|
|
|
|
@cache[ClassCacheTest] = ClassCacheTest
|
|
|
|
assert !@cache.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_clear!
|
|
|
|
assert @cache.empty?
|
|
|
|
@cache[ClassCacheTest] = ClassCacheTest
|
|
|
|
assert !@cache.empty?
|
|
|
|
@cache.clear!
|
|
|
|
assert @cache.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_key
|
|
|
|
@cache[ClassCacheTest] = ClassCacheTest
|
|
|
|
assert @cache.key?(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_rejects_strings
|
|
|
|
@cache[ClassCacheTest.name] = ClassCacheTest
|
|
|
|
assert @cache.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_with_class
|
|
|
|
@cache[ClassCacheTest] = ClassCacheTest
|
|
|
|
assert_equal ClassCacheTest, @cache[ClassCacheTest]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_with_name
|
|
|
|
@cache[ClassCacheTest] = ClassCacheTest
|
|
|
|
assert_equal ClassCacheTest, @cache[ClassCacheTest.name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_constantizes
|
|
|
|
assert @cache.empty?
|
|
|
|
assert_equal ClassCacheTest, @cache[ClassCacheTest.name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_is_an_alias
|
|
|
|
assert_equal @cache[ClassCacheTest], @cache.get(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_new
|
2011-03-02 12:18:05 -05:00
|
|
|
assert_deprecated do
|
|
|
|
@cache.new ClassCacheTest
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
assert @cache.key?(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
2011-05-07 19:02:42 -04:00
|
|
|
def test_new_rejects_strings_when_called_on_a_new_string
|
2011-03-02 12:31:40 -05:00
|
|
|
assert_deprecated do
|
|
|
|
@cache.new ClassCacheTest.name
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
assert !@cache.key?(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
2011-03-02 12:31:40 -05:00
|
|
|
def test_new_rejects_strings
|
|
|
|
@cache.store ClassCacheTest.name
|
|
|
|
assert !@cache.key?(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_store_returns_self
|
|
|
|
x = @cache.store ClassCacheTest
|
|
|
|
assert_equal @cache, x
|
|
|
|
end
|
|
|
|
|
2011-03-02 12:18:05 -05:00
|
|
|
def test_new_returns_proxy
|
|
|
|
v = nil
|
|
|
|
assert_deprecated do
|
|
|
|
v = @cache.new ClassCacheTest.name
|
|
|
|
end
|
|
|
|
|
2011-03-02 12:31:40 -05:00
|
|
|
assert_deprecated do
|
|
|
|
assert_equal ClassCacheTest, v.get
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_anonymous_class_fail
|
|
|
|
assert_raises(ArgumentError) do
|
2011-03-02 12:31:40 -05:00
|
|
|
assert_deprecated do
|
|
|
|
@cache.new Class.new
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
x = Class.new
|
|
|
|
@cache[x] = x
|
|
|
|
end
|
2011-03-02 12:31:40 -05:00
|
|
|
|
|
|
|
assert_raises(ArgumentError) do
|
|
|
|
x = Class.new
|
|
|
|
@cache.store x
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|