Skip to content

Commit

Permalink
Merge pull request #50144 from rails/rm-deprecations-1
Browse files Browse the repository at this point in the history
Remove deprecations part 1
  • Loading branch information
rafaelfranca committed Nov 22, 2023
2 parents 6be9ba2 + 03dae98 commit e7ea111
Show file tree
Hide file tree
Showing 31 changed files with 121 additions and 427 deletions.
7 changes: 7 additions & 0 deletions actionmailer/CHANGELOG.md
@@ -1,2 +1,9 @@
* Remove deprecated params via `:args` for `assert_enqueued_email_with`.

*Rafael Mendonça França*

* Remove deprecated `config.action_mailer.preview_path`.

*Rafael Mendonça França*

Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actionmailer/CHANGELOG.md) for previous changes.
24 changes: 0 additions & 24 deletions actionmailer/lib/action_mailer/preview.rb
Expand Up @@ -25,31 +25,7 @@ module Previews # :nodoc:
mattr_accessor :preview_interceptors, instance_writer: false, default: [ActionMailer::InlinePreviewInterceptor]
end

def preview_path
ActionMailer.deprecator.warn(<<-MSG.squish)
Using preview_path option is deprecated and will be removed in Rails 7.2.
Please use preview_paths instead.
MSG
self.class.preview_paths.first
end

module ClassMethods
def preview_path=(value)
ActionMailer.deprecator.warn(<<-MSG.squish)
Using preview_path= option is deprecated and will be removed in Rails 7.2.
Please use preview_paths= instead.
MSG
self.preview_paths << value
end

def preview_path
ActionMailer.deprecator.warn(<<-MSG.squish)
Using preview_path option is deprecated and will be removed in Rails 7.2.
Please use preview_paths instead.
MSG
self.preview_paths.first
end

# Register one or more Interceptors which will be called before mail is previewed.
def register_preview_interceptors(*interceptors)
interceptors.flatten.compact.each { |interceptor| register_preview_interceptor(interceptor) }
Expand Down
20 changes: 0 additions & 20 deletions actionmailer/lib/action_mailer/test_helper.rb
Expand Up @@ -160,26 +160,6 @@ def assert_enqueued_email_with(mailer, method, params: nil, args: nil, queue: ni
mailer = mailer.instance_variable_get(:@mailer)
end

if args.is_a?(Hash)
ActionMailer.deprecator.warn <<~MSG
Passing a Hash to the assert_enqueued_email_with :args kwarg causes the
Hash to be treated as params. This behavior is deprecated and will be
removed in Rails 7.2.
To specify a params Hash, use the :params kwarg:
assert_enqueued_email_with MyMailer, :my_method, params: { my_param: "value" }
Or, to specify named mailer args as a Hash, wrap the Hash in an array:
assert_enqueued_email_with MyMailer, :my_method, args: [{ my_arg: "value" }]
# OR
assert_enqueued_email_with MyMailer, :my_method, args: [my_arg: "value"]
MSG

params, args = args, nil
end

args = Array(args) unless args.is_a?(Proc)
queue ||= mailer.deliver_later_queue_name || ActiveJob::Base.default_queue_name

Expand Down
12 changes: 4 additions & 8 deletions actionmailer/test/test_helper_test.rb
Expand Up @@ -432,11 +432,9 @@ def test_assert_enqueued_email_with_with_no_block_with_args

def test_assert_enqueued_email_with_with_parameterized_args
assert_nothing_raised do
assert_deprecated(ActionMailer.deprecator) do
assert_enqueued_email_with TestHelperMailer, :test_parameter_args, args: { all: "good" } do
silence_stream($stdout) do
TestHelperMailer.with(all: "good").test_parameter_args.deliver_later
end
assert_enqueued_email_with TestHelperMailer, :test_parameter_args, params: { all: "good" } do
silence_stream($stdout) do
TestHelperMailer.with(all: "good").test_parameter_args.deliver_later
end
end
end
Expand Down Expand Up @@ -487,9 +485,7 @@ def test_assert_enqueued_email_with_with_no_block_with_parameterized_args
silence_stream($stdout) do
TestHelperMailer.with(all: "good").test_parameter_args.deliver_later
end
assert_deprecated(ActionMailer.deprecator) do
assert_enqueued_email_with TestHelperMailer, :test_parameter_args, args: { all: "good" }
end
assert_enqueued_email_with TestHelperMailer, :test_parameter_args, params: { all: "good" }
end
end

Expand Down
27 changes: 27 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,27 @@
* Remove deprecated support to set `Rails.application.config.action_dispatch.show_exceptions` to `true` and `false`.

*Rafael Mendonça França*

* Remove deprecated `speaker`, `vibrate`, and `vr` permissions policy directives.

*Rafael Mendonça França*

* Remove deprecated `Rails.application.config.action_dispatch.return_only_request_media_type_on_content_type`.

*Rafael Mendonça França*

* Deprecate `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`.

*Rafael Mendonça França*

* Remove deprecated comparison between `ActionController::Parameters` and `Hash`.

*Rafael Mendonça França*

* Remove deprecated constant `AbstractController::Helpers::MissingHelperError`.

*Rafael Mendonça França*

* Fix a race condition that could cause a `Text file busy - chromedriver`
error with parallel system tests

Expand All @@ -6,5 +30,8 @@
* Add `racc` as a dependency since it will become a bundled gem in Ruby 3.4.0

*Hartley McGuire*
* Remove deprecated constant `ActionDispatch::IllegalStateError`.

*Rafael Mendonça França*

Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/actionpack/CHANGELOG.md) for previous changes.
18 changes: 0 additions & 18 deletions actionpack/lib/abstract_controller/helpers.rb
Expand Up @@ -5,7 +5,6 @@

