なるようになるブログ

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

rails commit log流し読み(2020/05/04)

2020/05/04分のコミットです。

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


[ActiveStorage] Rewrite Blob.unattached scope code using where.missing

activestorage/app/models/active_storage/blob.rbの修正です。

Blob.unattached scopeを、where.missingを使用するようリファクタリングしています。


Support reentrant calls to RakeCommand.perform

railties/lib/rails/commands/rake/rake_command.rbrailties/lib/rails/tasks/statistics.rakeの修正です。

他のtop-level task実行された場合にRakeCommand.performが再度実行出来ないがバグがあったのを修正しています。


Adds :inline option to Action Mailbox generator rails_command

actionmailbox/lib/generators/action_mailbox/install/install_generator.rbの修正です。

Action Mailboxのmigration生成処理で、inlineオプションを指定して直接Rails::Command.invokeを実行するよう修正しています。


Fix rewhere to allow overwriting association queries

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

rewhereでassociation queryのオーバーライドが出来るよう修正しています。


Test actual query and result

activerecord/test/cases/finder_test.rbactiverecord/test/cases/relation/where_chain_test.rbの修正です。

rewhereのテストで結果を比較するのに、where_clauseやreleationで比較していたのを、to_aした値で比較するよう修正しています。

rails commit log流し読み(2020/05/03)

2020/05/03分のコミットです。

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

actionpack/CHANGELOG.md


