2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2016-08-06 12:03:25 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/dependencies"
|
2011-03-01 20:20:10 -05:00
|
|
|
|
|
|
|
module ActiveSupport
|
|
|
|
module Dependencies
|
|
|
|
class ClassCacheTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@cache = ClassCache.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty?
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 16:43:03 -05:00
|
|
|
@cache.store(ClassCacheTest)
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_not_empty @cache
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_clear!
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 16:43:03 -05:00
|
|
|
@cache.store(ClassCacheTest)
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_not_empty @cache
|
2011-03-01 20:20:10 -05:00
|
|
|
@cache.clear!
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_key
|
2011-11-23 16:43:03 -05:00
|
|
|
@cache.store(ClassCacheTest)
|
2011-03-01 20:20:10 -05:00
|
|
|
assert @cache.key?(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_with_class
|
2011-11-23 16:43:03 -05:00
|
|
|
@cache.store(ClassCacheTest)
|
|
|
|
assert_equal ClassCacheTest, @cache.get(ClassCacheTest)
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_with_name
|
2011-11-23 16:43:03 -05:00
|
|
|
@cache.store(ClassCacheTest)
|
|
|
|
assert_equal ClassCacheTest, @cache.get(ClassCacheTest.name)
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_constantizes
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 16:43:03 -05:00
|
|
|
assert_equal ClassCacheTest, @cache.get(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_get_constantizes_fails_on_invalid_names
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 16:43:03 -05:00
|
|
|
assert_raise NameError do
|
|
|
|
@cache.get("OmgTotallyInvalidConstantName")
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
2011-11-23 18:45:27 -05:00
|
|
|
def test_get_alias
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 18:45:27 -05:00
|
|
|
assert_equal @cache[ClassCacheTest.name], @cache.get(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
2011-11-23 16:43:03 -05:00
|
|
|
def test_safe_get_constantizes
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2011-11-23 16:43:03 -05:00
|
|
|
assert_equal ClassCacheTest, @cache.safe_get(ClassCacheTest.name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_safe_get_constantizes_doesnt_fail_on_invalid_names
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty @cache
|
2016-12-24 12:29:52 -05:00
|
|
|
assert_nil @cache.safe_get("OmgTotallyInvalidConstantName")
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
|
2011-03-02 12:31:40 -05:00
|
|
|
def test_new_rejects_strings
|
|
|
|
@cache.store ClassCacheTest.name
|
2018-04-17 18:21:34 -04:00
|
|
|
assert_not @cache.key?(ClassCacheTest.name)
|
2011-03-02 12:31:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_store_returns_self
|
|
|
|
x = @cache.store ClassCacheTest
|
|
|
|
assert_equal @cache, x
|
|
|
|
end
|
2011-03-01 20:20:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|