Skip to content

Commit 942be52

Browse files
Use the railties deprecator instead of creating a new one
Add tests to verify the app and helpers files deprecation / backwards compatibility, and remove the `.rb` extension from the message, since we generally require without them.
1 parent 46cd9f7 commit 942be52

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

railties/lib/rails/console/app.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
ActiveSupport::Deprecation.new.warn(<<~MSG, caller_locations(0..1))
4-
`rails/console/app.rb` has been deprecated and will be removed in Rails 8.0.
5-
Please require `rails/console/methods.rb` instead.
3+
Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
4+
`rails/console/app` has been deprecated and will be removed in Rails 8.0.
5+
Please require `rails/console/methods` instead.
66
MSG
77

88
require "rails/console/methods"

railties/lib/rails/console/helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
ActiveSupport::Deprecation.new.warn(<<~MSG, caller_locations(0..1))
4-
`rails/console/helpers.rb` has been deprecated and will be removed in Rails 8.0.
5-
Please require `rails/console/methods.rb` instead.
3+
Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
4+
`rails/console/helpers` has been deprecated and will be removed in Rails 8.0.
5+
Please require `rails/console/methods` instead.
66
MSG
77

88
require "rails/console/methods"

railties/lib/rails/console/methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.method_added(_method_name)
1313
end
1414

1515
def self.raise_deprecation_warning
16-
ActiveSupport::Deprecation.new.warn(<<~MSG, caller_locations(1..1))
16+
Rails.deprecator.warn(<<~MSG, caller_locations(1..1))
1717
Extending Rails console through `Rails::ConsoleMethods` is deprecated and will be removed in Rails 7.3.
1818
Please directly use IRB's extension API to add new commands or helpers to the console.
1919
For more details, please visit: https://github.com/ruby/irb/blob/master/EXTEND_IRB.md

railties/test/application/console_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ def foo
219219
write_prompt "foo", "=> \"this is foo\""
220220
end
221221

222+
def test_rails_console_app_and_helpers_files_kept_with_deprecation_for_backward_compatibility
223+
add_to_config <<-RUBY
224+
console do
225+
require "rails/console/app"
226+
require "rails/console/helpers"
227+
end
228+
RUBY
229+
230+
spawn_console("-e development", wait_for_prompt: false)
231+
232+
assert_output "`rails/console/app` has been deprecated", @primary, 30
233+
assert_output "`rails/console/helpers` has been deprecated", @primary, 30
234+
end
235+
222236
def test_rails_console_methods_patch_backward_compatibility_with_module_reopening
223237
add_to_config <<-RUBY
224238
console do

0 commit comments

Comments
 (0)