From 0536ea8c7855222111fad6df71d0d09b77ea4317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 21:43:03 +0000 Subject: Add safe_constantize to ActiveSupport::Dependencies. --- activesupport/test/class_cache_test.rb | 38 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'activesupport/test/class_cache_test.rb') diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb index 752c0ee478..87f61dcfc8 100644 --- a/activesupport/test/class_cache_test.rb +++ b/activesupport/test/class_cache_test.rb @@ -10,45 +10,53 @@ module ActiveSupport def test_empty? assert @cache.empty? - @cache[ClassCacheTest] = ClassCacheTest + @cache.store(ClassCacheTest) assert !@cache.empty? end def test_clear! assert @cache.empty? - @cache[ClassCacheTest] = ClassCacheTest + @cache.store(ClassCacheTest) assert !@cache.empty? @cache.clear! assert @cache.empty? end def test_set_key - @cache[ClassCacheTest] = ClassCacheTest + @cache.store(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] + @cache.store(ClassCacheTest) + assert_equal ClassCacheTest, @cache.get(ClassCacheTest) end def test_get_with_name - @cache[ClassCacheTest] = ClassCacheTest - assert_equal ClassCacheTest, @cache[ClassCacheTest.name] + @cache.store(ClassCacheTest) + assert_equal ClassCacheTest, @cache.get(ClassCacheTest.name) end def test_get_constantizes assert @cache.empty? - assert_equal ClassCacheTest, @cache[ClassCacheTest.name] + assert_equal ClassCacheTest, @cache.get(ClassCacheTest.name) + end + + def test_get_constantizes_fails_on_invalid_names + assert @cache.empty? + assert_raise NameError do + @cache.get("OmgTotallyInvalidConstantName") + end end - def test_get_is_an_alias - assert_equal @cache[ClassCacheTest], @cache.get(ClassCacheTest.name) + def test_safe_get_constantizes + assert @cache.empty? + assert_equal ClassCacheTest, @cache.safe_get(ClassCacheTest.name) + end + + def test_safe_get_constantizes_doesnt_fail_on_invalid_names + assert @cache.empty? + assert_equal nil, @cache.safe_get("OmgTotallyInvalidConstantName") end def test_new_rejects_strings -- cgit v1.2.3 From 7fcc8c0a1f38c77b12cb6ffe81fb2887e6c60b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 23:45:27 +0000 Subject: Rely solely on active_model_serializer and remove the fancy constant lookup. --- activesupport/test/class_cache_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport/test/class_cache_test.rb') diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb index 87f61dcfc8..b96f476ce6 100644 --- a/activesupport/test/class_cache_test.rb +++ b/activesupport/test/class_cache_test.rb @@ -49,6 +49,11 @@ module ActiveSupport end end + def test_get_alias + assert @cache.empty? + assert_equal @cache[ClassCacheTest.name], @cache.get(ClassCacheTest.name) + end + def test_safe_get_constantizes assert @cache.empty? assert_equal ClassCacheTest, @cache.safe_get(ClassCacheTest.name) -- cgit v1.2.3