Skip to content

Commit a7feaaf

Browse files
committed
Use the singleton instance as ActiveSupport deprecator
1 parent a3061e9 commit a7feaaf

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

activesupport/lib/active_support/deprecator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module ActiveSupport
44
def self.deprecator # :nodoc:
5-
@deprecator ||= ActiveSupport::Deprecation.new
5+
ActiveSupport::Deprecation._instance
66
end
77
end

activesupport/test/deprecation_test.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,12 @@ def method
760760
end
761761

762762
test "warn delegator is deprecated" do
763-
assert_deprecated("use your own Deprecation object instead", ActiveSupport.deprecator) do
764-
assert_deprecated(ActiveSupport::Deprecation._instance) do
765-
ActiveSupport::Deprecation.warn
766-
end
763+
_, deprecations = collect_deprecations(ActiveSupport.deprecator) do
764+
ActiveSupport::Deprecation.warn "foo"
767765
end
766+
assert_equal 2, deprecations.size
767+
assert_match("foo", deprecations.first)
768+
assert_match("use your own Deprecation object instead", deprecations.last)
768769
end
769770

770771
test "deprecate_methods delegator is deprecated" do
@@ -803,7 +804,8 @@ def method
803804
ActiveSupport::Deprecation.behavior
804805
end
805806
assert_deprecated("use Rails.application.deprecators.behavior= instead", ActiveSupport.deprecator) do
806-
ActiveSupport::Deprecation.behavior = ->(*) { }
807+
# we have to keep the same behavior for assert_deprecated to work
808+
ActiveSupport::Deprecation.behavior = ActiveSupport.deprecator.behavior
807809
end
808810
ensure
809811
ActiveSupport::Deprecation._instance.behavior = old_behavior
@@ -871,7 +873,7 @@ def method
871873
ActiveSupport::Deprecation.silenced
872874
end
873875
assert_deprecated("use Rails.application.deprecators.silenced= instead", ActiveSupport.deprecator) do
874-
ActiveSupport::Deprecation.silenced = true
876+
ActiveSupport::Deprecation.silenced = false
875877
end
876878
ensure
877879
ActiveSupport::Deprecation._instance.silenced = old_silenced
@@ -892,7 +894,7 @@ def method
892894
ActiveSupport::Deprecation.disallowed_warnings
893895
end
894896
assert_deprecated("use Rails.application.deprecators.disallowed_warnings= instead", ActiveSupport.deprecator) do
895-
ActiveSupport::Deprecation.disallowed_warnings = :all
897+
ActiveSupport::Deprecation.disallowed_warnings = []
896898
end
897899
ensure
898900
ActiveSupport::Deprecation._instance.disallowed_warnings = old_disallowed_warnings

railties/lib/rails/deprecator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Rails
44
def self.deprecator # :nodoc:
5-
ActiveSupport::Deprecation._instance
5+
@deprecator ||= ActiveSupport::Deprecation.new
66
end
77
end

0 commit comments

Comments
 (0)