aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-02 09:18:05 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-02 09:18:05 -0800
commit66245441d4471f29043433f6cf789498cf35b96c (patch)
treef3ac7db0c59f00d36baa7a82a006c7fd4cf0c135 /activesupport
parent2ee55557440a644453482a678e4ff08a4b5ebd3e (diff)
downloadrails-66245441d4471f29043433f6cf789498cf35b96c.tar.gz
rails-66245441d4471f29043433f6cf789498cf35b96c.tar.bz2
rails-66245441d4471f29043433f6cf789498cf35b96c.zip
adding backwards compat for class cache references. <3<3
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/dependencies.rb13
-rw-r--r--activesupport/test/class_cache_test.rb14
-rw-r--r--activesupport/test/dependencies_test.rb6
3 files changed, 25 insertions, 8 deletions
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