diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index d5c51ca417..97e20bdaf4 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -549,10 +549,21 @@ module ActiveSupport #:nodoc: end alias :get :[] + class Getter # :nodoc: + def initialize(name) + @name = name + end + + def get + Reference.get @name + end + end + def new(name) self[name] = name - self + Getter.new(name) end + deprecate :new def clear! @store.clear diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb index 3d3ae559e5..4d19e9841a 100644 --- a/activesupport/test/class_cache_test.rb +++ b/activesupport/test/class_cache_test.rb @@ -52,7 +52,9 @@ module ActiveSupport end def test_new - @cache.new ClassCacheTest + assert_deprecated do + @cache.new ClassCacheTest + end assert @cache.key?(ClassCacheTest.name) end @@ -61,9 +63,13 @@ module ActiveSupport assert !@cache.key?(ClassCacheTest.name) end - def test_new_returns_self - v = @cache.new ClassCacheTest.name - assert_equal @cache, v + def test_new_returns_proxy + v = nil + assert_deprecated do + v = @cache.new ClassCacheTest.name + end + + assert_equal ClassCacheTest, v.get end def test_anonymous_class_fail diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index b3ada53497..bc7f597f1d 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -479,13 +479,13 @@ class DependenciesTest < Test::Unit::TestCase with_loading 'dependencies' do c = ActiveSupport::Dependencies.ref("ServiceOne") service_one_first = ServiceOne - assert_equal service_one_first, c.get("ServiceOne") + assert_equal service_one_first, c.get ActiveSupport::Dependencies.clear assert ! defined?(ServiceOne) service_one_second = ServiceOne - assert_not_equal service_one_first, c.get("ServiceOne") - assert_equal service_one_second, c.get("ServiceOne") + assert_not_equal service_one_first, c.get + assert_equal service_one_second, c.get end end