Skip to content

Commit 9caf1d7

Browse files
Merge pull request rails#46424 from jonathanhefner/railties-deprecator
Add `Rails.deprecator`
2 parents 806b3be + 7a26f26 commit 9caf1d7

File tree

8 files changed

+18
-9
lines changed

8 files changed

+18
-9
lines changed

railties/lib/rails.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
require "active_support/core_ext/array/extract_options"
1111
require "active_support/core_ext/object/blank"
1212

13-
require "rails/application"
1413
require "rails/version"
14+
require "rails/deprecator"
15+
require "rails/application"
1516

1617
require "active_support/railtie"
1718
require "action_dispatch/railtie"

railties/lib/rails/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def message_verifier(verifier_name)
231231
# via <tt>deprecators[name] = deprecator</tt>.
232232
def deprecators
233233
@deprecators ||= ActiveSupport::Deprecation::Deprecators.new.tap do |deprecators|
234-
deprecators[:rails] = ActiveSupport::Deprecation.instance
234+
deprecators[:rails] = Rails.deprecator
235235
end
236236
end
237237

railties/lib/rails/application/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ def enable_reloading=(value)
339339
private_constant :ENABLE_DEPENDENCY_LOADING_WARNING
340340

341341
def enable_dependency_loading
342-
ActiveSupport::Deprecation.warn(ENABLE_DEPENDENCY_LOADING_WARNING)
342+
Rails.deprecator.warn(ENABLE_DEPENDENCY_LOADING_WARNING)
343343
@enable_dependency_loading
344344
end
345345

346346
def enable_dependency_loading=(value)
347-
ActiveSupport::Deprecation.warn(ENABLE_DEPENDENCY_LOADING_WARNING)
347+
Rails.deprecator.warn(ENABLE_DEPENDENCY_LOADING_WARNING)
348348
@enable_dependency_loading = value
349349
end
350350

railties/lib/rails/commands/dbconsole/dbconsole_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def configurations # :doc:
6565
end
6666

6767
def find_cmd_and_exec(commands, *args) # :doc:
68-
ActiveSupport::Deprecation.warn(<<~MSG.squish)
68+
Rails.deprecator.warn(<<~MSG.squish)
6969
Rails::DBConsole#find_cmd_and_exec is deprecated and will be removed in Rails 7.2.
7070
Please use find_cmd_and_exec on the connection adapter class instead.
7171
MSG

railties/lib/rails/deprecator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module Rails
4+
def self.deprecator # :nodoc:
5+
ActiveSupport::Deprecation.instance
6+
end
7+
end

railties/lib/rails/generators/testing/behavior.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def migration_file_name(relative)
108108
end
109109
end
110110

111-
Behaviour = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Rails::Generators::Testing::Behaviour", "Rails::Generators::Testing::Behavior")
111+
Behaviour = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Rails::Generators::Testing::Behaviour", "Rails::Generators::Testing::Behavior", Rails.deprecator)
112112
end
113113
end
114114
end

railties/test/application/configuration_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,8 +1392,8 @@ def index
13921392
test "config.enable_dependency_loading is deprecated" do
13931393
app "development"
13941394

1395-
assert_deprecated { Rails.application.config.enable_dependency_loading }
1396-
assert_deprecated { Rails.application.config.enable_dependency_loading = true }
1395+
assert_deprecated(Rails.deprecator) { Rails.application.config.enable_dependency_loading }
1396+
assert_deprecated(Rails.deprecator) { Rails.application.config.enable_dependency_loading = true }
13971397
end
13981398

13991399
test "ActionController::Base.raise_on_open_redirects is true by default for new apps" do
@@ -3902,6 +3902,7 @@ def new(app); self; end
39023902
assert_equal ActiveRecord.deprecator, Rails.application.deprecators[:active_record]
39033903
assert_equal ActiveStorage.deprecator, Rails.application.deprecators[:active_storage]
39043904
assert_equal ActiveSupport.deprecator, Rails.application.deprecators[:active_support]
3905+
assert_equal Rails.deprecator, Rails.application.deprecators[:rails]
39053906
end
39063907

39073908
test "can entirely opt out of deprecation warnings" do

railties/test/generators_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_hide_namespace
255255
end
256256

257257
def test_behaviour_aliases_behavior
258-
assert_deprecated do
258+
assert_deprecated(Rails.deprecator) do
259259
assert_same Rails::Generators::Testing::Behavior, Rails::Generators::Testing::Behaviour.itself
260260
end
261261
end

0 commit comments

Comments
 (0)