Repository: rails/rails
File: activerecord/lib/active_record/railtie.rb (Ruby)

Code before:

          connection_handler.clear_active_connections!(:all)
          connection_handler.flush_idle_connections!(:all)
        end
      end
    end

    initializer "active_record.set_filter_attributes" do
      ActiveSupport.on_load(:active_record) do
        self.filter_attributes += Rails.application.config.filter_parameters
      end
    end

    initializer "active_record.configure_message_verifiers" do |app|
      ActiveRecord.message_verifiers = app.message_verifiers

      use_legacy_signed_id_verifier = app.config.active_record.use_legacy_signed_id_verifier
      legacy_options = { digest: "SHA256", serializer: JSON, url_safe: true }

      if use_legacy_signed_id_verifier == :generate_and_verify
        app.message_verifiers.prepend { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier == :verify
        app.message_verifiers.rotate { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier
        raise "Unrecognized value for config.active_record.use_legacy_signed_id_verifier: #{use_legacy_signed_id_verifier.inspect}"
      end
    end

    initializer "active_record.generated_token_verifier" do
      config.after_initialize do |app|
        ActiveSupport.on_load(:active_record) do
          self.generated_token_verifier ||= app.message_verifier("active_record/token_for")
        end
      end
    end

    initializer "active_record_encryption.configuration" do |app|
      ActiveSupport.on_load(:active_record_encryption) do
        ActiveRecord::Encryption.configure(
          primary_key: app.credentials.dig(:active_record_encryption, :primary_key),
          deterministic_key: app.credentials.dig(:active_record_encryption, :deterministic_key),
          key_derivation_salt: app.credentials.dig(:active_record_encryption, :key_derivation_salt),
          **app.config.active_record.encryption
        )

        auto_filtered_parameters = ActiveRecord::Encryption::AutoFilteredParameters.new(app)
        auto_filtered_parameters.enable if ActiveRecord::Encryption.config.add_to_filter_parameters
      end

      ActiveSupport.on_load(:active_record) do
        # Support extended queries for deterministic attributes and validations

Review comment (suggestion):
We should add a test for this code path.  See [this test](https://github.com/rails/rails/blob/065ba4faaff079b070bf349820d18a90baf1d53b/railties/test/application/configuration_test.rb#L1460-L1469) for an example.

Code after:

          connection_handler.clear_active_connections!(:all)
          connection_handler.flush_idle_connections!(:all)
        end
      end
    end

    initializer "active_record.set_filter_attributes" do
      ActiveSupport.on_load(:active_record) do
        self.filter_attributes += Rails.application.config.filter_parameters
      end
    end

    initializer "active_record.configure_message_verifiers" do |app|
      ActiveRecord.message_verifiers = app.message_verifiers

      use_legacy_signed_id_verifier = app.config.active_record.use_legacy_signed_id_verifier
      legacy_options = { digest: "SHA256", serializer: JSON, url_safe: true }

      if use_legacy_signed_id_verifier == :generate_and_verify
        app.message_verifiers.prepend { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier == :verify
        app.message_verifiers.rotate { |salt| legacy_options if salt == "active_record/signed_id" }
      elsif use_legacy_signed_id_verifier
        raise ArgumentError, "Unrecognized value for config.active_record.use_legacy_signed_id_verifier: #{use_legacy_signed_id_verifier.inspect}"
      end
    end

    initializer "active_record.generated_token_verifier" do
      config.after_initialize do |app|
        ActiveSupport.on_load(:active_record) do
          self.generated_token_verifier ||= app.message_verifier("active_record/token_for")
        end
      end
    end

    initializer "active_record_encryption.configuration" do |app|
      ActiveSupport.on_load(:active_record_encryption) do
        ActiveRecord::Encryption.configure(
          primary_key: app.credentials.dig(:active_record_encryption, :primary_key),
          deterministic_key: app.credentials.dig(:active_record_encryption, :deterministic_key),
          key_derivation_salt: app.credentials.dig(:active_record_encryption, :key_derivation_salt),
          **app.config.active_record.encryption
        )

        auto_filtered_parameters = ActiveRecord::Encryption::AutoFilteredParameters.new(app)
        auto_filtered_parameters.enable if ActiveRecord::Encryption.config.add_to_filter_parameters
      end

      ActiveSupport.on_load(:active_record) do
        # Support extended queries for deterministic attributes and validations