なるようになるブログ

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

rails commit log流し読み(2019/07/26)

2019/07/26分のコミットです。

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md

activejob/CHANGELOG.md


Make sure AR can load without Rails

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

DatabaseTasks.for_eachメソッドの先頭でRailsが定義されているかどうかをチェックし、定義されていない場合は空のHashを返すよう修正しています。

メソッドの中でRails moduleの値を使用しており、Rails外でActive Recordを使用した場合にエラーになるのを避ける為。


Optimize DescendantsArray insertions

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

DescendantTracker::DescendantArray#<<でklassを追加する際に、参照先のオブジェクトが生きているかどうかをチェックし、GC済みのオブジェクトを除外していたのを、DescendantTracker::DescendantArray#eachで参照する際にGC済みのオブジェクトを除外するようにしています。処理高速化の為。


fix follow_redirect! not using the same HTTP verb on 307 redirection:

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

follow_redirect!でリダイレクトする際に、必ずGETリクエストになっていたのが、元のリクエストのHTTPメソッドを使用するよう修正しています。HTTP 1.1の仕様では、307リダイレクトはメソッドとボディは変更されないようになっている為。


Merge pull request #36758 from jturkel/feature/hash-optimization

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

HashWithIndifferentAccess#convert_valueメソッドのoptions引数のデフォルト値をfreezeするよう修正しています。


Merge pull request #36412 from robotdana/compact_blank

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

ActionController::Parameterscompact_blank、及び、compact_blank!メソッドを追加しています。それぞれreject(&:blank?)reject!(&:blank?)のショートハンド。


Merge pull request #36318 from itsWill/fix_event_object_payload

activesupport/lib/active_support/notifications/fanout.rbactivesupport/lib/active_support/notifications/instrumenter.rbの修正です。

ActiveSupport::Notifications.instrumentに指定したblock内でpayloadを変更した際に、その変更内容をActiveSupport::Notifications.subscribeで参照出来るよう修正しています。


