なるようになるブログ

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

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

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

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

railties/CHANGELOG.md


Address InnerJoinAssociationTest#test_eager_load_with_string_joins failure with mysql2

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

dirty testの前処理で作成したデータを後処理で削除するよう修正しています。MySQLだとテストの途中でデータがコミットされてしまっている為。


Adds a rails test:all rake task (#39221)

railties/lib/rails/test_unit/testing.rakeの修正です。

testディレクトリ配下の全てのテストを実行する為のtest:all taskを追加しています。

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

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

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

activerecord/CHANGELOG.md

actionpack/CHANGELOG.md


Add tests for to_s(:inspect)

Active Supportのテストの修正です。

to_s:inspectを指定した場合のテストを追加しています。


Fix index creation to preserve comment in bulk change table on MySQL

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

MySQLでbulk change tableでindexを作成する際に、commentオプションに指定した値がindex作成時に無視されてしまうバグがあったのを修正しています


Refactor index creation to use index definition visitor

Active Recordの修正です。

indexの作成処理をindex定義用のvisitorで行うようリファクタリングしています。


Remove unused require "active_support/core_ext/kernel/singleton_class"

使用していないactive_support/core_ext/kernel/singleton_classのrequireを削除しています。


Active Record uses singleton class eval in tests

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

active_support/core_ext/kernel/singleton_classのrequireを追加しています。テスト内でsingleton_classのclass_evalを使用している箇所があった為。


"core_ext/array" is not used in here, but used in others

require処理を、実際にそのrequireが必要なファイルで行うよう修正しています。


Callbacks tests also uses singleton class eval

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

active_support/core_ext/kernel/singleton_classのrequireを追加しています。テスト内でsingleton_classのclass_evalを使用している箇所があった為。


Remove unused require "active_support/core_ext/array/extract_options"

activesupport/lib/active_support/core_ext/class/attribute.rbactivesupport/lib/active_support/message_encryptor.rbの修正です。

使用していないactive_support/core_ext/array/extract_optionsのrequireを削除しています。


Eager generate relation methods if a method is on Kernel

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

Kernelにあるのと同じ名前のメソッドをrelationに定義した場合に、Kernel側のメソッドが呼ばれてしまうバグがあったのを修正しています。


Support ALGORITHM = INSTANT DDL option for index operations on MySQL

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

MySQLにindex operationsにALGORITHM = INSTANTのサポートを追加しています。


Don’t ignore X-Forwarded-For IPs with ports attached

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

X-Forwarded-For headerの値にport番号まで含まれていた場合に、remote_ipが正しいIPを返さないバグがあったのを修正しています。


Clarify existing app behavior when being upgraded [ci skip]

rails guideのUpgrading Ruby on Railsnの修正です。

Active Storage assignment behavior changeの項の言い回しを修正しています。


Use index_algorith(...) instead of index_algorithms.fetch(...)

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

Hashから値を取得するのにfetch + blockでArgumentErrorをraiseしていたのを、メソッドを使用して値を取得するよう修正しています。


Fix incorrectly successful datetime precision tests

activerecord/test/cases/adapters/mysql2/datetime_precision_quoting_test.rbの修正です。

値にmicrosecond precisionが含まれない事を確認するassertionが、microsecond precisionが含まれる場合も通る内容になってしまっていたのを修正しています。合わせて、もうサポートしていないバージョンのMariaDBに関するテストの削除等を行っています。

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

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

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


Make NameError#missing_name work even for real Ruby NameError

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

NameError#missing_nameメソッドを、Ruby本体のNameErrorが発生した場合も動作するよう修正しています。


reminder for helper Module in CHANGELOG for helper [ci skip]

actionpack/CHANGELOG.mdの修正です。

helperメソッドの挙動が変更になった対応( Remove require_dependency usage in helper [Closes #37632])についてのエントリーに、helperにmodule objectを渡せる事、及び、それを推奨する旨の説明を追加しています。


Add test case for generate_relation_method

activerecord/test/cases/scoping/named_scoping_test.rbactiverecord/test/models/topic.rbの修正です。

generate_relation_methodメソッドについてのテストを追加しています。


Remove duplicated attribute alias resolution

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

重複していたattributeのalias解決処理を削除しています。


Support kwargs for named scopes

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

named scopesで引数にキーワード引数を使用した場合に、キーワード引数に関するwarningが出ないよう対応しています。


Association callbacks work with abort instead of exceptions [ci skip]

rails guideのActive Record Associationsの修正です。

Association Callbacksの項で、before_addでExceptionをthrowするとassociationのadd/removeを中断される旨説明が行われていたのですが、実際はabortをthrowする必要がある旨、その旨説明を修正しています。

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

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

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

railties/CHANGELOG.md


Fix assert{enqueued,performed}with doc examples [ci skip]

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

assert_enqueued_with / assert_performed_withのdoc内にあるexampleで、jobに指定する引数とassertionに指定する引数が一致してなかったのを修正しています。


Link between configuration.md and cache_store documentation [ci skip]

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

config.cache_storeについて説明している箇所に、オプションに指定出来る値についてのdocへのリンク(Cache Stores guide)を追加しています。


Support procs for assert{enqueued,performed}with

activejob/lib/active_job/test_helper.rbactivejob/test/cases/test_helper_test.rbの修正です。

assert_enqueued_with / assert_performed_withのdoc内にargs引数にProcが指定出来る旨説明を追加、及び、Procを指定した場合のテストを追加しています。


Merge pull request #39001 from jonathanhefner/test-runner-recognize-windows-paths

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

test runnerのpath match処理が、Windowsでも動作するよう修正しています。


Make Active Storage update migrations reversible

activestorage/db/update_migrate/20190112182829_add_service_name_to_active_storage_blobs.rbactivestorage/db/update_migrate/20191206030411_create_active_storage_variant_records.rbの修正です。

Active Storageのupdate用migirationをrollback出来るよう対応しています。


remove_foreign_key doesn't care :validate option if database has no feature

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

MySQL adapterで、add_foreign_keyvalidateオプションを指定した場合に、ArgumentErrorが発生してしまうリグレッションが起こっていたのを修正しています。


Add config.generators.after_generate for processing to generated files

railtiesの修正です。

generatorsで生成したファイルに対して処理を行えるようにする為の、config.generators.after_generate callbackを追加しています。


undef_method can take varargs

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

undefine_attribute_methodsでメソッドを未定義にするのに、メソッド毎にundef_methodを呼び出していたのを、一度のundef_methodでまとめて未定義にするよう修正しています。

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

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

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

activesupport/CHANGELOG.md

railties/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #39164 from jhawthorn/deprecate_dots_take_two

actionview/lib/action_view/template/resolver.rbの修正です。

template名に.を使用するのをdeprecateにした対応を、再度コミットしています。

interpolated stringを使用した場合に誤ったdeprecate warningが出てしまうのは、Ignore interpolated strings in DependencyTrackerで対応された為。


Don't attempt to add a string to a lambda

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

Time::DATE_FORMATSにProcを指定した場合に、Stringとの連結処理を行わないよう修正しています。


Add DATE_FORMATS[:inspect]

Active Record、Active Supportの修正です。

Active Recordのtime attributesのinspect結果にsubsecの値も含むよう修正したのですが、これはTime::DATE_FORMATS[:db]にsubsecの値を追加する形で対応されました。

ただ、inspect用であれば、DATE_FORMATSinspect用のformatを追加した方が良いのでは、という意見が出て、DATE_FORMATS[:inspect]を追加し、そのformatでsubsecを指定するよう修正しています。


register the obsolescence of require_dependency in the CHANGELOG [ci skip]

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

require_dependencyのdocについて言い回しを修正&require_dependencyメソッドのdocにzeitwerk modeの場合require_dependencyはobsoleteである旨CHANGELOGに追記しています。


Merge pull request #39163 from kamipo/remove_deprecated_in_range

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

deprecateになっていたattr.inにrange objectを渡した場合の処理を削除しています。


Merge pull request #39036

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

テスト実行時にテスト対象とするファイル(test/**/*_test.rb)と除外するファイル(test/{system,dummy}/**/*_test.rb)をenv(DEFAULT_TESTDEFAULT_TEST_EXCLUDE)で指定出来るよう修正しています。


Do the attribute keys conversion at one place

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

attribute keyの変換処理をPredicateBuilder#build_from_hashメソッドでだけ行うよう修正しています。


Merge pull request #39148 from hotatekaoru/add_change_null_for_change_table

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

change_tableメソッド内でchange_nullメソッドを使用出来るよう対応しています。


Allow unscope to be aware of table name qualified values

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

unscopeの引数にテーブル名修飾値(e.g. posts.unscope(where: :"comments.hidden"))を指定出来るよう修正しています。


Merge pull request #38326 from Shopify/set-callback-allocations

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

set_callbacksメソッドで、Ruby 2.6より以上の場合の場合不要なオブジェクトの生成処理を行わないよう修正しています。


Update rails gem version in bug report templates to pass CI on Ruby master

bug report templates の修正です。

Railsのバージョンを6.0.3に更新していますRuby masterでテストが通るようにする為。


Fix the result of aggregations to maintain duplicated "group by" fields

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

同じカラムを複数回groupした場合の戻り値が6.0.36.0.2で変わってしまった(元は戻り値のkeyがArrayになっていたのが、Stringになった)のを、6.0.2までと同じ挙動になるよう修正しています。


Merge pull request #37905 from Vasfed/feature/guide_association_cleanup

rails guideのActive Record Associationsの修正です。

belongs_to associationについて説明している箇所に、belongs_toは1対1の関係に使われる旨説明が記載されている箇所があったのですが、実際はそうでは無いため、該当箇所の説明を修正、及び、associationに関する説明の追記を行っています。


Load selenium/webdriver only if needed

actionpack/lib/action_dispatch/system_test_case.rbactionpack/lib/action_dispatch/system_testing/driver.rbの修正です。

system testでselenium以外のdriverを使用している場合、selenium/webdriverはloadしないよう修正しています。

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

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

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

activesupport/CHANGELOG.md

actionview/CHANGELOG.md


Attributes can be dup-ed

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

ActiveModel::Attributesinitialize_dupメソッドを実装して、attributeをdup出来るよう対応しています。


Demonstrate connecting Active Storage to S3-compatible APIs [ci skip]

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

Digital Ocean SpacesのようなS3とAPIの互換性があるクラウドでActive Storageを使用する場合の説明を追加しています。


Revert "Merge pull request #39022 from kamipo/perf_where_in"

wherevalueのArrayを指定した場合にオブジェクトの生成数を減らせるようリファクタリングした、Merge pull request #39022 from kamipo/perf_where_inをRevertしています。違う性能改善のPRと変更内容がコンフリしてしまい、そちらをMerge出来るようにする為、との事です。


Merge branch 'fix-array-builder-wheres'

Active Recordの修正です。

wherevalueのArrayを指定した場合の性能改善として、同種の値がwhereに指定された場合用のnodeを追加し、既存のnodeで行っていたがスキップ出来る処理を行わないようにして、処理を高速に行えるようにしています。


Add 3rd person aliases of Symbol#start_with? and Symbol#end_with?

Active Supportの修正です。

Symbol#starts_with? / #ends_with?メソッドを追加しています。

それぞれSymbol#start_with? / end_with?のaliasとして定義されており、Symbol#start_with? / ends_with?メソッドが定義されていない場合ようにSymbol#start_with? / ends_with?メソッドの定義も追加しています。


Ensure array passed to preloader has no duplicate records by object_id

activerecord/lib/active_record/associations/preloader/association.rbの修正です。

has_many through associationをpreloadした際に、同じレコードが複数ロードされてしまうバグがあったのを修正しています。


Merge pull request #38999 from zvkemp/action-view-instrument-layout

Action Viewの修正です。

layoutのrendering処理(TemplateRenderer#render_with_layout)対してinstrumentation hookを追加しています。hook名はrender_layout.action_view


Ensure sqlite3_mem transaction tests run in memory

activerecord/test/cases/adapters/sqlite3/transaction_test.rbの修正です。

SQLite3でパスをファイルURIとして認識させる為のフラグ(SQLite3::Constants::Open::URI)の指定が漏れてしまっている箇所があったのを修正しています。


Preserve multiple arguments in Symbol#start_with? and Symbol#end_with?

activesupport/lib/active_support/core_ext/symbol/starts_ends_with.rbの修正です。

Ruby本体と同様に、Symbol#start_with?Symbol#end_with?に引数を複数渡せるよう修正しています。


Ensure type cast is not evaluated at relation build time

Active Recordの修正です。

type cast処理をrelation build時に行わないよう修正しています。query実行時に処理が実行される事を期待しているアプリがある為、との事です。


Remove redundant squish for single line message

activemodel/lib/active_model/attribute_set/builder.rbactiverecord/lib/active_record/connection_adapters/abstract/quoting.rbの修正です。

1行メッセージを出力するのに不要なsquishが指定されていたのを削除しています。


Merge pull request #39068 from jhawthorn/dependency_tracker_interpolation

actionview/lib/action_view/dependency_tracker.rbの修正です。

ActionView::DependencyTrackerでinterpolated stringは無視するよう修正しています。

ActionView::DependencyTracker正規表現でtemplateを検索するのですが、Rubyのコードの解析はしておらず、interpolated stringを使用すると想定と異なるtemplateを取得してしまう可能性がある為。


Removes require_dependency from the AR test suite

Active Recordのテストの修正です。

テスト内でrequire_dependencyを使用していたのを、普通にrequire / loadでファイルをロードするよう修正しています。


update the documentation of require_dependency [ci skip]

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

require_dependencyメソッドのdocにzeitwerk modeの場合require_dependencyはobsoleteである(使用する必要が無い)旨説明を追加しています。


Merge pull request #39162 from kamipo/dogfooding_symbol_starts_ends_with

Symbol#start_with? / #end_with?メソッドをRailsのコード内で使用するよう修正しています。

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

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

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

activerecord/CHANGELOG.md

actionmailer/CHANGELOG.md

actionpack/CHANGELOG.md


Remove hashing from secure_compare and clarify documentation

activesupport/lib/active_support/security_utils.rbの修正です.

secure_compareメソッドでfixed_length_secure_compareを呼び出す際にハッシュ化していたのを削除しています。

ハッシュ化だと文字列の内容の推測を防ぐ事は出来るが文字列の長さの推測を防ぐ事が出来ず(ハッシュ化の実行が文字列の長さに依存する為)ハッシュ化してもセキュリティ上のメリットが無いため、代わりに長さでのチェックを行うようにした、との事です。


Add a separator to the cache key for ActiveSupport::CachingKeyGenerator

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

ActiveSupport::CachingKeyGeneratorのcache keyにセパレータを追加するよう修正しています。

このcache keyはsaltとkey lengthを単純に連結している為、例えば、@caching_generator.generate_key("133", 7)@caching_generator.generate_key("13", 37)で同じkey(1337)が生成されてしまっていまい、後者の場合に想定通りのkey lengthにならない、という問題がありました。で、これを避ける為に、saltとkey lengthの間にセパレータを追加し対応しています。


Style fix for CachingKeyGenerator

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

rubocopの設定に違反している箇所があったのを修正しています


Inspect time attributes with subsec

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

Active Recordのtime attributesのinspect結果にsubsecの値も含むよう修正しています。


Fix flakey destroyed_by_association tests

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

destroyed_by_associationテストで想定外のデータが削除されてしまうのを避ける為に、明示的にfixtureで必要なデータをロードするよう修正しています。


Remove obsolete explain logging test

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

既に削除済みのauto-explainの為のテストが残っていたのを削除しています。


Include parallelize :threads option when fork is not available

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

rails newで生成されるtest_helper.rbに、forkが使えない環境ではparallelizeにスレッドオプションを指定するよう修正しています。


Fix rewhere to truly overwrite collided where clause by new where clause

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

rewhereで指定したconditionで元のwhereのconditionが正しくオーバーライトされないケースがあったのを修正しています。


Merge pull request #39051 from kamipo/more_concise_or_ast

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

orを1000回呼び出すと、"Stack level too deep"が発生してしまうバグがあったのを修正しています。


Merge pull request #39022 from kamipo/perf_where_in

Active Recordの修正です。

wherevalueのArrayを指定した場合にオブジェクトの生成数を減らせるようリファクタリングしています。


Remove deprecated ActionMailer::Base.receive in favor of Action Mailbox

Action Mailerの修正です。

deprecateになっていたActionMailer::Base.receiveメソッドを削除しています。


Remove deprecated ActionMailer::DeliveryJob and ActionMailer::Parameterized::DeliveryJob

Action Mailerの修正です。

deprecateになっていたActionMailer::DeliveryJobActionMailer::Parameterized::DeliveryJobを削除しています。


Remove deprecated force_ssl at the controller level.

Action Packの修正です。

deprecateになっていたcontrollerレベルでのforce_sslを削除しています。


Remove unneeded test after force_ssl removal

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

先程削除したcontrollerレベルでのforce_sslに関するテストが残っていたのを削除しています。


Deprecate starts_with? and ends_with? for String core extensions

Active Supportの修正です。

String#starts_with?及びString#ends_with?メソッドをdeprecateにしています。

Ruby本体に同等のメソッド(start_with? / end_with?)がある、かつ、starts_with? / ends_with?を使用するとSymbol#start_with? / Symbol#end_with?がある事のメリットをうけられない、という理由によりdeprecateになりました。

が、merge後にちょっと議論が発生し、String#starts_with?及びString#ends_with?はそのままとなる事になりました。


save and save! doesn't take positional arguments

Active Recordの修正です。

savesave!メソッドのシグネチャが、positional引数とkeyword引数両方を受け取れるようになっていたのですが、savesave!はpositional引数はそもそも受け取られない為、不要なシグネチャを削除しています。


Relax required rack-mini-profiler version 2.0.x to 2.x

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

rails newで生成されるGemfileで、rack-mini-profilerのバージョン指定が~> 2.0.0になっていたのを、~> 2.0に修正しています。


Follow up to #38953 [ci skip]

rails guideの修正です。

config.load_defaultsに指定する値がStringになっていたのを、rails newで実際に生成される内容に合わせてFloatを使用するよう修正しています。


Follow up to 3f27aa8cdf8c3c7f36d630f0241854f712e4c937

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

キーワード引数を受け取れないsave_block_result_to_cacheメソッドのシグネチャ**が指定されていたのを削除しています。


Type::Value#initialize doesn't take positional arguments

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

Type::Value#initializeメソッドのシグネチャが、positional引数とkeyword引数両方を受け取れるようになっていたのですが、positional引数は受け取られない為不要なシグネチャを削除しています。


Avoid synchronize { } call only for MRI

actionpack/lib/action_dispatch/http/response.rbactiverecord/lib/active_record/connection_adapters/abstract/connection_pool.rbの修正です。

変数参照時にsynchronizeを使用するかどうかのチェックを、JRUBY_VERSIONが定義されているかどうかでチェックしていたのを、MRIの場合のみsynchronizeを使用しないよう修正しています。


Use the file_fixture_path for fixture_file_upload:

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

fixture_file_uploadメソッドがファイルを検索するのに、fixture_path相対パスで検索していたのがdeprecateになりました。今後はfile_fixture_path相対パスで検索されるようになります。

fixture_pathはActive Recordの為の値であり、file_fixture_pathがある今Action Packでfixture_pathを使うのは良くないのでは、という事でdeprecateになりました。


Revert "Merge pull request #39152 from kamipo/deprecate_starts_ends_with"

String#starts_with?及びString#ends_with?メソッドをdeprecateにした、Deprecate starts_with? and ends_with? for String core extensionsをRevertしています。