diff options
author | Dominic Cleal <dominic@cleal.org> | 2017-03-22 15:40:24 +0000 |
---|---|---|
committer | Dominic Cleal <dominic@cleal.org> | 2017-03-22 16:21:40 +0000 |
commit | f53a3005f57aaf3e346adf9e777c5eb91050e8e8 (patch) | |
tree | 050628260550155a1fe044474240e5b8c35f3227 /activesupport/test/deprecation_test.rb | |
parent | 34fe2a4fc778d18b7fe6bdf3629c1481bee789b9 (diff) | |
download | rails-f53a3005f57aaf3e346adf9e777c5eb91050e8e8.tar.gz rails-f53a3005f57aaf3e346adf9e777c5eb91050e8e8.tar.bz2 rails-f53a3005f57aaf3e346adf9e777c5eb91050e8e8.zip |
Add AS::Deprecation::DeprecatedConstantAccessor
An alternative to DeprecatedConstantProxy which works more transparently
with exceptions because it returns the object that the new constant
refers to rather than a proxy. This is then compatible with
`rescue OldException`.
Diffstat (limited to 'activesupport/test/deprecation_test.rb')
-rw-r--r-- | activesupport/test/deprecation_test.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 5f72fbf662..36d1ef0849 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -35,6 +35,18 @@ class Deprecatee A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::A", "Deprecatee::B::C") end +class DeprecateeWithAccessor + include ActiveSupport::Deprecation::DeprecatedConstantAccessor + + module B + C = 1 + end + deprecate_constant "A", "DeprecateeWithAccessor::B::C" + + class NewException < StandardError; end + deprecate_constant "OldException", "DeprecateeWithAccessor::NewException" +end + class DeprecationTest < ActiveSupport::TestCase include ActiveSupport::Testing::Stream @@ -162,6 +174,17 @@ class DeprecationTest < ActiveSupport::TestCase assert_not_deprecated { assert_equal Deprecatee::B::C.class, Deprecatee::A.class } end + def test_deprecated_constant_accessor + assert_not_deprecated { DeprecateeWithAccessor::B::C } + assert_deprecated("DeprecateeWithAccessor::A") { assert_equal DeprecateeWithAccessor::B::C, DeprecateeWithAccessor::A } + end + + def test_deprecated_constant_accessor_exception + raise DeprecateeWithAccessor::NewException.new("Test") + rescue DeprecateeWithAccessor::OldException => e + assert_kind_of DeprecateeWithAccessor::NewException, e + end + def test_assert_deprecated_raises_when_method_not_deprecated assert_raises(Minitest::Assertion) { assert_deprecated { @dtc.not } } end |