module AbstractController
module Helpers
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
extend ActiveSupport::Concern

included do
Expand All @@ -24,23 +23,6 @@ module Helpers
self._helpers = define_helpers_module(self)
end

class DeprecatedMissingHelperError < LoadError
def initialize(error, path)
@error = error
@path = "helpers/#{path}.rb"
set_backtrace error.backtrace

if /^#{path}(\.rb)?$/.match?(error.path)
super("Missing helper file helpers/%s.rb" % path)
else
raise error
end
end
end
deprecate_constant "MissingHelperError", "AbstractController::Helpers::DeprecatedMissingHelperError",
message: "AbstractController::Helpers::MissingHelperError has been deprecated. If a Helper is not present, a NameError will be raised instead.",
deprecator: AbstractController.deprecator

def _helpers
self.class._helpers
end
Expand Down
31 changes: 15 additions & 16 deletions actionpack/lib/action_controller/metal/strong_parameters.rb
Expand Up @@ -242,9 +242,21 @@ class Parameters
# config.action_controller.always_permitted_parameters = %w( controller action format )
cattr_accessor :always_permitted_parameters, default: %w( controller action )

cattr_accessor :allow_deprecated_parameters_hash_equality, default: true, instance_accessor: false

class << self
def allow_deprecated_parameters_hash_equality
ActionController.deprecator.warn <<-WARNING.squish
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality` is
deprecated and will be removed in Rails 7.3.
WARNING
end

def allow_deprecated_parameters_hash_equality=(value)
ActionController.deprecator.warn <<-WARNING.squish
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`
is deprecated and will be removed in Rails 7.3.
WARNING
end

def nested_attribute?(key, value) # :nodoc:
/\A-?\d+\z/.match?(key) && (value.is_a?(Hash) || value.is_a?(Parameters))
end
Expand Down Expand Up @@ -284,20 +296,7 @@ def ==(other)
if other.respond_to?(:permitted?)
permitted? == other.permitted? && parameters == other.parameters
else
if self.class.allow_deprecated_parameters_hash_equality && Hash === other
ActionController.deprecator.warn <<-WARNING.squish
Comparing equality between `ActionController::Parameters` and a
`Hash` is deprecated and will be removed in Rails 7.2. Please only do
comparisons between instances of `ActionController::Parameters`. If
you need to compare to a hash, first convert it using
`ActionController::Parameters#new`.
To disable the deprecated behavior set
`Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality = false`.
WARNING
@parameters == other
else
super
end
super
end
end

Expand Down
7 changes: 0 additions & 7 deletions actionpack/lib/action_dispatch.rb
Expand Up @@ -44,15 +44,8 @@ module Rack # :nodoc:
# such as MIME-type negotiation, decoding parameters in POST, PATCH, or PUT
# bodies, handling HTTP caching logic, cookies and sessions.
module ActionDispatch
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
extend ActiveSupport::Autoload

class DeprecatedIllegalStateError < StandardError
end
deprecate_constant "IllegalStateError", "ActionDispatch::DeprecatedIllegalStateError",
message: "ActionDispatch::IllegalStateError is deprecated without replacement.",
deprecator: ActionDispatch.deprecator

class MissingController < NameError
end

Expand Down
14 changes: 0 additions & 14 deletions actionpack/lib/action_dispatch/http/mime_negotiation.rb
Expand Up @@ -16,20 +16,6 @@ class InvalidType < ::Mime::Type::InvalidMimeType; end

included do
mattr_accessor :ignore_accept_header, default: false

def return_only_media_type_on_content_type=(value)
ActionDispatch.deprecator.warn(
"`config.action_dispatch.return_only_request_media_type_on_content_type` is deprecated and will" \
" be removed in Rails 7.2."
)
end

def return_only_media_type_on_content_type
ActionDispatch.deprecator.warn(
"`config.action_dispatch.return_only_request_media_type_on_content_type` is deprecated and will" \
" be removed in Rails 7.2."
)
end
end

