🔗 Active Support CHANGELOG
参考: Release 8.1.0.beta1 · rails/rails
参考: コミットリスト: Comparing v8.0.2.1...v8.1.0.beta1 · rails/rails
🔗 Allow getter and setter for options[:namespace]
in ActiveSupport::Cache::Store
by byroot · Pull Request #55580 · rails/rails
ActiveSupport::Cache::Store
に#namespace=
と#namespace
.を追加。パラレルテストなどで状況によってはStore#clear
の代わりに利用可能。Nick Schwaderer
同Changelogより
🔗 Creates parallel_worker_id
helper for running parallel tests by Schwad · Pull Request #55565 · rails/rails
パラレルテスト実行用の
parallel_worker_id
を作成。テスト中にどのワーカーが現在実行中かを知ることが可能になる。Nick Schwaderer
同Changelogより
🔗 Make local cache middleware updatable by gmcgibbon · Pull Request #55553 · rails/rails
ActiveSupport::Cache::Strategy::LocalCache::Middleware
が更新可能になった。起動したアプリケーションの
Rails.cache
にあるキャッシュクライアントが変更された場合は、リクエストローカルキャッシュを適切に設定するために、それに対応するマウント済みミドルウェアを更新する必要がある。さもないと、冗長なキャッシュ操作によって誤ってデータストアにアクセスしてしまう。Gannon McGibbon
同Changelogより
🔗 Add #assert_events_reported test helper by george-ma · Pull Request #55497 · rails/rails
assert_events_reported
テストヘルパーをActiveSupport::EventReporter
に追加。この新しいアサーションによって、複数のイベントを順序と無関係に単一のブロック内でテストできるようになる。assert_events_reported([ { name: "user.created", payload: { id: 123 } }, { name: "email.sent", payload: { to: "user@example.com" } } ]) do create_user_and_send_welcome_email end
George Ma
同Changelogより
🔗 Add AS::TimeZone#standard_name method by bogdan · Pull Request #53199 · rails/rails
ActiveSupport::TimeZone#standard_name
メソッドを追加。
zone = ActiveSupport::TimeZone['Hawaii']
# 従来
ActiveSupport::TimeZone::MAPPING[zone.name]
# 新しい方法
zone.standard_name # => 'Pacific/Honolulu'
Bogdan Gusiev
🔗 Structured Event Reporting in Rails by adrianna-chang-shopify · Pull Request #55334 · rails/rails
Rails.event
でアクセス可能な「Structured Event Reporter」を追加。このイベントレポーター機能は、Railsアプリケーション内で構造化されたイベントを生成する共通インターフェイスを提供する。
Rails.event.notify("user.signup", user_id: 123, email: "user@example.com")
イベントへのタグ追加をサポートする。
Rails.event.tagged("graphql") do # イベントが{ graphql: true }タグを含む Rails.event.notify("user.signup", user_id: 123, email: "user@example.com") end
コンテキストも追加できる。
# すべてのイベントが{request_id: "abc123", shop_id: 456}コンテキストを含む Rails.event.set_context(request_id: "abc123", shop_id: 456)
イベントはサブスクライバに送信される。アプリケーションはサブスクライバを登録することで、イベントのシリアライズと送信方法を制御可能になる。サブスクライバは、イベントハッシュを受け取る
#emit
メソッドを実装する必要がある。class LogSubscriber def emit(event) payload = event[:payload].map { |key, value| "#{key}=#{value}" }.join(" ") source_location = event[:source_location] log = "[#{event[:name]}] #{payload} at #{source_location[:filepath]}:#{source_location[:lineno]}" Rails.logger.info(log) end end
Adrianna Chang
同Changelogより
🔗 [Fix #55460] Make ActiveSupport::Logger
#freeze
-friendly by joshuay03 · Pull Request #55465 · rails/rails
ActiveSupport::Logger
を#freeze
してもFrozenError
をraiseしないようになった。Joshua Young
同Changelogより
🔗 Make ActiveSupport::Gzip.compress
deterministic by Mr0grog · Pull Request #55382 · rails/rails★
ActiveSupport::Gzip.compress
を入力に対して決定論的に振る舞うよう修正。従来の
ActiveSupport::Gzip.compress
は出力にタイムスタンプを含んでいたため、呼び出しの瞬間の秒数が異なっていると同じ入力データに対して出力が異なってしまっていた。修正後はタイムスタンプが常に0
に設定されるため、同じ入力に対して常に同じ出力を得られるようになった。Rob Brackett
同Changelogより
🔗 Implement ActiveSupport::BacktraceCleaner#clean_locations by fxn · Pull Request #55255 · rails/rails
新しい
ActiveSupport::BacktraceCleaner#clean_locations
メソッドにThread::Backtrace::Location
オブジェクトの配列を渡すとオブジェクトのクリーンな配列を返すようになった。clean_locations = backtrace_cleaner.clean_locations(caller_locations)
フィルタとサイレンサーは従来通り文字列を受け取る。ただしlocationsはイミュータブルなので、受け取った配列内のlocationsの
path
属性は元のフィルタなしの状態のままとなる。Xavier Noria
同Changelogより
🔗 Allow for nested ExecutionContext in test by byroot · Pull Request #55247 · rails/rails
テストケースにおける
CurrentAttributes
とExecutionContext
のステート管理を改善。これら2つのグローバルステートは、Rails executorでラップされたコード内(通常はAction ControllerやActive Jobのヘルパー)から呼び出されるたびに、完全にクリアされていた。
test "#index works" do CurrentUser.id = 42 get :index CurrentUser.id == nil end
改修後は、executorに再び入るときにステートを適切に保存して復元するようになった。
Jean Boussier
同Changelogより
🔗 Implement ActiveSupport::BacktraceCleaner#first_clean_location by fxn · Pull Request #55230 · rails/rails
新しい
ActiveSupport::BacktraceCleaner#first_clean_location
メソッドは、呼び出し元のコールスタックの最初のクリーンなlocationまたはnil
を返す。このlocationはThread::Backtrace::Location
である。
何か問題が発生したオブジェクトでアプリケーションレベルのlocationを(文字列ではなく)オブジェクトとして報告したい場合に有用。Xavier Noria
同Changelogより
🔗 perf FileUpdateChecker, ignore gems paths by ermolaev · Pull Request #54129 · rails/rails
パフォーマンス改善のため
FileUpdateChecker
とEventedFileUpdateChecker
がGem.path
の変更を監視しないようになった。Ermolaev Andrey, zzak
同Changelogより
🔗 Implement ActiveSupport::BacktraceCleaner#first_clean_frame by fxn · Pull Request #55222 · rails/rails
新しい
ActiveSupport::BacktraceCleaner#first_clean_frame
メソッドは、呼び出し元のコールスタックの最初のクリーンなフレームまたはnil
を返す。何か問題が発生したオブジェクトでアプリケーションレベルのフレームを文字列として報告したい場合に有用。Xavier Noria
同Changelogより
🔗 Allow for nested ExecutionContext in test by byroot · Pull Request #55247 · rails/rails
CurrentAttributes
インスタンスをリクエスト終了時に常に破棄するようになった。従来の
CurrentAttributes
インスタンスは、リクエスト終了時に属性を再初期化する目的で、属性を(破棄せずに)リセットしていた。これは、そのオブジェクトでは宣言された属性以外にステートを保持していないことを前提としている点に問題がある。実際には必ずしもステートを保持しないとは限らず、その場合リクエスト間でステートが漏洩する可能性があった。
修正後はリクエスト終了時に
CurrentAttributes
インスタンスが常に破棄されるようになったため、次のリクエスト開始時に新しいインスタンスが作成されるようになった。Jean Boussier, Janko Marohnić
同Changelogより
🔗 Add public API for before_fork_hook
in parallel testing by eileencodes · Pull Request #54985 · rails/rails
パラレルテストで実装された
before_fork_hook
を呼び出すためのpublic APIを導入する。parallelize_before_fork do # テストプロセスがforkする直前にアクションを実行する end
Eileen M. Uchitelle
同Changelogより
🔗 Implement ability to opt out of parallel database hooks by eileencodes · Pull Request #54984 · rails/rails
パラレルテストでデータベース作成をスキップする機能を実装した。
Railsのパラレルテストでは、プロセスごとにデータベースが作成される。この振る舞いが望ましくない場合や、データベース処理を独自に実装したい場合は、このデフォルトの振る舞いを無効にできるようになった。
プロセスごとのデータベース作成をスキップするには、
parallelize
メソッドで変更する。parallelize(workers: 10, parallelize_databases: false)
あるいはアプリケーションのコンフィグで指定する。
config.active_support.parallelize_databases = false
Eileen M. Uchitelle
同Changelogより
🔗 Allow to configure maximum cache key sizes by fatkodima · Pull Request #54915 · rails/rails★
キャッシュキーのサイズに最大値を設定可能になった。
キーの長さが設定値(デフォルトで250バイト)を超えると、はみ出し分を切り捨て、残ったキーのダイジェストが追加される。
従来の
ActiveSupport::Cache::RedisCacheStore
では、切り捨て前のキャッシュキーサイズが最大1kbになっていたが、現在は250バイトに削減された。config.cache_store = :redis_cache_store, { max_key_size: 64 }
fatkodima
同Changelogより
注: ActiveSupport::Cache::RedisCacheStore
キャッシュキー最大サイズのデフォルト値が変更されたことで、既存のRailsアプリケーションで250バイトを超えるキャッシュキーが使われている場合にキャッシュが無効になる可能性が考えられます(レビューコメントによると250バイトを超えることはめったにないだろうとされていますが)。
🔗 Use UNLINK for RedisCacheStore in ActiveSupport by roharon · Pull Request #54861 · rails/rails
ActiveSupport::Cache::RedisCacheStore
で従来のDEL
コマンドではなくUNLINK
コマンド(ブロッキングしないため高速)を使うよう変更された。Aron Roh
同Changelogより
🔗 Add Cache#read_counter
and Cache#write_counter
by ghiculescu · Pull Request #54855 · rails/rails
Cache#read_counter
メソッドとCache#write_counter
メソッドが追加された。Rails.cache.write_counter("foo", 1) Rails.cache.read_counter("foo") # => 1 Rails.cache.increment("foo") Rails.cache.read_counter("foo") # => 2
Alex Ghiculescu
同Changelogより
🔗 Introduce capture_error_reports
by andrewn617 · Pull Request #54809 · rails/rails
ActiveSupport::Testing::ErrorReporterAssertions
に#capture_error_reports
を導入した。指定のエラークラスと一致するブロック内で発生したエラーをすべてキャプチャする。
reports = capture_error_reports(IOError) do Rails.error.report(IOError.new("Oops")) Rails.error.report(IOError.new("Oh no")) Rails.error.report(StandardError.new) end assert_equal 2, reports.size assert_equal "Oops", reports.first.error.message assert_equal "Oh no", reports.last.error.message
Andrew Novoselac
同Changelogより
🔗 Introduce ActiveSupport::ErrorReport#add_middleware by andrewn617 · Pull Request #54512 · rails/rails
ActiveSupport::ErrorReporter
に#add_middleware
メソッドを導入。エラーを報告する際、報告されたエラーとベース実行コンテキストを引数として、エラーコンテキストミドルウェアが呼び出されるようになった。
スタックはコンテキストハッシュを変更することが許されており、変更されたコンテキストはエラーサブスクライバに渡される。ミドルウェアはErrorReporter#report
と同じパラメータを受け取る。Andrew Novoselac, Sam Schmidt
同Changelogより
🔗 Allow execution wrapper to handle all exceptions by gmcgibbon · Pull Request #54455 · rails/rails★
executorのエラーラッピングを変更して、
Exception
を含むあらゆる例外をレポートするよう変更。
SystemStackError
やNoMemoryError
といった重大なエラーが発生した場合は、エラーレポーターでもこの種の例外を報告可能にすべき。Gannon McGibbon
同Changelogより
🔗 Clear AR connections in tests before forking for parallelization by flavorjones · Pull Request #54376 · rails/rails
テストワーカーがforkする直前に呼び出されるコールバックを
ActiveSupport::Testing::Parallelization.before_fork_hook
で宣言可能にした。Mike Dalessio
同Changelogより
🔗 Allow passing in a date or time to ActiveSupport::Testing::TimeHelpers#freeze_time by joshuay03 · Pull Request #54303 · rails/rails
#freeze_time
テストヘルパーの引数に日付や時刻を渡せるようになった。Time.current # => Sun, 09 Jul 2024 15:34:49 EST -05:00 freeze_time Time.current + 1.day sleep 1 Time.current # => Mon, 10 Jul 2024 15:34:49 EST -05:00
Joshua Young
同Changelogより
🔗 JSON serialized attributes can return symbolized keys by matthaigh27 · Pull Request #54172 · rails/rails
ActiveSupport::JSON
に以下のようにオプションを渡せるようになった。ActiveSupport::JSON.decode('{"key": "value"}', symbolize_names: true) # => { key: "value" }
matthaigh27
同Changelogより
🔗 Update NotificationAssertions
's assert_notifcation
to match against payload subsets and return matched notification by larouxn · Pull Request #54126 · rails/rails
ActiveSupport::Testing::NotificationAssertions
'sassert_notification
がデフォルトでペイロードのサブセットに部分マッチするようになった。従来は、通知ペイロード内のキーバリューが長過ぎるため、以下のアサーションは失敗していた。ペイロードのサブセットにマッチするよう修正されたことで、アサーションがパスするようになった。
assert_notification("post.submitted", title: "Cool Post") do ActiveSupport::Notifications.instrument("post.submitted", title: "Cool Post", body: "Cool Body") end
また、マッチした通知を永続化してアサーションをさらにカスタマイズできるようになった。
notification = assert_notification("post.submitted", title: "Cool Post") do ActiveSupport::Notifications.instrument("post.submitted", title: "Cool Post", body: Body.new("Cool Body")) end assert_instance_of(Body, notification.payload[:body])
Nicholas La Roux
同Changelogより
🔗 Deprecate String#mb_chars
and AS::Multibyte::Chars
. by byroot · Pull Request #54081 · rails/rails★
String#mb_chars
とActiveSupport::Multibyte::Chars
が非推奨化された。これらのAPIはRubyの文字列がエンコーディング情報を認識していなかったRuby 1.8時代の遺物であり、今日ではこれらを必要とするまっとうな理由は存在しない。
Jean Boussier
同Changelogより
🔗 Deprecate ActiveSupport::Configurable
by seanpdoyle · Pull Request #53970 · rails/rails★
ActiveSupport::Configurable
が非推奨化された。Sean Doyle
同Changelogより
🔗 Fix #to_query
to not include =
for nil values by byroot · Pull Request #53962 · rails/rails★
nil.to_query("key")
がkey=
ではなくkey
をクエリ文字列として返すよう修正。従来は
key=
がクエリ文字列として返されていたため、Rack::Utils.parse_nested_query
の挙動と合っていなかった。Erol Fornoles
同Changelogより
🔗 Don't wrap redis in ConnectionPool
if already given one for ActiveSupport::Cache::RedisCacheStore
by joshuay03 · Pull Request #53845 · rails/rails
ActiveSupport::Cache::RedisCacheStore
を利用している状態で、:redis
オプションが既にConnectionPool
の場合はConnectionPool
にredisをラップしないよう修正。Joshua Young
同Changelogより
🔗 Improve error highlighting of multiline methods in ERB templates by martinemde · Pull Request #53763 · rails/rails★
ERB::Util.tokenize
のエラーハイライトを改善。文字列にERBタグが含まれていない場合に、完全な入力文字列を含む:PLAIN
トークンを返すように なった。Martin Emde
同Changelogより
🔗 Fix multibyte character tokenization bug in ERB::Util by martinemde · Pull Request #53655 · rails/rails★
ERB::Util.tokenize
で、ERBタグの前にマルチバイト文字が存在する場合にトークン化がおかしくなるバグを修正。Martin Emde
同Changelogより
🔗 Add ActiveSupport::Testing::NotificationAssertions
test helper module by larouxn · Pull Request #53065 · rails/rails
ActiveSupport::Notifications
のテストを支援するActiveSupport::Testing::NotificationAssertions
モジュールを追加。Nicholas La Roux, Yishu See, Sean Doyle
同Changelogより
🔗 Fix CurrentAttributes#attributes
to return new object each time by fatkodima · Pull Request #53440 · rails/rails★
ActiveSupport::CurrentAttributes#attributes
メソッドが呼び出しのたびに新しいハッシュオブジェクトを返すよう修正。従来は、メソッド呼び出しのたびに同じハッシュオブジェクトを返していた。
fatkodima
同Changelogより
🔗 Add prefix address when IPAddr of CIDR encoded with JSON by taketo1113 · Pull Request #53393 · rails/rails
ActiveSupport::JSON.encode
でCIDR記法をサポートするようになった。従来:
ActiveSupport::JSON.encode(IPAddr.new("172.16.0.0/24")) # => "\"172.16.0.0\""
変更後:
ActiveSupport::JSON.encode(IPAddr.new("172.16.0.0/24")) # => "\"172.16.0.0/24\""
Taketo Takashima
同Changelogより
🔗 Make FileUpdateChecker faster with many extensions by jdelStrother · Pull Request #53680 · rails/rails
ActiveSupport::FileUpdateChecker
で多数のファイル拡張子をチェックするときの速度を改善した。Jonathan del Strother
同Changelogより
breaking changesの可能性があるプルリク・コミット
個別のプルリクにも目印として★を追加しています。