From f53a3005f57aaf3e346adf9e777c5eb91050e8e8 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Wed, 22 Mar 2017 15:40:24 +0000 Subject: 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`. --- activesupport/test/deprecation_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'activesupport/test/deprecation_test.rb') 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 -- cgit v1.2.3