aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-02 09:31:40 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-02 09:31:40 -0800
commit69e348013bc3ce4289c5fefc29c1aacc47048c0d (patch)
treed856dfa248e6c3bd9e4c00b4dc7e2bfbb8909687
parent66245441d4471f29043433f6cf789498cf35b96c (diff)
downloadrails-69e348013bc3ce4289c5fefc29c1aacc47048c0d.tar.gz
rails-69e348013bc3ce4289c5fefc29c1aacc47048c0d.tar.bz2
rails-69e348013bc3ce4289c5fefc29c1aacc47048c0d.zip
adding deprecation noticies to deprecated class cache methods
-rw-r--r--activesupport/lib/active_support/dependencies.rb13
-rw-r--r--activesupport/test/class_cache_test.rb27
-rw-r--r--activesupport/test/dependencies_test.rb8
3 files changed, 41 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 97e20bdaf4..4abeb74c45 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -557,6 +557,7 @@ module ActiveSupport #:nodoc:
def get
Reference.get @name
end
+ deprecate :get
end
def new(name)
@@ -565,6 +566,11 @@ module ActiveSupport #:nodoc:
end
deprecate :new
+ def store(name)
+ self[name] = name
+ self
+ end
+
def clear!
@store.clear
end
@@ -575,7 +581,14 @@ module ActiveSupport #:nodoc:
def ref(name)
Reference.new(name)
end
+ deprecate :ref
+
+ # Store a reference to a class +klass+.
+ def reference(klass)
+ Reference.store klass
+ end
+ # Get the reference for class named +name+.
def constantize(name)
Reference.get(name)
end
diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb
index 4d19e9841a..8445af8d25 100644
--- a/activesupport/test/class_cache_test.rb
+++ b/activesupport/test/class_cache_test.rb
@@ -59,28 +59,49 @@ module ActiveSupport
end
def test_new_rejects_strings
- @cache.new ClassCacheTest.name
+ assert_deprecated do
+ @cache.new ClassCacheTest.name
+ end
assert !@cache.key?(ClassCacheTest.name)
end
+ def test_new_rejects_strings
+ @cache.store ClassCacheTest.name
+ assert !@cache.key?(ClassCacheTest.name)
+ end
+
+ def test_store_returns_self
+ x = @cache.store ClassCacheTest
+ assert_equal @cache, x
+ end
+
def test_new_returns_proxy
v = nil
assert_deprecated do
v = @cache.new ClassCacheTest.name
end
- assert_equal ClassCacheTest, v.get
+ assert_deprecated do
+ assert_equal ClassCacheTest, v.get
+ end
end
def test_anonymous_class_fail
assert_raises(ArgumentError) do
- @cache.new Class.new
+ assert_deprecated do
+ @cache.new Class.new
+ end
end
assert_raises(ArgumentError) do
x = Class.new
@cache[x] = x
end
+
+ assert_raises(ArgumentError) do
+ x = Class.new
+ @cache.store x
+ end
end
end
end
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index bc7f597f1d..ef017d7436 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -477,15 +477,15 @@ class DependenciesTest < Test::Unit::TestCase
def test_references_should_work
with_loading 'dependencies' do
- c = ActiveSupport::Dependencies.ref("ServiceOne")
+ c = ActiveSupport::Dependencies.reference("ServiceOne")
service_one_first = ServiceOne
- assert_equal service_one_first, c.get
+ assert_equal service_one_first, c.get("ServiceOne")
ActiveSupport::Dependencies.clear
assert ! defined?(ServiceOne)
service_one_second = ServiceOne
- assert_not_equal service_one_first, c.get
- assert_equal service_one_second, c.get
+ assert_not_equal service_one_first, c.get("ServiceOne")
+ assert_equal service_one_second, c.get("ServiceOne")
end
end