1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# frozen_string_literal: true
require_relative "../abstract_unit"
require "active_support/deprecation"
class ProxyWrappersTest < ActiveSupport::TestCase
Waffles = false
NewWaffles = :hamburgers
module WaffleModule
def waffle?
true
end
end
def setup
@deprecator = ActiveSupport::Deprecation.new
end
def test_deprecated_object_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message")
assert_not proxy
end
def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles)
assert_not proxy
end
def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles)
assert_not proxy
end
def test_including_proxy_module
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
klass = Class.new
assert_deprecated("OldWaffleModule", @deprecator) do
klass.include proxy
end
assert_predicate klass.new, :waffle?
end
def test_prepending_proxy_module
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
klass = Class.new do
def waffle?
false
end
end
assert_deprecated("OldWaffleModule", @deprecator) do
klass.prepend proxy
end
assert_predicate klass.new, :waffle?
end
def test_extending_proxy_module
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("OldWaffleModule", WaffleModule.name, @deprecator)
obj = Object.new
assert_deprecated("OldWaffleModule", @deprecator) do
obj.extend proxy
end
assert_predicate obj, :waffle?
end
end
|