なるようになるブログ

読書感想文かrailsについてかrubyについてか

rails commit log流し読み(2023/03/01)

2023/03/01分のコミットです。

CHANGELOGにのったコミットは以下の通りです。

activerecord/CHANGELOG.md

actionmailer/CHANGELOG.md

activesupport/CHANGELOG.md


Allow applications to register custom database configurations

activerecord/lib/active_record/database_configurations.rbの修正です。

database configurationを処理する為のhandlerに独自のhandlerを設定出来るよう修正しています。handlerはActiveRecord::DatabaseConfigurations.register_db_config_handlerで登録する必要があります。例えば、custom_configというkeyが指定されていた場合に、CustomConfigというhandlerを使用したい場合下記のように設定すれば良いようになっています。

# database.yml
development:
  primary:
    url: postgres://localhost/primary
  animals:
    url: postgres://localhost/animals
    custom_config:
      sharded: 1
class CustomConfig < ActiveRecord::DatabaseConfigurations::UrlConfig
  def sharded?
    custom_config.fetch("sharded", false)
  end

  private
    def custom_config
      configuration_hash.fetch(:custom_config)
    end
end
ActiveRecord::DatabaseConfigurations.register_db_config_handler do |env_name, name, url, config|
  next unless config.key?(:custom_config)
  CustomConfig.new(env_name, name, url, config)
end

Allow configs_for to accept a custom hash key

activerecord/lib/active_record/database_configurations.rbの修正です。

先程の独自のhanlderを対応出来るようにした対応に合わせて、database configuration内のcustom hash keyをconfigs_forメソッドに指定出来るよう修正しています。custom hash keyはconfig_keyオプションで指定出来るようになっています。合わせて、deprecatedになっていたconfigs_forメソッドの:include_replicasオプションを削除しています。


Merge PR #47520

actionmailer/lib/action_mailer/test_helper.rbの修正です。

enqueueされている全てのメールを送信する為のdeliver_enqueued_emailsメソッドをActionMailer::TestHelperに追加しています。

def test_deliver_enqueued_emails
  deliver_enqueued_emails do
    ContactMailer.welcome.deliver_later
  end
  assert_emails 1
end

Deprecate initialize memcache store with dalli client

activesupport/lib/active_support/cache/mem_cache_store.rbの修正です。

ActiveSupport::Cache::MemCacheStore#initializeの最初の引数にDalli::Clientインスタンスを指定出来るようになっていたのを、Dalli::Clientインスタンスを指定出来るのをdeprecateにしています。ドキュメントには無い挙動(ドキュメント上は最初の引数に指定出来るのはmemcachedのaddressになっている)だったのですが、Dalli::Clientインスタンスが指定されるとActiveSupport::Cache::MemCacheStore#initializeに指定した他の引数(e.g. pool_size)が無視されてしまい、混乱の元になる、という事でdeprecatedになっています。


Always write to debug.log in activerecord tests

activerecord/test/support/connection.rbの修正です。

Active RecordのテストをCIで実行する際ログが出力されないようになっていたのを、必ずログを出力するよう修正してます。不安定テストの調査の為。


Replace call to BINARY with CAST(_ AS BINARY) (#47523)

activerecord/lib/arel/visitors/mysql.rbの修正です。

MySQLBINARY operatorを使っていた箇所をCAST(... AS BINARY)を使用するよう修正しています。BINARY operatorがMySQL 8.0.27でdeprecatedになった為。

参考: MySQL :: MySQL 8.0 Reference Manual :: 12.11 Cast Functions and Operators


Merge pull request #47488 from jkotchoff/rails-info-routes-layout-compaction

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erbの修正です。

/rails/info/routesでrouteを表示する際に、長いroutesが改行して表示されるよう修正しています。


Merge pull request #47539 from fatkodima/pg-notice-receiver-capture-output

activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rbの修正です。

SQLのwarningの出力内容をチェックするテストで、warningを正しく取得出来てなかったのを修正しています。


Install dartsass-rails when generating app with sass (#47545)

railtiesの修正です。

rails newcssオプションにsassを指定した場合、Gemfileにdartsass-railsを追加するよう修正しています。


Merge pull request #47544 from skipkayhil/fix-delayed-job-tests-always-running

activejob/Rakefileの修正です。

各adapter向けのテストを実行するrake taskで、delayed_jobでだけしか通らないテストがdelayed_job以外のadapterで実行されないよう修正しています。