read configuration to determine excluded eager loaded directory (#36354)

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

eager loadの対象から除外されるディレクトリがassetsjavascriptに固定になっていたのを、assets + webpacker.ymlsource_pathに指定されているディレクトリを除外するよう修正しています。source_pathをカスタマイズしている場合に正しく除外されるようにする為。


let autoloaded? support modules with overridden names [closes #36757]

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

nameを上書きしているmoduleについてもautoloaded?で正しくチェック出来るよう修正しています。


Use connection.error_number in MySQLDatabaseTasks

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

DBが作成済みかどうかをチェックする際に、mysql2 adapterが提供しているerror_numberを使用していたのを、connectionのerror_numberメソッドを使用するよう修正しています。mysql2以外のadapterでも動作するようにする為。


Merge pull request #36380 from edudepetris/ed/36272-better-negative-scope-warning

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

enumnot_ではじめる名前を使っている場合に、デフォルトで生成されるnegative scopeと名前がコンフリクトする旨メッセージを表示するよう修正しています。


Use binding.local_variable_get for :for

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

HashWithIndifferentAccess#convert_valueメソッドの引数の指定にキーワード引数を指定 + binding.local_variable_getを使用するようにして、そもそもoptions引数を削除するようリファクタリングしています。


Fixup 64a430129f

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

先のリファクタリングで修正漏れがあったのを対応しています。


Merge pull request #36731 from jhawthorn/dir_glob_base_instead_of_chdir

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

Paths#files_inメソッドで、Dir.chdirでpathを変更してからDir.globを実行していたのを、Dir.globbaseオプションにpathを指定するようにして、Dir.chdirの呼び出しをを削除するようリファクタリングしています。


Only merge DATABASE_URL settings into the current env

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

DATABASE_URLを指定していた場合、現在のenv以外だけでなく全てのenvにその指定した値が影響してしまうバグがあったのを修正しています。


Merge pull request #36747 from y-yagi/add_mention_about_collection_cache_versioning

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

デフォルトで生成されるnew_framework_defaults_6_0.rbRails.application.config.active_record.collection_cache_versioningについての説明を追加しています。


Merge pull request #36765 from kylekeesling/patch-1

actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rbの修正です。

develiomentで検証用にinbound mailを作成する際に、添付ファイルのファイル名が保持されてなかったのを保持するよう修正しています。


Merge pull request #36767 from vlado/active_job_test_helper_can_now_handle_relative_at_options

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

assert_enqueued_withassert_enqueued_withメソッドのatオプションに相対時間(e.g. at: 5.minutes.from_now))を指定した場合に、microsecondsの値を0にするよう修正しています。

assertionとjob呼び出しの間にmicrosecondsが変わってしまい、その影響でassertionが失敗するのを避ける為。


Merge pull request #36576 from mtsmfm/mtsmfm/fix-fixture-resolver

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

ActionView::FixtureResolver:any variantsのサポートを追加しています。


Correct assertion argument order

actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rbの修正です。

添付ファイル名をチェックするテストで、assert_equalメソッドの引数が逆(actual、expectedの順になっていた)になっていたのを修正しています。


Fix flaky test ActionControllerBaseRenderTest#test_direct_render_to_string

actionpack/test/controller/render_test.rbの修正です。

modify_templateで使用するテンプレートと、通常テストで使用するテンプレートが別になるよう修正しています。modify_templateではテンプレートの内容を変更しており、同じテンプレートを参照するとタイミングによってはテストが失敗してしまう為(期待している結果とテンプレートの内容が変わってしまっている為)。


Merge pull request #36005 from shioyama/plain_matcher_first

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

attribute methodを検索する際に、prefixとsuffixの指定の無いplain matcherを最後に取得するようにして(優先度を下げる為)いたのを、最初に取得するよう修正しています。現状の実装では、plain matcherを最後に使用する必要は無いだろう、とのことです。


Use correct variable in secure_compare!

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

ActiveSupport::SecureCompareRotator#secure_compare!メソッドで参照するインスタンス変数をタイポしていたのを修正しています。


Merge pull request #36180 from jonathanhefner/optimize-string-from

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

String#fromString#toメソッドで不要なRangeオブジェクトが生成されないようリファクタリングしています。


Merge pull request #35334 from sharang-d/digest-doc-update

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

ActionView::Digestor.digestメソッドのdocに説明が不足していたformat引数についての説明を追加しています。


Merge pull request #36300 from okuramasafumi/make-handle-options-private

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

内部でだけ使用するCookieJar#handle_optionsメソッドの可視性をprivateに変更しています。


[ci skip] add CSRF token explanation for javascript documentation

rails guideのWorking with JavaScript in Railsの修正です。

CSRF tokenを独自に作成したAJAXリクエストで送信する方法について説明した、Cross-Site Request Forgery (CSRF) token in Ajaxの項を追加しています。


Add a default value for arg format in ActionView::Digestor.digest()

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

ActionView::Digestor.digestformat引数のデフォルト値にnilを指定するよう修正しています。5.2まではformatオプションは無く、下位互換の為デフォルト値を指定するようにしています。


Fix join middle table alias when using HABTM

activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rbの修正です。

HABTMの結合に使用するmiddle tableのaliasをjoinした場合に、エラーになってしまうバグがあったのを修正しています。


Prettify diff generated by git for encripted file:

railtiesの修正です。

credentialsの編集内容をgit diff / git logで見れるよう対応しています。

例。

diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc
index 2475c8c..53bba7c 100644
--- a/config/credentials.yml.enc
+++ b/config/credentials.yml.enc
@@ -1,6 +1,6 @@
-# aws:
-#   access_key_id: 123
-#   secret_access_key: 345
+aws:
+  access_key_id: 123
+  secret_access_key: 345

表示には.gitattributesを使用しており、git configdiff.rails_credentials.textconv 'bin/rails credentials:show'を設定 + .gitattributesにdiff内容を保存、という形で対応してます。

そのため、.gitattributesgit configの設定が必要です。credentials:edit実行時にその設定を行うかどうかのプロンプトが表示されるので、そのプロンプトをOKした場合それらの設定が行われるようになっています。


Removed webpacker:compile step from scaffold test as it is not required and assets are already precompiled in build_app step

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

scaffoldのテスト内で行っていたwebpacker:compileを削除しています。テスト用アプリ構築時にcompileを行うようになっており、このタイミングでは不要な為。