From 6a2393ff6b09bb3e4d305d57ea71a37ccc24adac Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 2 Jun 2022 14:43:40 -0700 Subject: [PATCH] Fix includes of deprecation proxy modules Previously, including/prepending/extending one of these deprecated constants would silently succeed, since it is a module. This adds a defintion for append_features/prepend_features/extended so that it can forward the inclusion onto the target module. --- .../deprecation/proxy_wrappers.rb | 15 ++++++++ .../test/deprecation/proxy_wrappers_test.rb | 37 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index 1584f7157a..3b490746c3 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -158,6 +158,21 @@ module ActiveSupport target.class end + def append_features(base) + @deprecator.warn(@message, caller_locations) + base.include(target) + end + + def prepend_features(base) + @deprecator.warn(@message, caller_locations) + base.prepend(target) + end + + def extended(base) + @deprecator.warn(@message, caller_locations) + base.extend(target) + end + private def target ActiveSupport::Inflector.constantize(@new_const.to_s) diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb index 631d75d708..84fb94c797 100644 --- a/activesupport/test/deprecation/proxy_wrappers_test.rb +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -7,6 +7,12 @@ class ProxyWrappersTest < ActiveSupport::TestCase Waffles = false NewWaffles = :hamburgers + module WaffleModule + def waffle? + true + end + end + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") assert_not proxy @@ -21,4 +27,35 @@ class ProxyWrappersTest < ActiveSupport::TestCase proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) assert_not proxy end + + def test_including_proxy_module + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name) + klass = Class.new + assert_deprecated do + klass.include proxy + end + assert klass.new.waffle? + end + + def test_prepending_proxy_module + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name) + klass = Class.new do + def waffle? + false + end + end + assert_deprecated do + klass.prepend proxy + end + assert klass.new.waffle? + end + + def test_extending_proxy_module + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name) + obj = Object.new + assert_deprecated do + obj.extend proxy + end + assert obj.waffle? + end end