2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2016-08-06 12:03:25 -04:00
|
|
|
require "active_support/testing/stream"
|
2006-07-26 20:10:06 -04:00
|
|
|
|
2006-08-01 07:12:38 -04:00
|
|
|
class Deprecatee
|
2006-08-05 02:33:28 -04:00
|
|
|
def initialize
|
|
|
|
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request)
|
2016-08-06 12:03:25 -04:00
|
|
|
@_request = "there we go"
|
2006-08-05 02:33:28 -04:00
|
|
|
end
|
|
|
|
def request; @_request end
|
|
|
|
def old_request; @request end
|
|
|
|
|
2006-08-01 07:12:38 -04:00
|
|
|
def partially(foo = nil)
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::Deprecation.warn("calling with foo=nil is out") if foo.nil?
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
|
|
|
|
2006-08-01 07:12:38 -04:00
|
|
|
def not() 2 end
|
|
|
|
def none() 1 end
|
|
|
|
def one(a) a end
|
2016-10-28 23:05:58 -04:00
|
|
|
def multi(a, b, c) [a, b, c] end
|
2006-08-01 07:12:38 -04:00
|
|
|
deprecate :none, :one, :multi
|
2006-10-24 12:56:59 -04:00
|
|
|
|
|
|
|
def a; end
|
|
|
|
def b; end
|
|
|
|
def c; end
|
|
|
|
def d; end
|
|
|
|
def e; end
|
2016-08-06 13:38:33 -04:00
|
|
|
deprecate :a, :b, c: :e, d: "you now need to do something extra for this one"
|
2008-06-03 14:32:53 -04:00
|
|
|
|
2009-06-24 18:59:58 -04:00
|
|
|
def f=(v); end
|
|
|
|
deprecate :f=
|
|
|
|
|
2018-12-07 02:03:18 -05:00
|
|
|
deprecate :g
|
2020-01-19 11:44:34 -05:00
|
|
|
def g(h) h end
|
2018-12-07 02:03:18 -05:00
|
|
|
|
2008-06-03 14:32:53 -04:00
|
|
|
module B
|
|
|
|
C = 1
|
|
|
|
end
|
2016-08-06 12:03:25 -04:00
|
|
|
A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::A", "Deprecatee::B::C")
|
2019-06-26 06:33:22 -04:00
|
|
|
|
|
|
|
module New
|
|
|
|
class Descendant; end
|
|
|
|
end
|
|
|
|
Old = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::Old", "Deprecatee::New")
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
|
|
|
|
2017-03-22 11:40:24 -04:00
|
|
|
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
|
|
|
|
|
2008-06-10 17:01:05 -04:00
|
|
|
class DeprecationTest < ActiveSupport::TestCase
|
2015-01-15 01:42:33 -05:00
|
|
|
include ActiveSupport::Testing::Stream
|
|
|
|
|
2006-07-26 20:10:06 -04:00
|
|
|
def setup
|
2006-08-01 07:12:38 -04:00
|
|
|
# Track the last warning.
|
|
|
|
@old_behavior = ActiveSupport::Deprecation.behavior
|
|
|
|
@last_message = nil
|
|
|
|
ActiveSupport::Deprecation.behavior = Proc.new { |message| @last_message = message }
|
|
|
|
|
|
|
|
@dtc = Deprecatee.new
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-08-01 07:12:38 -04:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
ActiveSupport::Deprecation.behavior = @old_behavior
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-08-01 07:12:38 -04:00
|
|
|
|
|
|
|
def test_inline_deprecation_warning
|
|
|
|
assert_deprecated(/foo=nil/) do
|
|
|
|
@dtc.partially
|
|
|
|
end
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-09-03 22:57:40 -04:00
|
|
|
|
2006-08-01 07:12:38 -04:00
|
|
|
def test_undeprecated
|
|
|
|
assert_not_deprecated do
|
|
|
|
assert_equal 2, @dtc.not
|
|
|
|
end
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-08-01 07:12:38 -04:00
|
|
|
|
2020-01-19 11:44:34 -05:00
|
|
|
def test_deprecate_method_on_class
|
2011-05-21 03:29:30 -04:00
|
|
|
assert_deprecated(/none is deprecated/) do
|
2006-08-01 07:12:38 -04:00
|
|
|
assert_equal 1, @dtc.none
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_deprecated(/one is deprecated/) do
|
|
|
|
assert_equal 1, @dtc.one(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_deprecated(/multi is deprecated/) do
|
2016-10-28 23:05:58 -04:00
|
|
|
assert_equal [1, 2, 3], @dtc.multi(1, 2, 3)
|
2006-08-01 07:12:38 -04:00
|
|
|
end
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-08-01 07:12:38 -04:00
|
|
|
|
2020-01-19 11:44:34 -05:00
|
|
|
def test_deprecate_method_doesnt_expand_positional_argument_hash
|
|
|
|
hash = { k: 1 }
|
|
|
|
|
|
|
|
assert_deprecated(/one is deprecated/) do
|
|
|
|
assert_same hash, @dtc.one(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_deprecated(/g is deprecated/) do
|
|
|
|
assert_same hash, @dtc.g(hash)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-22 17:16:17 -05:00
|
|
|
def test_deprecate_object
|
2016-08-06 12:03:25 -04:00
|
|
|
deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:")
|
2013-01-22 17:16:17 -05:00
|
|
|
assert_deprecated(/:bomb:/) { deprecated_object.to_s }
|
|
|
|
end
|
|
|
|
|
2006-08-01 07:12:38 -04:00
|
|
|
def test_nil_behavior_is_ignored
|
|
|
|
ActiveSupport::Deprecation.behavior = nil
|
|
|
|
assert_deprecated(/foo=nil/) { @dtc.partially }
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|
2006-08-05 02:33:28 -04:00
|
|
|
|
2010-07-01 04:26:45 -04:00
|
|
|
def test_several_behaviors
|
2017-04-19 14:50:25 -04:00
|
|
|
@a, @b, @c = nil, nil, nil
|
2010-07-01 04:26:45 -04:00
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
2017-04-19 14:50:25 -04:00
|
|
|
lambda { |msg, callstack, horizon, gem| @a = msg },
|
|
|
|
lambda { |msg, callstack| @b = msg },
|
|
|
|
lambda { |*args| @c = args },
|
2010-07-01 04:26:45 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
@dtc.partially
|
|
|
|
assert_match(/foo=nil/, @a)
|
|
|
|
assert_match(/foo=nil/, @b)
|
2017-04-19 14:50:25 -04:00
|
|
|
assert_equal 4, @c.size
|
2010-07-01 04:26:45 -04:00
|
|
|
end
|
|
|
|
|
2013-08-12 19:38:48 -04:00
|
|
|
def test_raise_behaviour
|
|
|
|
ActiveSupport::Deprecation.behavior = :raise
|
2013-08-12 19:23:21 -04:00
|
|
|
|
2016-08-06 12:03:25 -04:00
|
|
|
message = "Revise this deprecated stuff now!"
|
2016-02-10 13:02:18 -05:00
|
|
|
callstack = caller_locations
|
2013-08-12 19:23:21 -04:00
|
|
|
|
2013-12-19 06:03:39 -05:00
|
|
|
e = assert_raise ActiveSupport::DeprecationException do
|
2017-04-19 14:50:25 -04:00
|
|
|
ActiveSupport::Deprecation.behavior.first.call(message, callstack, "horizon", "gem")
|
2013-08-12 19:23:21 -04:00
|
|
|
end
|
2013-12-19 06:03:39 -05:00
|
|
|
assert_equal message, e.message
|
2016-02-10 13:02:18 -05:00
|
|
|
assert_equal callstack.map(&:to_s), e.backtrace.map(&:to_s)
|
2013-08-12 19:23:21 -04:00
|
|
|
end
|
|
|
|
|
2012-04-28 17:22:11 -04:00
|
|
|
def test_default_stderr_behavior
|
|
|
|
ActiveSupport::Deprecation.behavior = :stderr
|
|
|
|
behavior = ActiveSupport::Deprecation.behavior.first
|
|
|
|
|
|
|
|
content = capture(:stderr) {
|
2017-04-19 14:50:25 -04:00
|
|
|
assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "gem")
|
2012-04-28 17:22:11 -04:00
|
|
|
}
|
|
|
|
assert_match(/Some error!/, content)
|
|
|
|
assert_match(/call stack!/, content)
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_default_stderr_behavior_with_warn_method
|
|
|
|
ActiveSupport::Deprecation.behavior = :stderr
|
|
|
|
|
|
|
|
content = capture(:stderr) {
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::Deprecation.warn("Instance error!", ["instance call stack!"])
|
2012-09-13 02:38:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_match(/Instance error!/, content)
|
|
|
|
assert_match(/instance call stack!/, content)
|
|
|
|
end
|
|
|
|
|
2012-04-28 17:22:11 -04:00
|
|
|
def test_default_silence_behavior
|
|
|
|
ActiveSupport::Deprecation.behavior = :silence
|
|
|
|
behavior = ActiveSupport::Deprecation.behavior.first
|
|
|
|
|
2013-01-05 11:59:36 -05:00
|
|
|
stderr_output = capture(:stderr) {
|
2017-04-19 14:50:25 -04:00
|
|
|
assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "gem")
|
2012-04-28 17:22:11 -04:00
|
|
|
}
|
2018-01-25 18:16:57 -05:00
|
|
|
assert_empty stderr_output
|
2012-04-28 17:22:11 -04:00
|
|
|
end
|
|
|
|
|
2017-04-19 14:50:25 -04:00
|
|
|
def test_default_notify_behavior
|
|
|
|
ActiveSupport::Deprecation.behavior = :notify
|
|
|
|
behavior = ActiveSupport::Deprecation.behavior.first
|
|
|
|
|
|
|
|
begin
|
|
|
|
events = []
|
2019-09-03 04:15:21 -04:00
|
|
|
ActiveSupport::Notifications.subscribe("deprecation.my_gem_custom") { |*args|
|
|
|
|
events << args.extract_options!
|
2017-04-19 14:50:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "MyGem::Custom")
|
|
|
|
assert_equal 1, events.size
|
|
|
|
assert_equal "Some error!", events.first[:message]
|
|
|
|
assert_equal ["call stack!"], events.first[:callstack]
|
|
|
|
assert_equal "horizon", events.first[:deprecation_horizon]
|
|
|
|
assert_equal "MyGem::Custom", events.first[:gem_name]
|
|
|
|
ensure
|
|
|
|
ActiveSupport::Notifications.unsubscribe("deprecation.my_gem_custom")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-18 13:35:09 -04:00
|
|
|
def test_default_invalid_behavior
|
|
|
|
e = assert_raises(ArgumentError) do
|
|
|
|
ActiveSupport::Deprecation.behavior = :invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal ":invalid is not a valid deprecation behavior.", e.message
|
|
|
|
end
|
|
|
|
|
2006-08-05 02:33:28 -04:00
|
|
|
def test_deprecated_instance_variable_proxy
|
|
|
|
assert_not_deprecated { @dtc.request.size }
|
2006-09-03 22:57:40 -04:00
|
|
|
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_deprecated("@request.size") { assert_equal @dtc.request.size, @dtc.old_request.size }
|
|
|
|
assert_deprecated("@request.to_s") { assert_equal @dtc.request.to_s, @dtc.old_request.to_s }
|
2006-08-05 02:33:28 -04:00
|
|
|
end
|
2006-09-03 22:57:40 -04:00
|
|
|
|
2006-12-20 16:28:31 -05:00
|
|
|
def test_deprecated_instance_variable_proxy_shouldnt_warn_on_inspect
|
|
|
|
assert_not_deprecated { assert_equal @dtc.request.inspect, @dtc.old_request.inspect }
|
|
|
|
end
|
|
|
|
|
2008-06-03 14:32:53 -04:00
|
|
|
def test_deprecated_constant_proxy
|
|
|
|
assert_not_deprecated { Deprecatee::B::C }
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_deprecated("Deprecatee::A") { assert_equal Deprecatee::B::C, Deprecatee::A }
|
2013-01-22 17:22:05 -05:00
|
|
|
assert_not_deprecated { assert_equal Deprecatee::B::C.class, Deprecatee::A.class }
|
2008-06-03 14:32:53 -04:00
|
|
|
end
|
|
|
|
|
2019-06-26 06:33:22 -04:00
|
|
|
def test_deprecated_constant_descendant
|
|
|
|
assert_not_deprecated { Deprecatee::New::Descendant }
|
|
|
|
|
|
|
|
assert_deprecated("Deprecatee::Old") do
|
|
|
|
assert_equal Deprecatee::Old::Descendant, Deprecatee::New::Descendant
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(NameError) do
|
|
|
|
assert_deprecated("Deprecatee::Old") { Deprecatee::Old::NON_EXISTENCE }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-22 11:40:24 -04:00
|
|
|
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
|
|
|
|
|
2015-10-16 12:38:58 -04:00
|
|
|
def test_assert_deprecated_raises_when_method_not_deprecated
|
|
|
|
assert_raises(Minitest::Assertion) { assert_deprecated { @dtc.not } }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_not_deprecated
|
|
|
|
assert_raises(Minitest::Assertion) { assert_not_deprecated { @dtc.partially } }
|
|
|
|
end
|
|
|
|
|
2006-08-08 17:21:04 -04:00
|
|
|
def test_assert_deprecation_without_match
|
|
|
|
assert_deprecated do
|
|
|
|
@dtc.partially
|
|
|
|
end
|
|
|
|
end
|
2006-09-03 22:57:40 -04:00
|
|
|
|
2006-09-14 23:56:25 -04:00
|
|
|
def test_assert_deprecated_matches_any_warning
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_deprecated "abc" do
|
|
|
|
ActiveSupport::Deprecation.warn "abc"
|
|
|
|
ActiveSupport::Deprecation.warn "def"
|
2006-09-14 23:56:25 -04:00
|
|
|
end
|
2013-12-18 02:51:24 -05:00
|
|
|
rescue Minitest::Assertion
|
2016-08-06 12:03:25 -04:00
|
|
|
flunk "assert_deprecated should match any warning in block, not just the last one"
|
2006-09-14 23:56:25 -04:00
|
|
|
end
|
|
|
|
|
2006-09-15 01:54:18 -04:00
|
|
|
def test_assert_not_deprecated_returns_result_of_block
|
|
|
|
assert_equal 123, assert_not_deprecated { 123 }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_deprecated_returns_result_of_block
|
2016-08-06 12:03:25 -04:00
|
|
|
result = assert_deprecated("abc") do
|
|
|
|
ActiveSupport::Deprecation.warn "abc"
|
2006-09-15 01:54:18 -04:00
|
|
|
123
|
|
|
|
end
|
|
|
|
assert_equal 123, result
|
|
|
|
end
|
|
|
|
|
2010-07-01 05:59:10 -04:00
|
|
|
def test_assert_deprecated_warn_work_with_default_behavior
|
2016-08-06 12:03:25 -04:00
|
|
|
ActiveSupport::Deprecation.instance_variable_set("@behavior", nil)
|
|
|
|
assert_deprecated("abc") do
|
|
|
|
ActiveSupport::Deprecation.warn "abc"
|
2010-07-01 05:59:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-08-14 14:15:44 -04:00
|
|
|
def test_silence
|
|
|
|
ActiveSupport::Deprecation.silence do
|
|
|
|
assert_not_deprecated { @dtc.partially }
|
|
|
|
end
|
2006-09-04 01:55:55 -04:00
|
|
|
|
|
|
|
ActiveSupport::Deprecation.silenced = true
|
|
|
|
assert_not_deprecated { @dtc.partially }
|
|
|
|
ActiveSupport::Deprecation.silenced = false
|
2006-08-14 14:15:44 -04:00
|
|
|
end
|
2006-10-24 12:56:59 -04:00
|
|
|
|
2019-10-25 18:53:03 -04:00
|
|
|
def test_silence_threaded
|
|
|
|
barrier = Concurrent::CyclicBarrier.new(2)
|
|
|
|
|
|
|
|
th = Thread.new do
|
|
|
|
ActiveSupport::Deprecation.silence do
|
|
|
|
barrier.wait
|
|
|
|
barrier.wait
|
|
|
|
assert_not_deprecated { ActiveSupport::Deprecation.warn "abc" }
|
|
|
|
end
|
|
|
|
assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }
|
|
|
|
end
|
|
|
|
|
|
|
|
barrier.wait
|
|
|
|
|
|
|
|
assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.silence do
|
|
|
|
assert_not_deprecated { ActiveSupport::Deprecation.warn "abc" }
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }
|
|
|
|
|
|
|
|
barrier.wait
|
|
|
|
th.join
|
|
|
|
ensure
|
|
|
|
th.kill
|
|
|
|
end
|
|
|
|
|
2006-10-24 12:56:59 -04:00
|
|
|
def test_deprecation_without_explanation
|
|
|
|
assert_deprecated { @dtc.a }
|
|
|
|
assert_deprecated { @dtc.b }
|
2009-06-24 18:59:58 -04:00
|
|
|
assert_deprecated { @dtc.f = :foo }
|
2006-10-24 12:56:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_deprecation_with_alternate_method
|
|
|
|
assert_deprecated(/use e instead/) { @dtc.c }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_deprecation_with_explicit_message
|
|
|
|
assert_deprecated(/you now need to do something extra for this one/) { @dtc.d }
|
|
|
|
end
|
2011-07-25 15:05:06 -04:00
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_deprecation_in_other_object
|
2011-07-25 15:05:06 -04:00
|
|
|
messages = []
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
klass = Class.new do
|
|
|
|
delegate :warn, :behavior=, to: ActiveSupport::Deprecation
|
|
|
|
end
|
|
|
|
|
|
|
|
o = klass.new
|
|
|
|
o.behavior = Proc.new { |message, callstack| messages << message }
|
|
|
|
assert_difference("messages.size") do
|
|
|
|
o.warn("warning")
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_deprecated_method_with_custom_method_warning
|
2011-07-25 15:05:06 -04:00
|
|
|
deprecator = deprecator_with_messages
|
2012-09-13 02:38:34 -04:00
|
|
|
|
|
|
|
class << deprecator
|
|
|
|
private
|
|
|
|
def deprecated_method_warning(method, message)
|
|
|
|
"deprecator.deprecated_method_warning.#{method}"
|
|
|
|
end
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
deprecatee = Class.new do
|
2011-07-25 15:05:06 -04:00
|
|
|
def method
|
|
|
|
end
|
2012-09-13 02:38:34 -04:00
|
|
|
deprecate :method, deprecator: deprecator
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
deprecatee.new.method
|
|
|
|
assert deprecator.messages.first.match("DEPRECATION WARNING: deprecator.deprecated_method_warning.method")
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_deprecate_with_custom_deprecator
|
2015-06-11 12:18:33 -04:00
|
|
|
custom_deprecator = Struct.new(:deprecation_warning).new
|
2012-09-13 02:38:34 -04:00
|
|
|
|
2015-06-11 12:18:33 -04:00
|
|
|
assert_called_with(custom_deprecator, :deprecation_warning, [:method, nil]) do
|
|
|
|
klass = Class.new do
|
|
|
|
def method
|
|
|
|
end
|
|
|
|
deprecate :method, deprecator: custom_deprecator
|
2012-09-13 02:38:34 -04:00
|
|
|
end
|
|
|
|
|
2015-06-11 12:18:33 -04:00
|
|
|
klass.new.method
|
|
|
|
end
|
2012-09-13 02:38:34 -04:00
|
|
|
end
|
|
|
|
|
2011-07-25 15:05:06 -04:00
|
|
|
def test_deprecated_constant_with_deprecator_given
|
|
|
|
deprecator = deprecator_with_messages
|
2012-09-13 02:38:34 -04:00
|
|
|
klass = Class.new
|
2016-10-28 23:05:58 -04:00
|
|
|
klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new("klass::OLD", "Object", deprecator))
|
2011-07-25 15:05:06 -04:00
|
|
|
assert_difference("deprecator.messages.size") do
|
|
|
|
klass::OLD.to_s
|
|
|
|
end
|
|
|
|
end
|
2013-01-05 11:59:36 -05:00
|
|
|
|
2017-01-20 18:02:34 -05:00
|
|
|
def test_deprecated_constant_with_custom_message
|
|
|
|
deprecator = deprecator_with_messages
|
|
|
|
|
|
|
|
klass = Class.new
|
|
|
|
klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new("klass::OLD", "Object", deprecator, message: "foo"))
|
|
|
|
|
|
|
|
klass::OLD.to_s
|
|
|
|
assert_match "foo", deprecator.messages.last
|
|
|
|
end
|
|
|
|
|
2011-07-25 15:05:06 -04:00
|
|
|
def test_deprecated_instance_variable_with_instance_deprecator
|
|
|
|
deprecator = deprecator_with_messages
|
2013-01-05 11:59:36 -05:00
|
|
|
|
2011-07-25 15:05:06 -04:00
|
|
|
klass = Class.new() do
|
2012-09-13 02:38:34 -04:00
|
|
|
def initialize(deprecator)
|
|
|
|
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
|
2011-07-25 15:05:06 -04:00
|
|
|
@_request = :a_request
|
|
|
|
end
|
|
|
|
def request; @_request end
|
|
|
|
def old_request; @request end
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
assert_difference("deprecator.messages.size") { klass.new(deprecator).old_request.to_s }
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_deprecated_instance_variable_with_given_deprecator
|
|
|
|
deprecator = deprecator_with_messages
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
klass = Class.new do
|
2011-07-25 15:05:06 -04:00
|
|
|
define_method(:initialize) do
|
|
|
|
@request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
|
|
|
|
@_request = :a_request
|
|
|
|
end
|
|
|
|
def request; @_request end
|
|
|
|
def old_request; @request end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_difference("deprecator.messages.size") { klass.new.old_request.to_s }
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_delegate_deprecator_instance
|
|
|
|
klass = Class.new do
|
2011-07-25 15:05:06 -04:00
|
|
|
attr_reader :last_message
|
2012-09-13 02:38:34 -04:00
|
|
|
delegate :warn, :behavior=, to: ActiveSupport::Deprecation
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
self.behavior = [Proc.new { |message| @last_message = message }]
|
|
|
|
end
|
|
|
|
|
2011-07-25 15:05:06 -04:00
|
|
|
def deprecated_method
|
|
|
|
warn(deprecated_method_warning(:deprecated_method, "You are calling deprecated method"))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2012-09-13 02:38:34 -04:00
|
|
|
def deprecated_method_warning(method_name, message = nil)
|
|
|
|
message || "#{method_name} is deprecated and will be removed from This Library"
|
|
|
|
end
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
object = klass.new
|
|
|
|
object.deprecated_method
|
|
|
|
assert_match(/You are calling deprecated method/, object.last_message)
|
|
|
|
end
|
|
|
|
|
2015-12-19 02:35:38 -05:00
|
|
|
def test_default_deprecation_horizon_should_always_bigger_than_current_rails_version
|
2016-05-10 00:40:52 -04:00
|
|
|
assert_operator ActiveSupport::Deprecation.new.deprecation_horizon, :>, ActiveSupport::VERSION::STRING
|
2015-12-19 02:35:38 -05:00
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_default_gem_name
|
|
|
|
deprecator = ActiveSupport::Deprecation.new
|
2011-07-25 15:05:06 -04:00
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
deprecator.send(:deprecated_method_warning, :deprecated_method, "You are calling deprecated method").tap do |message|
|
|
|
|
assert_match(/is deprecated and will be removed from Rails/, message)
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
def test_custom_gem_name
|
2016-08-06 12:03:25 -04:00
|
|
|
deprecator = ActiveSupport::Deprecation.new("2.0", "Custom")
|
2011-07-25 15:05:06 -04:00
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
deprecator.send(:deprecated_method_warning, :deprecated_method, "You are calling deprecated method").tap do |message|
|
|
|
|
assert_match(/is deprecated and will be removed from Custom/, message)
|
2011-07-25 15:05:06 -04:00
|
|
|
end
|
|
|
|
end
|
2012-09-13 02:38:34 -04:00
|
|
|
|
2018-12-07 02:03:18 -05:00
|
|
|
def test_deprecate_work_before_define_method
|
2020-01-19 11:44:34 -05:00
|
|
|
assert_deprecated(/g is deprecated/) { @dtc.g(1) }
|
2018-12-07 02:03:18 -05:00
|
|
|
end
|
|
|
|
|
2019-11-07 08:30:18 -05:00
|
|
|
def test_config_disallows_no_deprecations_by_default
|
|
|
|
assert_equal ActiveSupport::Deprecation.disallowed_warnings, []
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allows_configuration_of_disallowed_warnings
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
config_warnings = ["unsafe_method is going away"]
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = config_warnings
|
|
|
|
assert_equal ActiveSupport::Deprecation.disallowed_warnings, config_warnings
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_disallowed_behavior_with_no_disallowed_messages
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = :raise
|
|
|
|
@dtc.none
|
|
|
|
@dtc.partially
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disallowed_behavior_does_not_apply_to_allowed_messages
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = :raise
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]
|
|
|
|
|
|
|
|
@dtc.none
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disallowed_behavior_when_disallowed_message_configured_with_substring
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = :raise
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]
|
|
|
|
|
|
|
|
e = assert_raise ActiveSupport::DeprecationException do
|
|
|
|
@dtc.partially
|
|
|
|
end
|
|
|
|
|
|
|
|
message = "DEPRECATION WARNING: calling with foo=nil is out"
|
|
|
|
assert_match message, e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disallowed_behavior_when_disallowed_message_configured_with_symbol_treated_as_substring
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = :raise
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [:foo]
|
|
|
|
|
|
|
|
e = assert_raise ActiveSupport::DeprecationException do
|
|
|
|
@dtc.partially
|
|
|
|
end
|
|
|
|
|
|
|
|
message = "DEPRECATION WARNING: calling with foo=nil is out"
|
|
|
|
assert_match message, e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disallowed_behavior_when_disallowed_message_configured_with_regular_expression
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = :raise
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [/none|one*/]
|
|
|
|
|
|
|
|
e = assert_raise ActiveSupport::DeprecationException do
|
|
|
|
@dtc.none
|
|
|
|
end
|
|
|
|
|
|
|
|
message = "none is deprecated"
|
|
|
|
assert_match message, e.message
|
|
|
|
|
|
|
|
e = assert_raise ActiveSupport::DeprecationException do
|
|
|
|
@dtc.one
|
|
|
|
end
|
|
|
|
|
|
|
|
message = "one is deprecated"
|
|
|
|
assert_match message, e.message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disallowed_behavior_when_disallowed_message_configured_with_scalar_symbol_all
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
allowed_message = nil
|
|
|
|
disallowed_message = nil
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| allowed_message = msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| disallowed_message = msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = :all
|
|
|
|
|
|
|
|
@dtc.partially
|
|
|
|
assert_nil allowed_message
|
|
|
|
assert_match(/foo=nil/, disallowed_message)
|
|
|
|
|
|
|
|
allowed_message = nil
|
|
|
|
disallowed_message = nil
|
|
|
|
@dtc.none
|
|
|
|
assert_nil allowed_message
|
|
|
|
assert_match(/none is deprecated/, disallowed_message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_different_behaviors_for_allowed_and_disallowed_messages
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@a, @b, @c, @d = nil, nil, nil, nil
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @a = msg },
|
|
|
|
lambda { |msg, callstack| @b = msg },
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @c = msg },
|
|
|
|
lambda { |msg, callstack| @d = msg },
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]
|
|
|
|
|
|
|
|
@dtc.partially
|
|
|
|
@dtc.none
|
|
|
|
|
|
|
|
assert_match(/none is deprecated/, @a)
|
|
|
|
assert_match(/none is deprecated/, @b)
|
|
|
|
assert_match(/foo=nil/, @c)
|
|
|
|
assert_match(/foo=nil/, @d)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"b is deprecated",
|
|
|
|
"c is deprecated"
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow do
|
|
|
|
@dtc.a
|
|
|
|
@dtc.b
|
|
|
|
@dtc.c
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/c is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_empty @warnings_disallowed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow_only_matching_warnings
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated",
|
|
|
|
"b is deprecated",
|
|
|
|
"c is deprecated",
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow ["b is", "c is"] do
|
|
|
|
@dtc.none
|
|
|
|
@dtc.a
|
|
|
|
@dtc.b
|
|
|
|
@dtc.c
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/c is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
|
|
|
|
assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow_with_symbol
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated",
|
|
|
|
"b is deprecated",
|
|
|
|
"c is deprecated",
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow [:"b is", :"c is"] do
|
|
|
|
@dtc.none
|
|
|
|
@dtc.a
|
|
|
|
@dtc.b
|
|
|
|
@dtc.c
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/c is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
|
|
|
|
assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow_with_regexp
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated",
|
|
|
|
"b is deprecated",
|
|
|
|
"c is deprecated",
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow [/(b|c)\sis/] do
|
|
|
|
@dtc.none
|
|
|
|
@dtc.a
|
|
|
|
@dtc.b
|
|
|
|
@dtc.c
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/c is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
|
|
|
|
assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow_only_has_effect_inside_provided_block
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated"
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will" do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
@dtc.a
|
|
|
|
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_allow_only_has_effect_on_the_thread_on_which_it_was_called
|
|
|
|
th1, th2 = nil, nil
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated"
|
|
|
|
]
|
|
|
|
|
|
|
|
th1 = Thread.new do
|
|
|
|
# barrier.wait
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will" do
|
|
|
|
th2 = Thread.new do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
th2.join
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
th1.join
|
|
|
|
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
th1.kill
|
|
|
|
th2.kill
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_is_a_noop_based_on_if_kwarg_truthy_or_falsey
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated"
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: true do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: Object.new do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: false do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: nil do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_is_a_noop_based_on_if_kwarg_using_proc
|
|
|
|
resetting_disallowed_deprecation_config do
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = [
|
|
|
|
lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = [
|
|
|
|
"a is deprecated"
|
|
|
|
]
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: Proc.new { true } do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
|
|
|
|
@warnings_allowed, @warnings_disallowed = [], []
|
|
|
|
|
|
|
|
ActiveSupport::Deprecation.allow "a is deprecated and will", if: Proc.new { false } do
|
|
|
|
@dtc.a
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
|
|
|
|
assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-13 02:38:34 -04:00
|
|
|
private
|
|
|
|
def deprecator_with_messages
|
|
|
|
klass = Class.new(ActiveSupport::Deprecation)
|
|
|
|
deprecator = klass.new
|
2016-08-16 03:30:11 -04:00
|
|
|
deprecator.behavior = Proc.new { |message, callstack| deprecator.messages << message }
|
2012-09-13 02:38:34 -04:00
|
|
|
def deprecator.messages
|
|
|
|
@messages ||= []
|
|
|
|
end
|
|
|
|
deprecator
|
|
|
|
end
|
2019-11-07 08:30:18 -05:00
|
|
|
|
|
|
|
def resetting_disallowed_deprecation_config
|
|
|
|
original_deprecations = ActiveSupport::Deprecation.disallowed_warnings
|
|
|
|
original_behaviors = ActiveSupport::Deprecation.disallowed_behavior
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActiveSupport::Deprecation.disallowed_warnings = original_deprecations
|
|
|
|
ActiveSupport::Deprecation.disallowed_behavior = original_behaviors
|
|
|
|
end
|
2006-07-26 20:10:06 -04:00
|
|
|
end
|