# The MIME type of the HTTP request, such as Mime[:xml].
Expand Down
19 changes: 0 additions & 19 deletions actionpack/lib/action_dispatch/http/permissions_policy.rb
Expand Up @@ -132,25 +132,6 @@ def initialize_copy(other)
end
end

%w[speaker vibrate vr].each do |directive|
define_method(directive) do |*sources|
ActionDispatch.deprecator.warn(<<~MSG)
The `#{directive}` permissions policy directive is deprecated
and will be removed in Rails 7.2.
There is no browser support for this directive, and no plan
for browser support in the future. You can just remove this
directive from your application.
MSG

if sources.first
@directives[directive] = apply_mappings(sources)
else
@directives.delete(directive)
end
end
end

def build(context = nil)
build_directives(context).compact.join("; ")
end
Expand Down
Expand Up @@ -186,12 +186,6 @@ def show?(request)
false
when :rescuable
rescue_response?
when true
ActionDispatch.deprecator.warn("Setting action_dispatch.show_exceptions to true is deprecated. Set to :all instead.")
true
when false
ActionDispatch.deprecator.warn("Setting action_dispatch.show_exceptions to false is deprecated. Set to :none instead.")
false
else
true
end
Expand Down
3 changes: 0 additions & 3 deletions actionpack/lib/action_dispatch/railtie.rb
Expand Up @@ -51,9 +51,6 @@ class Railtie < Rails::Railtie # :nodoc:

ActiveSupport.on_load(:action_dispatch_request) do
self.ignore_accept_header = app.config.action_dispatch.ignore_accept_header
unless app.config.action_dispatch.respond_to?(:return_only_request_media_type_on_content_type)
self.return_only_media_type_on_content_type = app.config.action_dispatch.return_only_request_media_type_on_content_type
end
ActionDispatch::Request::Utils.perform_deep_munge = app.config.action_dispatch.perform_deep_munge
end

Expand Down
6 changes: 0 additions & 6 deletions actionpack/test/controller/helper_test.rb
Expand Up @@ -264,12 +264,6 @@ def test_helper_proxy_config
assert_equal "smth", AllHelpersController.helpers.config.my_var
end

def test_missing_helper_error_is_deprecated
assert_deprecated(AbstractController.deprecator) do
AbstractController::Helpers::MissingHelperError
end
end

private
def expected_helper_methods
TestHelper.instance_methods
Expand Down
47 changes: 10 additions & 37 deletions actionpack/test/controller/parameters/equality_test.rb
Expand Up @@ -19,36 +19,21 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
)
end

test "deprecated comparison works" do
test "parameters are not equal to the hash" do
@hash = @params.each_pair.to_h
assert_deprecated(ActionController.deprecator) do
assert_equal @params, @hash
end
end

test "deprecated comparison disabled" do
without_deprecated_params_hash_equality do
@hash = @params.each_pair.to_h
assert_not_deprecated(ActionController.deprecator) do
assert_not_equal @params, @hash
end
end
assert_not_equal @params, @hash
end

test "not eql? to equivalent hash" do
@hash = {}
@params = ActionController::Parameters.new(@hash)
assert_not_deprecated(ActionController.deprecator) do
assert_not @params.eql?(@hash)
end
assert_not @params.eql?(@hash)
end

test "not eql? to equivalent nested hash" do
@params1 = ActionController::Parameters.new({ foo: {} })
@params2 = ActionController::Parameters.new({ foo: ActionController::Parameters.new({}) })
assert_not_deprecated(ActionController.deprecator) do
assert_not @params1.eql?(@params2)
end
assert_not @params1.eql?(@params2)
end

test "not eql? when permitted is different" do
Expand All @@ -62,26 +47,14 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end

test "has_value? converts hashes to parameters" do
assert_not_deprecated(ActionController.deprecator) do
params = ActionController::Parameters.new(foo: { bar: "baz" })
assert params.has_value?("bar" => "baz")
params[:foo] # converts value to AC::Params
assert params.has_value?("bar" => "baz")
end
params = ActionController::Parameters.new(foo: { bar: "baz" })
assert params.has_value?("bar" => "baz")
params[:foo] # converts value to AC::Params
assert params.has_value?("bar" => "baz")
end

test "has_value? works with parameters" do
without_deprecated_params_hash_equality do
params = ActionController::Parameters.new(foo: { bar: "baz" })
assert params.has_value?(ActionController::Parameters.new("bar" => "baz"))
end
params = ActionController::Parameters.new(foo: { bar: "baz" })
assert params.has_value?(ActionController::Parameters.new("bar" => "baz"))
end

private
def without_deprecated_params_hash_equality
ActionController::Parameters.allow_deprecated_parameters_hash_equality = false
yield
ensure
ActionController::Parameters.allow_deprecated_parameters_hash_equality = true
end
end

0 comments on commit e7ea111

Please sign in to comment.