Skip to content

Commit

Permalink
Remove deprecated support to passing an array of strings to `ActiveSu…
Browse files Browse the repository at this point in the history
…pport::Deprecation#warn`
  • Loading branch information
rafaelfranca committed Oct 18, 2024
1 parent 44a4f27 commit 48ce13f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Remove deprecated support to passing an array of strings to `ActiveSupport::Deprecation#warn`.

*Rafael Mendonça França*

* Remove deprecated support to setting `attr_internal_naming_format` with a `@` prefix.

*Rafael Mendonça França*
Expand Down
19 changes: 0 additions & 19 deletions activesupport/lib/active_support/deprecation/reporting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def deprecation_caller_message(callstack)

def extract_callstack(callstack)
return [] if callstack.empty?
return _extract_callstack(callstack) if callstack.first.is_a? String

offending_line = callstack.find { |frame|
# Code generated with `eval` doesn't have an `absolute_path`, e.g. templates.
Expand All @@ -150,24 +149,6 @@ def extract_callstack(callstack)
[offending_line.path, offending_line.lineno, offending_line.label]
end

def _extract_callstack(callstack)
ActiveSupport.deprecator.warn(<<~MESSAGE)
Passing the result of `caller` to ActiveSupport::Deprecation#warn is deprecated and will be removed in Rails 8.0.
Please pass the result of `caller_locations` instead.
MESSAGE

offending_line = callstack.find { |line| !ignored_callstack?(line) } || callstack.first

if offending_line
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
md.captures
else
offending_line
end
end
end

RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/" # :nodoc:
LIB_DIR = RbConfig::CONFIG["libdir"] # :nodoc:

Expand Down
21 changes: 12 additions & 9 deletions activesupport/test/deprecation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ def setup
end
end

test "passing callstack as `caller` is deprecated" do
assert_deprecated(/Passing the result of `caller` to ActiveSupport::Deprecation#warn/, ActiveSupport.deprecator) do
assert_deprecated(@deprecator) do
@deprecator.warn("Yo dawg!", caller)
end
end
end

test "assert_deprecated requires a deprecator" do
assert_raises(ArgumentError) do
assert_deprecated do
Expand Down Expand Up @@ -196,11 +188,22 @@ def setup
assert_match "call stack!", output
end

class CallerLocation
attr_reader :path, :lineno, :label
alias_method :absolute_path, :path

def initialize(label, lineno)
@path = __FILE__
@lineno = lineno
@label = label
end
end

test ":stderr behavior with #warn" do
@deprecator.behavior = :stderr

output = capture(:stderr) do
@deprecator.warn("Instance error!", ["instance call stack!"])
@deprecator.warn("Instance error!", [CallerLocation.new("instance call stack!", __LINE__)])
end

assert_match(/Instance error!/, output)
Expand Down
2 changes: 2 additions & 0 deletions guides/source/8_0_release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ Please refer to the [Changelog][active-support] for detailed changes.

* Remove deprecated support to setting `attr_internal_naming_format` with a `@` prefix.

* Remove deprecated support to passing an array of strings to `ActiveSupport::Deprecation#warn`.

### Deprecations

### Notable changes
Expand Down

0 comments on commit 48ce13f

Please sign in to comment.