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.
This commit is contained in:
parent
693c14c54d
commit
6a2393ff6b
|
@ -158,6 +158,21 @@ module ActiveSupport
|
||||||
target.class
|
target.class
|
||||||
end
|
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
|
private
|
||||||
def target
|
def target
|
||||||
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
||||||
|
|
|
@ -7,6 +7,12 @@ class ProxyWrappersTest < ActiveSupport::TestCase
|
||||||
Waffles = false
|
Waffles = false
|
||||||
NewWaffles = :hamburgers
|
NewWaffles = :hamburgers
|
||||||
|
|
||||||
|
module WaffleModule
|
||||||
|
def waffle?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_deprecated_object_proxy_doesnt_wrap_falsy_objects
|
def test_deprecated_object_proxy_doesnt_wrap_falsy_objects
|
||||||
proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message")
|
proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message")
|
||||||
assert_not proxy
|
assert_not proxy
|
||||||
|
@ -21,4 +27,35 @@ class ProxyWrappersTest < ActiveSupport::TestCase
|
||||||
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles)
|
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles)
|
||||||
assert_not proxy
|
assert_not proxy
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue