なるようになるブログ

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

rails commit log流し読み(2022/09/14)

2022/09/14分のコミットです。

CHANGELOGへの追加はありませんでした。


Clarify --edge points to latest stable branch of rails

railties/lib/rails/generators/app_base.rbの修正です。

rails new--edgeオプションを指定した場合に使用されるブランチ名をオプションのdescriptionに含むよう修正しています。


Use explicit deprecator in AS::Deprecation tests

activesupport/test/deprecation_test.rbの修正です。

Use explicit deprecator in AS::Deprecation testsと同様に、ActiveSupport::Deprecationのテストでテスト内で固有のdeprecatorを使用するよう修正しています。


Update guides on secuity page for sql injection sample code [ci-skip]

rails guideのSecuring Rails Applicationsの修正です。

sql injectionのサンプルコードを、現在のRailsが生成するSQLで成功する内容に修正しています。


Merge pull request #46024 from sreeram-venkitesh/fix-action-controller-link [ci-skip]

rails guideのLayouts and Rendering in Railsの修正です。

renderメソッドのAPI docのリンク先が誤っていたのを修正しています。


ErrorReporter: allow to unsubscribe

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

ErrorReporterでsubscriberのunscribeが出来るようメソッドを追加しています。


Add ability to handle reconnects with the connected() callback

Action Cableの修正です。

connected()メソッドのcallbackで、reconnect処理が行われたどうかを判別出来るよう修正しています。


[ci skip] Fix form_with documentation

actionview/lib/action_view/helpers/form_helper.rbのdocの修正です。

form_withメソッドのdoc内のexampleで、現在生成されないdata-remoteが残っている箇所があったのを修正しています。

rails commit log流し読み(2022/09/13)

2022/09/13分のコミットです。

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

activejob/CHANGELOG.md


Fix disallowed deprecations with default warning

activesupport/lib/active_support/deprecation/disallowed.rbactivesupport/lib/active_support/deprecation/reporting.rbの修正です。

filterにString、Symbolを指定 + デフォルトのwarning messageを使用した場合に、deprecation_disallowed?explicitly_allowed?メソッドでエラーになってしまうバグがあったのを修正しています。


Fix missed test changes for pool method deprecations

activerecord/test/cases/connection_adapters/connection_handler_test.rbactiverecord/test/cases/connection_management_test.rbの修正です。

テストの実行順によりfailしてしまうテストがあったのを修正しています。


Minor refactoring to schema migration and internal metadata

activerecord/lib/active_record/migration.rbactiverecord/lib/active_record/schema_migration.rbの修正です。

ActiveRecord::SchemaMigrationActiveRecord::InternalMetadataActiveRecord::Baseの子クラスでなくなった事を説明する為のdeprecateメッセージに、アプリケーション側で必要な対応の詳細な情報を含むよう修正しています。


ActiveModel: Fix method name in Callbacks documentation.

activemodel/lib/active_model/callbacks.rbのdocの修正です。

initializeinitializerにタイポしていたのを修正しています。


Fix bug in internal metadata

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

internal metadataに値を追加する際に、すでに同じ値があった場合の挙動が、Move InternalMetadata to an independent objectの対応で誤って変更されてしまったのを、元の挙動に戻しています。


Clarifications for the Plugins Rails Guide

rails guideのThe Basics of Creating Rails Pluginsの修正です。

rails pluginコマンドで生成するgemspecを修正する説明を追加(修正しないとbundleコマンドの実行がエラーになる為)、及び、exampleコードでrequireが不足していたのを修正しています。


Merge pull request #46005 from yahonda/diag45899

Active Jobの修正です。

Active JobからQue gem用のadapterを削除しています。Que gem側でもActive Job向けの処理が含まれており、それぞれのgemで処理を行うのは煩雑、かつ、メンテナンスが困難になる為、Active Job側からは削除されました。今後Que gem側でActive Job用のadapterが追加される予定、との事です。


Merge pull request #44547 from skipkayhil/fix-incorrect-assertions

Minitest/AssertWithExpectedArgument copを追加、及び、誤ったassertionの指定をしている箇所があったのを修正しています。


Remove redundant AS::Deprecation tests

activesupport/test/deprecation_test.rbの修正です。

ActiveSupport::Deprecationのテストで、内容が重複しているテストがあったのを削除しています。


Use declarative syntax for AS::Deprecation tests

activesupport/test/deprecation_test.rbの修正です。

テストを定義するのにdeclarative syntax(testメソッドを使用した方式)を使用するよう修正しています。


Test AS::Deprecation :log behavior

activesupport/test/deprecation_test.rbの修正です。

ActiveSupport::Deprecationのbehaviorに:logを指定した場合のテストを追加しています。


Use explicit deprecator in AS::Deprecation tests

activesupport/test/deprecation_test.rbの修正です。

Use explicit deprecator in AS::Deprecation testsと同様に、ActiveSupport::Deprecationのテストでテスト内で固有のdeprecatorを使用するよう修正しています。


Simpler Railtie subscribe in error_reporting.md

rails guideのError Reporting in Rails Applicationsの修正です。

Railtieでのsubscribe処理のexampleコードをRails.errorを使用するよう修正しています。

rails commit log流し読み(2022/09/12)

2022/09/12分のコミットです。

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

activerecord/CHANGELOG.md


Use explicit deprecator in AS::Deprecation tests

activesupport/test/deprecation_test.rbの修正です。

ActiveSupport::Deprecationのテストで、テスト内で固有のdeprecatorを使用するよう修正しています。top-levelのActiveSupport::Deprecation APIを削除しても良いのでは、という議論があり、その為の対応との事です。


Allow empty callstack in AS::Deprecation#warn

activesupport/lib/active_support/deprecation/reporting.rbの修正です。

ActiveSupport::deprecation#warnに空のcallbackを指定出来るよう修正しています。


Clean up deprecation tests

activesupport/test/deprecation_test.rbの修正です。

ActiveSupport::Deprecationのテストで、テスト後にbehaviorの状態等を元に戻すよう修正しています。


Merge pull request #45997 from RubyElders/add-rack-deep-params

actionpack/lib/action_dispatch/http/request.rbの修正です。

ActionDispatch::RequestのHTTP request処理でrescueするエラークラスにRack::QueryParser::ParamsTooDeepErrorを追加しています。 Rack 2.2.4以降だと、paramsがlimit以上にnestしている場合に、Rack::QueryParser::ParamsTooDeepErrorをraiseするようになった為。


Merge pull request #45946 from st0012/error-reporter-doc

Rails guideに、Error Reporter機能について説明した、Error Reporting in Rails Applications guideを追加しています。


Move InternalMetadata to an independent object

Active Recordの修正です。

ActiveRecord::InternalMetadataActiveRecord::Baseの子クラスだったのを、ActiveRecord::Baseとの継承関係が無い独立したクラスに変更しています。何らかの理由でActiveRecord::InternalMetadata経由でconnectionを操作したい場合、ActiveRecord::InternalMetadataconnection attributeが追加されている為、その値経由で処理を行えるようになっています。

rails commit log流し読み(2022/09/10)

2022/09/10分のコミットです。

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

activerecord/CHANGELOG.md

actionpack/CHANGELOG.md

actionmailer/CHANGELOG.md

activesupport/CHANGELOG.md


Default prepared_statements to false for mysql2 adapter

activerecord/lib/active_record/connection_adapters/abstract_adapter.rbactiverecord/lib/active_record/connection_adapters/mysql2_adapter.rbの修正です。

MySQL adapterでprepared_statementsのデフォルトが誤ってtrueになってしまっていたのを、falseに戻しています。なお、Rails 7.2からはデフォルトtrueになる予定。


Improve app generator docs

railties/lib/rails/generators/rails/app/USAGEの修正です。

app generatorのdocについて、フォーマットの修正、exampleコードの追加等を行っています。


Merge pull request #45964 from jhawthorn/server_timing_safety

actionpack/lib/action_dispatch/middleware/server_timing.rbの修正です。

ActionDispatch::ServerTiming middlewareがマルチスレッド環境だと正しく結果が取得出来ないバグがあったのを修正しています。


Fix grammatical issue

railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.ttの修正です。

config.eager_loadについて説明している箇所のグラマーの修正を行っています。


improve "in_order_of" to allow string column name

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

QueryMethods#in_order_ofでstring columnの値でもorder処理が出来るよう修正しています。


Extract annotations using a parser for Ruby files

railties/lib/rails/source_annotation_extractor.rbの修正です。

Rubyファイルのannotationsの取得処理に、ripperを使用するよう修正しています。実際のコードが無いコメントだけのannotationを除外出来るようにする為。


Recommend mandatory STARTTLS for Google (#43594)

actionmailer/lib/action_mailer/base.rbのdoc、及び、rails guideのAction Mailer Basicsの修正です。

config.action_mailer.smtp_settingsのexampleで、enable_starttls_autoではなくenable_starttlsを使用するよう修正しています。STARTTLSの方がセキュアな為。


Merge pull request #41517 from brunoarueira/fix/issue-38080-encoding-uploaded-file-headers

actionpack/lib/action_dispatch/http/upload.rbの修正です。

ActionDispatch::Http::UploadedFileのheaderのencodeがUTF-8になるよう修正しています。元はASCII-8BITだったのですが、ASCII-8BITだと値をjsonに変換するような場合(instrumentで取得した値をそのままJSONに変換したい場合など)にエラーになってしまう為。


Add more instructions to RELEASING_RAILS

RELEASING_RAILS.mdの修正です。

リリース前の各パッケージサイトのログイン確認や、リリース処理後のリリースアナウンスの記事のフォーマットの追加などを行っています。


Merge pull request #45887 from ianneub/add-exclude-to-action_controller-parameters

actionpack/lib/action_controller/metal/strong_parameters.rbの修正です。

ActionController::Parametersに指定されたkeyが存在しない場合にtrueを返すexclude?メソッドを追加しています。


Merge pull request #44131 from frenkel/explicit-negative-currency-format

activesupport/lib/active_support/locale/en.ymlの修正です。

currencyのnegative値のデフォルトフォーマット(negative_format)を追加しています。値は-%u%nNumberHelpernegative_formatを使用している箇所がある為。


Merge pull request #40051 from fsateler/feature/redirect-referer

actionpack/lib/action_dispatch/testing/integration.rbの修正です。

follow_redirect!メソッドでHTTP_REFERER headerを設定するよう修正しています。実際のブラウザの挙動と合わせる為。


Copy-edit 8e65c22

actionpack/CHANGELOG.mdの修正です。

先のfollow_redirect!の対応のエントリーをファイルの先頭に移動しています。


Merge PR #44438

activerecord/lib/active_record/connection_adapters/abstract/quoting.rbactiverecord/lib/active_record/connection_adapters/mysql/quoting.rbの修正です。

ActiveSupport::DurationSQLのbind parameterとして渡した場合に、自動でinteger値に変換する、という挙動がdeprecateになりました。今後は、明示的に呼び出す側で変換する必要があります。

# 秒のinteger値が必要な場合
Record.where("duration = ?", 1.hour.to_i)

# ISO 8601 stringが必要な場合
Record.where("duration = ?", 1.hour.iso8601)

Require used model to fix isolated tests

activerecord/test/cases/relation/field_ordered_values_test.rbの修正です。

不足していたmodelのrequireを追加しています。


Merge pull request #45829 from ghiculescu/nested-attribute-docs-improvements

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

nested attributesを使用したformの作り方の説明、及び、そのformのデータをテストでエミュレートした場合のexampleをdocに追加しています。


Merge pull request #45987 from igorkasyanchuk/main

Action Mailer、railtiesの修正です。

email preview pageでメールをEMLファイルとしてダウンロードが出来るよう修正しています。


Merge PR #45956

actionpack/lib/action_dispatch/middleware/cookies.rbの修正です。

encrypted cookieのparse処理で、JSON::ParserErrorをrescueするよう修正しています。cookie serializerにJSONを指定している場合にJSON::ParserErrorが発生する可能性がある、かつ、エラーがそのままraiseされてしまうと、サーバ側でcookieが削除出来ず、ユーザがブラウザでcookieを削除しないといけなくなってしまう為。


Corrected hyperlink address in help manual -h, -c option by removing the unnecessary bracket. (#45989)

railties/lib/rails/generators/rails/app/app_generator.rbの修正です。

app generatorのcssオプションのdescriptionを修正しています。


Remove unnecessary gitignore entry

.gitignoreの修正です。

先のコミットで誤って不要なignoreの設定が追加されてしまったのを削除しています。


Use devcontainer features to install github CLI (#45990)

devcontainerの修正です。

devcontainerでgithub-cliをインストールするよう修正しています。また、github-cliにより不要になった各処理用のスクリプトを削除しています。


Remove CHANGELOG entry for change only existing in main

activerecord/CHANGELOG.mdの修正です。

Default prepared_statements to false for mysql2 adapterで追加されたエントリーを削除しています。prepared_statementsのデフォルトが誤ってtrueになっていたのはmainブランチのみで、リリースされたgemに影響が無くCHANGELOGの記載が不要な為。


Merge pull request #45974 from gmcgibbon/improve_plugin_generator_docs

railties/lib/rails/generators/rails/plugin/USAGEの修正です。

plugin generatorのUSAGAにより詳細なpluginについての説明を追加しています。


Add italic and underline support to ActiveSupport::LogSubscriber#color

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

ActiveSupport::LogSubscriber#colorメソッドで、ログ出力の際にitalic及びunderlineを指定出来るよう修正しています。合わせて、メソッドの第二引数で指定出来るようになっていたboldの指定をキーワード引数に変更しています。

info color("Hello world!", :red, bold: true, underline: true)

Merge pull request #45885 from iainbeeston/patch-1 [skip ci]

rails guideのActive Storage Overviewの修正です。

image processingに指定出来るオプションについての詳細な説明を追加しています。


Ruby 3.2 FileUtils.rm_f raises Errno::EISDIR to remove directories

railties/test/application/test_runner_test.rbの修正です。

ディレクトリを削除するのにFileUtils.rm_fを使用していたのを、FileUtils.rm_rを使用するよう修正しています。Ruby 3.2だとFileUtils.rm_fディレクトリを削除しようとするとエラーになる為。

rails commit log流し読み(2022/09/09)

2022/09/09分のコミットです。

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

activesupport/CHANGELOG.md

railties/CHANGELOG.md

actionview/CHANGELOG.md

activerecord/CHANGELOG.md


Revert "Merge pull request #44695 from Edouard-chin/ec-tagger-logger-broadcast"

TaggedLoggingが他のloggerに対してbroadcast処理を行う際にTaggedLoggingに指定されていたTagを送信するよう修正した、Fix TaggedLogging functionality when broadcasting to another logger:をRevertしています。

taggedに指定したtagが、tagの指定が無いログ出力の時にも使われてしまう、というバグがあった為。


Add String#downcase_first method

activesupport/lib/active_support/core_ext/string/inflections.rbactivesupport/lib/active_support/inflector/methods.rbの修正です。

最初の文字を小文字にするString#downcase_firstメソッドを追加しています。

downcase_first('If they enjoyed The Matrix') # => "if they enjoyed The Matrix"

Merge pull request #45972 from rails/revert-45904-drop-method-source

メソッドの定義箇所を取得するのにmethod_source gemを使用していたのをripperを使うよう修正した、Replace method_source gem with stdlib equivalentをRevertしています。 Active Supportのtestメソッドを使用したテストに対するfilter処理が正しく動作しなくなってしまった為。


Delegate application record generator description to orm hooked generator.

railties/lib/rails/generators/rails/application_record/application_record_generator.rbの修正です。

application record generator descriptionをorm hooked generatorにdelegateするよう修正しています。orm generatorで独自のdescriptionを定義している場合に、それが反映されるようにする為。


Add :locals to ActionView rendering instrumentation

Action Viewの修正です。

Action Viewのrendering instrumentationに:localsのデータを含むよう修正しています。


replace hardcoded ImageMagick with generic 'variant processor'

rails guideのConfiguring Rails Applicationsの修正です。

Active Storageのtransform処理について説明している箇所で、ImageMagickで処理が行われるという記載があったのを、variant processor経由と説明を修正しています。


Support prerelease rubies in Gemfile template

railties/lib/rails/generators/rails/app/templates/Gemfile.ttの修正です。

Gemfile templateでRubyのバージョン指定にRUBY_VERSIONではなくGem.ruby_versionを使用するよう修正しています。prerelease Rubyを指定出来るようにする為。


Merge pull request #45908 from rails/redo-schema-migration

Active Recordの修正です。

ActiveRecord::SchemaMigrationActiveRecord::Baseの子クラスだったのを、ActiveRecord::Baseとの継承関係が無い独立したクラスに変更しています。何らかの理由でActiveRecord::SchemaMigration経由でconnectionを操作したい場合、ActiveRecord::SchemaMigrationconnection attributeが追加されている為、その値経由で処理を行えるようになっています。


Mysql2Adapter remove reference to closed connection

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

Mysql2Adapter#reconnectメソッドでraw_connectionを初期化するよう修正しています。reconnect内のconnect処理で失敗した場合に、変な状態の変数が残らないようにする為。

rails commit log流し読み(2022/09/08)

2022/09/08分のコミットです。

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

activerecord/CHANGELOG.md

railties/CHANGELOG.md


Make ActionView::PathSet immutable

Action Viewの修正です。

ActionView::PathSetの状態を変更するメソッドを削除し、ActionView::PathSetがimmutableになるよう修正しています。また、削除されたメソッドの代わりに、新規にPathSetを生成する為のbuilderメソッドを追加しています。


Fix bug in connection handler methods using all pools

Active Recordの修正です。

connection handler methods(active_connections?, clear_active_connections!, clear_reloadable_connections!, clear_all_connections!, 及び flush_idle_connections!)が、roleが指定されていない場合current_role または :writing roleのpoolにしか処理をしなかったのを、デフォルトで全てのpoolに対して処理を行うよう修正しています。起動時に呼ばれる処理(flush_idle_connectionsclear_active_connections!など)は、roleに関わらず全てのpoolに対して行われる事が期待されている処理な為、デフォルトを全てのpoolに対しての処理に変更したとの事です。


Make connection_pool_list take an explicit argument

Active Recordの修正です。

all_connection_poolsメソッドをdeprecatedに変更、及び、connection_pool_listメソッドの引数の指定を必須に変更しています。all_connection_poolsメソッドと同様の結果が必要な場合、connection_pool_list(:all)を使用する必要があります。


Fix loading records with encrypted attributes defined on columns with default values

activerecord/lib/active_record/encryption/encryptable_record.rbactiverecord/lib/active_record/encryption/encrypted_attribute_type.rbの修正です。

encrypted attributesにcolumnsのdefault valueが反映されないバグがあったのを修正しています。


Make contributing guide consistent about bug fixes

rails guideのContributing to Ruby on Railsの修正です。

CHANGELOGについて説明している箇所で、軽微なbug fixの場合CHANGELOGの追加は不要である旨説明を修正しています。


Show BCC recipients in mailer preview

railties/lib/rails/templates/rails/mailers/email.html.erbの修正です。

mailerのpreivewでBCC recipientsを表示するよう修正しています。


Enable Minitest/AssertRaisesWithRegexpArgument cop

Minitest/AssertRaisesWithRegexpArgument copで指摘される内容の修正を行っています。実際のcopの追加は後ほど別コミットで行われています。


Enable Minitest/AssertRaisesWithRegexpArgument cop

Minitest/AssertRaisesWithRegexpArgument copを追加しています。


Fix typo in :active_record_suppressor_registry symbol

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

suppressorsuppresorにタイポしていたのを修正しています。


Reduce allocations of pool_configs

Active Recordの修正です。

pool_configsの取得処理で、オブジェクト生成数を減らすようリファクタリングしています。


Merge pull request #45495 from okuramasafumi/rewrite-pull-request-template

.github/pull_request_template.mdの修正です。

PRのテンプレートに、Checklist等記載して欲しい内容を追加しています。


Add ability to run only before/around/after callbacks in run_callbacks

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

run_callbacksメソッドで、どのcallback(before/around/afterのどれか)のみを実行するかを引数で指定出来るよう修正しています。