Skip to content

Commit 7a6bcc6

Browse files
Merge pull request rails#46388 from jonathanhefner/action_view-deprecator
Add `ActionView.deprecator`
2 parents 7a6382b + b5248ac commit 7a6bcc6

File tree

10 files changed

+22
-16
lines changed

10 files changed

+22
-16
lines changed

actionpack/test/controller/render_test.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ def test_dynamic_render_with_absolute_path
395395
def test_dynamic_render
396396
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
397397
assert_raises ActionView::MissingTemplate do
398-
assert_deprecated(ActionDispatch.deprecator) do
399-
get :dynamic_render, params: { id: '../\\../test/abstract_unit.rb' }
400-
end
398+
get :dynamic_render, params: { id: '../\\../test/abstract_unit.rb' }
401399
end
402400
end
403401

actionview/lib/action_view.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
require "active_support"
2727
require "active_support/rails"
2828
require "action_view/version"
29+
require "action_view/deprecator"
2930

3031
module ActionView
3132
extend ActiveSupport::Autoload
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 ActionView
4+
def self.deprecator # :nodoc:
5+
@deprecator ||= ActiveSupport::Deprecation.new
6+
end
7+
end

actionview/lib/action_view/railtie.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class Railtie < Rails::Engine # :nodoc:
7373
end
7474
end
7575

76+
initializer "action_view.deprecator" do |app|
77+
app.deprecators[:action_view] = ActionView.deprecator
78+
end
79+
7680
initializer "action_view.logger" do
7781
ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
7882
end

actionview/lib/action_view/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def locals_code
415415
locals = @locals - Module::RUBY_RESERVED_KEYWORDS
416416
deprecated_locals = locals.grep(/\A@+/)
417417
if deprecated_locals.any?
418-
ActiveSupport::Deprecation.warn(<<~MSG)
418+
ActionView.deprecator.warn(<<~MSG)
419419
Passing instance variables to `render` is deprecated.
420420
In Rails 7.1, #{deprecated_locals.to_sentence} will be ignored.
421421
MSG

actionview/lib/action_view/template/resolver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
module ActionView
1111
# = Action View Resolver
1212
class Resolver
13-
Path = ActionView::TemplatePath
14-
deprecate_constant :Path
13+
Path = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("ActionView::Resolver::Path", "ActionView::TemplatePath", ActionView.deprecator)
1514

1615
class PathParser # :nodoc:
1716
ParsedPath = Struct.new(:path, :details)

actionview/test/abstract_unit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def self.require_helpers(helpers_dirs)
3939
Thread.abort_on_exception = true
4040

4141
# Show backtraces for deprecated behavior for quicker cleanup.
42-
ActiveSupport::Deprecation.debug = true
42+
ActionView.deprecator.debug = true
4343

4444
# Disable available locale checks to avoid warnings running the test suite.
4545
I18n.enforce_available_locales = false

actionview/test/template/compiled_templates_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_template_with_unicode_identifier
5252

5353
def test_template_with_instance_variable_identifier
5454
expected_deprecation = "In Rails 7.1, @foo will be ignored."
55-
assert_deprecated(expected_deprecation) do
55+
assert_deprecated(expected_deprecation, ActionView.deprecator) do
5656
assert_equal "bar", render(template: "test/render_file_instance_variable", locals: { "@foo": "bar" })
5757
end
5858
end

actionview/test/template/render_test.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def test_render_partial_from_default
204204
def test_render_outside_path
205205
assert File.exist?(File.expand_path("../../test/abstract_unit.rb", __dir__))
206206
assert_raises ActionView::MissingTemplate do
207-
assert_deprecated do
208-
@view.render(template: "../\\../test/abstract_unit.rb")
209-
end
207+
@view.render(template: "../\\../test/abstract_unit.rb")
210208
end
211209
end
212210

@@ -334,7 +332,7 @@ def test_render_error_indentation
334332
end
335333

336334
def test_render_template_with_errors
337-
e = assert_raises(ActionView::Template::Error) { assert_deprecated { @view.render(template: "test/_raise") } }
335+
e = assert_raises(ActionView::Template::Error) { @view.render(template: "test/_raise") }
338336
assert_match %r!method.*doesnt_exist!, e.message
339337
assert_equal "", e.sub_template_message
340338
assert_equal "1", e.line_number
@@ -537,7 +535,7 @@ def test_render_inline_with_render_from_to_proc
537535
end
538536

539537
def test_optional_second_arg_works_without_deprecation
540-
assert_not_deprecated do
538+
assert_not_deprecated(ActionView.deprecator) do
541539
ActionView::Template.register_template_handler :ruby_handler, ->(view, source = nil) { source }
542540
end
543541
assert_equal "3", @view.render(inline: "(1 + 2).to_s", type: :ruby_handler)
@@ -588,9 +586,7 @@ def test_render_ignores_templates_with_malformed_template_handlers
588586
%w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
589587
assert File.exist?(File.expand_path("#{FIXTURE_LOAD_PATH}/test/malformed/#{name}~")), "Malformed file (#{name}~) which should be ignored does not exists"
590588
assert_raises(ActionView::MissingTemplate) do
591-
ActiveSupport::Deprecation.silence do
592-
@view.render(template: "test/malformed/#{name}")
593-
end
589+
@view.render(template: "test/malformed/#{name}")
594590
end
595591
end
596592
end

railties/test/application/configuration_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,6 +3893,7 @@ def new(app); self; end
38933893
assert_equal ActionController.deprecator, Rails.application.deprecators[:action_controller]
38943894
assert_equal ActionDispatch.deprecator, Rails.application.deprecators[:action_dispatch]
38953895
assert_equal ActionMailer.deprecator, Rails.application.deprecators[:action_mailer]
3896+
assert_equal ActionView.deprecator, Rails.application.deprecators[:action_view]
38963897
assert_equal ActiveRecord.deprecator, Rails.application.deprecators[:active_record]
38973898
assert_equal ActiveSupport.deprecator, Rails.application.deprecators[:active_support]
38983899
end

0 commit comments

Comments
 (0)