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:
parent
2ee5555744
commit
66245441d4
3 changed files with 25 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue