1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

adding backwards compat for class cache references. <3<3

This commit is contained in:
Aaron Patterson 2011-03-02 09:18:05 -08:00
parent 2ee5555744
commit 66245441d4
3 changed files with 25 additions and 8 deletions

View file

@ -549,10 +549,21 @@ module ActiveSupport #:nodoc:
end end
alias :get :[] alias :get :[]
class Getter # :nodoc:
def initialize(name)
@name = name
end
def get
Reference.get @name
end
end
def new(name) def new(name)
self[name] = name self[name] = name
self Getter.new(name)
end end
deprecate :new
def clear! def clear!
@store.clear @store.clear

View file

@ -52,7 +52,9 @@ module ActiveSupport
end end
def test_new def test_new
@cache.new ClassCacheTest assert_deprecated do
@cache.new ClassCacheTest
end
assert @cache.key?(ClassCacheTest.name) assert @cache.key?(ClassCacheTest.name)
end end
@ -61,9 +63,13 @@ module ActiveSupport
assert !@cache.key?(ClassCacheTest.name) assert !@cache.key?(ClassCacheTest.name)
end end
def test_new_returns_self def test_new_returns_proxy
v = @cache.new ClassCacheTest.name v = nil
assert_equal @cache, v assert_deprecated do
v = @cache.new ClassCacheTest.name
end
assert_equal ClassCacheTest, v.get
end end
def test_anonymous_class_fail def test_anonymous_class_fail

View file

@ -479,13 +479,13 @@ class DependenciesTest < Test::Unit::TestCase
with_loading 'dependencies' do with_loading 'dependencies' do
c = ActiveSupport::Dependencies.ref("ServiceOne") c = ActiveSupport::Dependencies.ref("ServiceOne")
service_one_first = ServiceOne service_one_first = ServiceOne
assert_equal service_one_first, c.get("ServiceOne") assert_equal service_one_first, c.get
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
assert ! defined?(ServiceOne) assert ! defined?(ServiceOne)
service_one_second = ServiceOne service_one_second = ServiceOne
assert_not_equal service_one_first, c.get("ServiceOne") assert_not_equal service_one_first, c.get
assert_equal service_one_second, c.get("ServiceOne") assert_equal service_one_second, c.get
end end
end end