Remove require_dependency usage in helper [Closes #37632]

helperメソッドでhelper moduleをロードする際に、require_dependencyを使用していたのを、String#constantizeを使用してのロードを使用するよう修正しています。

require_dependencyに依存していると、autoload pathsを$LOAD_PATHに追加する必要があり、それを避ける為(config.add_autoload_paths_to_load_pathにfalseを指定出来るようにする為)。

これにより、helper "foo/bar"とした場合、

require_dependency "foo/bar_helper"
module_name = "foo/bar_helper".camelize
module_name.constantize

という挙動になっていたのが、

prefix = "foo/bar".camelize
"#{prefix}Helper".constantize

となっています。通常のユースケースでは恐らく問題ないですが、autoload pathsには存在しないが$LOAD_PATHにのみ指定していたhelper pathにあるhelperをロードするような場合に影響があります。


Fix typo

actionpack/test/abstract_unit.rbactionpack/test/controller/helper_test.rbの修正です。

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


Fix actionview tests for missing helper

actionview/test/abstract_unit.rbactionview/test/actionpack/abstract/helper_test.rbの修正です。

先のhelperメソッドの挙動変更の対応によりAction Viewのテストがエラーになってしまっていたのを修正しています。


Allow associations to be autosaved multiple times

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

associationのautosaveが必ず一回しか実行されなくなってしまっていたのを、複数回実行されるよう修正しています。

save後にtransactionをrollbackしsaveを無効化し再度saveを行う、というような場合に実行されるようにする為。


Extract build_cast_value for limit_value and offset_value

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

LIMITOFFSETのcast valueのbuild処理をメソッドに切り出しています。


Don't use deprecated column in the error message

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

エラーメッセージ内でdeprecateになったcolumnを使用している箇所があったのを、使用しないよう修正しています。


Refactor preparable to be had the state in Arel collectors

Active Recordの修正です。

preparableかどうかの情報を専用のmoduleで保持していたのを、Arel collectorsで保持するよう修正しています。


Fix random CI failure due to non-deterministic has_one record

activerecord/test/models/company.rbの修正です。

テスト用のクラスのhas_one associationにorderの指定を追加しています。結果が不定になるのを避ける為。

rails commit log流し読み(2020/05/02)

2020/05/02分のコミットです。

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

activerecord/CHANGELOG.md

activemodel/CHANGELOG.md


Add back the support to pass at as a proc in the job assertions

activejob/lib/active_job/test_helper.rbの修正です。

job assertionsのat引数にProcオブジェクトを渡せるよう修正しています。


Add test for slug to ID with ID is out of range

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

whereの引数のidにslug + 範囲外の値を指定した場合のテストを追加しています。


Support query attrs and bind params in dot output

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

dot出力でquery attrsとbind paramsをサポートするよう修正しています。


Merge pull request #39108 from kamipo/lock_benchmarck-ips_version

benchmark-ipsのバージョンを2.8.0未満にロックしています。2.8.0だと必要なファイルがgemに含まれておらず、使用時にエラー(LoadError)になってしまう為。


Support limit(n) and offset(n) nodes in dot output

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

dot出力でlimit(n)offset(n) nodeをサポートするよう修正しています。


Deprecate passing a column to type_cast

Active Recordの修正です。

type_castにcolumnを渡すのがdeprecateになりました。

type castに必要な型情報はtype objectから完全に分離されており、type_castにcolumnを渡して処理を行う事は通常不要な為。


Fix minimum and maximum on non numeric column

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

Fix aggregate functions to return numeric value consistently even on custom attribute typeでaggregation functionsの結果が必ずnumericになるようにしたのですが、minimummaximumに関してはそうでは無かった(引数にdateカラムを指定した場合、結果はdateになる事を期待していた)為、minimummaximumについては元の挙動になるよう修正しています。


Deprecate marshalling load from legacy attributes format

activemodel/lib/active_model/attribute_set/builder.rbの修正です。

PERF: Recover marshaling dump/load performanceでattribute hashをmarshallした際のフォーマットが変更になったのですが、その変更前の古いフォーマットでのloadのサポートがdeprecateになりました。


Depend on Zeitwerk 2.3

Zeitwerkのバージョン指定を~> 2.3に修正しています。

rails commit log流し読み(2020/05/01)

2020/05/01分のコミットです。

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


Batch attribute methods definition in a single module_eval

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

attribute methodsを定義する際に、メソッド毎にmodule_evalを実行していたのを、まとめて1つのmodule_evalでメソッドの定義を行うよう修正しています。


Should not rely on the global Arel::Table.engine in the framework

Active Recordの修正です。

グローバルのArel::Table.engineに依存していた処理があったのを、依存しないよう修正しています。

DBを複数使用している場合、グローバルのArel::Table.engineとcurrent connectionは同じ値とは限らない為。


Merge pull request #39064 from kamipo/pg-1.1

pg gemのrequireバージョンを1.1以上に修正しています。

違う対応で必要な機能が1.1.0で追加されている、1.1.0以上をサポートする事でクリーンアップ出来る箇所がある、等の理由により対応が行われています。


Merge pull request #39063 from kamipo/remove_useless_typecast_on_aggregation

Active Recordの修正です。

aggregated valueに対するtype cast処理を削除しています。

PostgreSQL adapterの為にcast処理が必要だったのですが、adapter側でnumeric valueを直接返す事ができるようになり、cast処理は不要になった為削除しています。


Fix random CI failure due to non-deterministic order

activerecord/test/cases/associations/nested_through_associations_test.rbの修正です。

データを取得する際にorderを指定するよう修正しています。結果が不定になるのを避ける為。


Replace result_as_array by type mapping

activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rbactiverecord/lib/active_record/connection_adapters/postgresql_adapter.rbの修正です。

PostgreSQL adapterでqueryの実行結果のArrayへの変換処理を独自メソッドで行っていたのを、type mappingを使用するよう修正しています。


Avoid quite useless loop in find_by_sql

activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rbactiverecord/lib/active_record/querying.rbの修正です。

find_by_sqlメソッドで、不要な場合ばcolumn typeの設定処理のループを行わないよう修正しています。


Also batch attribute readers and writers

Active Recordの修正です。

Batch attribute methods definition in a single module_evalで、readerとsetterについて対応が漏れていた為、readerとsetterについても1つのmodule_evalでまとめてメソッドの定義を行うようにしています。


Add mention to shared section in config_for docs [ci skip]

rails guideのConfiguring Rails Applications、及び、railties/lib/rails/application.rbのdocの修正です。

config_forのshared sectionについての説明を追加しています。


Remove internal without_transaction_enrollment callbacks

activerecord/lib/active_record/touch_later.rbactiverecord/lib/active_record/transactions.rbの修正です。

without_transaction_enrollment callbackを削除しています。

internal用に追加されたが現在は使っていない、かつ、具体的にユーザが使用出来るユースケースも現状無い、という理由で削除されています。

rails commit log流し読み(2020/04/30)

2020/04/30分のコミットです。

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

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


Deprecate allowed_index_name_length in DatabaseLimits

activerecord/lib/active_record/connection_adapters/abstract/database_limits.rbactiverecord/lib/active_record/connection_adapters/abstract/schema_statements.rbの修正です。

DatabaseLimitsallowed_index_name_lengthをdeprecateにしています。

allowed_index_name_lengthはSQLite3 adapterで、一時的にリネームする際のマージンを考慮した値を返すメソッドでしたが、実際はそのマージンの考慮は不要であり、このメソッドももう不要となった為deprecateにしています。


removes require_dependency calls in ActiveStorage::Blob

activestorage/app/models/active_storage/blob.rbの修正です。

blob関連のmoduleをロードするのにrequire_dependencyで明示的にファイル名を指定していたのを、各moduleをqualified nameで指定するようにしてい、require_dependency無しでロード出来るよう対応しています。


Merge pull request #39087 from RKushnir/plus-prefix-operator-for-duration

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

ActiveSupport::Durationでunary plusをオーバーライドして、selfを返すよう修正しています。これにより、+ 1.secondの戻り値もActiveSupport::Durationになります。

Before:

+1.second.class
# => ActiveSupport::Duration
(+ 1.second).class
# => Integer

After:

+1.second.class
# => ActiveSupport::Duration
(+ 1.second).class
# => ActiveSupport::Duration

rails commit log流し読み(2020/04/29)

2020/04/29分のコミットです。

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


Replace all single quotes in code snippets by double quotes for consistency

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

各exampleコードのシングルクォートをダブルクォートに修正しています。


Remove confusing json by default support and add json post example

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

What to include in your Functional Testsの項に、JSONリクエストでデータを作成する方法の例を追加しています。


Ensure direct uploads to a public S3 service have a public ACL

activestorage/lib/active_storage/service/s3_service.rbの修正です。

configにpublic: trueを指定した場合に、S3にdirect uploadでアップロードしたファイルにpublic ACL権限が指定されないバグがあったのを修正しています。


Set a public ACL for files uploaded to a public GCS service

activestorage/lib/active_storage/service/gcs_service.rbの修正です。

GCS serviceでアップロードするファイルに対するオプションを指定出来るよう対応しています。

が、CIを壊してしまった為、後ほどRevertされています。


Revert "Set a public ACL for files uploaded to a public GCS service"

直前のGCS serviceでアップロードするファイルに対するオプションを指定出来るようにした対応をRevertしています。


Do not need - 2 margin for allowed_index_name_length in SQLite3

activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rbactiverecord/lib/active_record/connection_adapters/sqlite3_adapter.rbの修正です。

SQLite3 adapterでallowed_index_name_lengthindex_name_lengthから-2にした値を返していたのを、index_name_lengthの値をそのまま返すよう修正しています。

Rails内部でrename処理をする際に一時的な値として2文字追加する為、その分を-2していたのですが、SQLite3ではidentifier name lengthには上限が無く、マージンは必要無かった為削除しています。


Merge pull request #38374 from peterb/improve_zeitwerk_check_warning_message

railties/lib/rails/tasks/zeitwerk.rakeの修正です。

zeitwerk:checkでautoloadされるがeager loadの対象になってないディレクトリがあった場合に表示されるメッセージを、eager loadの対象に追加されてないからチェックが行われてない事がわかるよう修正しています。


files -> directories in zeitwerk:check warning [skip ci]

railties/lib/rails/tasks/zeitwerk.rakeの修正です。

先のメッセージの修正のフォローアップとして、メッセージ内のfilesdirectoriesに修正しています。

zeitwerk:checkでautoloadされるがeager loadの対象になってないディレクトリがあった場合に表示されるメッセージを、eager loadの対象に追加されてないからチェックが行われてない事がわかるよう修正しています。


files -> directories in zeitwerk:check warning [skip ci]

rails commit log流し読み(2020/04/28)

2020/04/28分のコミットです。

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


Refactor Arel node Casted, Quoted, and BindParam

Active Recordの修正です。

Casted, Quoted, BindParamクラスにvalue_for_databasevalue_before_type_castメソッドを定義し、値の変換処理をそれぞれのメソッドで行うよう修正しています。


Improve performance for scope_for_create

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

scope_for_createメソッドで不要なオブジェクトの生成数を減らすようリファクタリングしています。