なるようになるブログ

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

rails commit log流し読み(2018/06/13)

2018/06/13分のコミットです。

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

activerecord/CHANGELOG.md


Add ability to configure cache notifications info

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

cache notificationsのpayloadをメソッド内で固定で保持していたのを、値をメソッドに切り出して、アプリ側で任意の値を追加出来るようにしています。

GitHubでは接続先のhostとurlをpayloadに追加するようにしているとの事です。


Update "Active Support Core Extensions" Guide

rails guideのActive Support Core Extensionsの修正です。

Date, Time, DateTimeに定義されているメソッドについて説明している箇所で、メソッドが定義されているファイルにいての説明に誤りがあったのを修正しています。


Merge pull request #29373 from untidy-hair/store_accessor_enhance

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

ActiveRecord::Store.store_accessorに任意のsuffixを指定出来るsuffxオプションを追加しています。suffixオプションには任意のsuffix(String又はSymbolで指定)、または、trueが指定出来るようになっています。trueを指定した場合はattribute + accessorでアクセス出来るようになります。

Merge pull request #32306 from danhuynhdev/feature/store-accessor-prefixので、prefixは指定出来るように既になっていた為、これでprefix / suffix両方指定出来るようになっています。

rails commit log流し読み(2018/06/12)

2018/06/12分のコミットです。

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


Merge pull request #29939 from arthurchui/activerecord-delete-associations-loop

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

CollectionAssociation#remove_recordsメソッドでtargetから既にあるassociationを削除する際に、Array#deleteを使用していたのを、Hash#select!を使用するよう修正しています。

Hashの方が高速(Arrayだと計算量がO(N2)だけど、HashだとO(N))な為。が、これについては次のコミットで別な形で再度修正されています。


Use -= to change the update the collection on the association

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

CollectionAssociation#remove_recordsメソッドでtargetから既にあるassociationを削除するのに-=を使用するよう修正しています。

target=メソッドを使用すると、associationがload済みになり、次にreaderにアクセスする際にqueryの実行が抑止出来る為。が、これはこれで別の問題があった為、また次のコミットで修正されています。


Don't use target=

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

associationを削除するのにtarget=メソッドを使用せず、@targetを直接更新するよう修正しています。

ここでassociationをload済みにしてしまうと、オブジェクトが古い状態のままになってしまう場合がある為。


Merge pull request #32997 from utilum/dev_dep_guide_update_ast_requirements

Development Dependencies Install guideに Active Storageのテストで必要なパッケージ(ffmpegmupdf等)のインストール方法についての説明を追加しています。


Merge pull request #33092 from utilum/warnings_in_contribute_guide

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

Warningsの項でRUBYOPT=-W0を指定するとwarningが表示されなくなる旨説明が記載されていたのですが、実際はその挙動にならない(warningは表示される)為、該当の説明を削除しています。


Merge pull request #33106 from marcandre/datecalc

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

DateAndTime::Calculations moduleで曜日の管理をするのに、月曜が0になっていたのを、日曜が0になるよう修正しています。

曜日を計算するのにwdayから1引いてから計算する(Rubyのwdayは日曜が0ので、各メソッドでcurrent_day_number = wday != 0 ? wday - 1 : 6というのを最初にやっていた)という不要な処理を削除する為。


Fix bug with eager_load in development environment

actionpack/lib/action_dispatch/journey/routes.rbの修正です。

eager_loadをdevelopmentでtrueにしている、かつ、Routeが空の場合にArgumentErrorが発生してしまうバグがあったのを修正しています。


Remove backticks around proejct names

rails guideのActive Storage OverviewDevelopment Dependencies Installの修正です。

XQuartzやPoppler等のプロジェクト名をバッククォートで囲まないよう修正しています。


Fix active_model/errors docs [ci skip]

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

ActiveModel::Errors#full_messageメソッドのdocから不要なインデントを削除しています。


Add changelog for #32956 [ci skip]

activemodel/CHANGELOG.mdの修正です。

ActiveModel::Errors#full_messageメソッドで出力するエラーメッセージのフォーマットを変更出来るよう対応した、Allow to override the full_message error formatについてCHANGELOGにエントリーを追加しています。


Add comma to example in guides/source/active_storage_overview.md [ci skip]

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

Attaching File/IO Objectsの項にあるexampleコードでカンマが不足していたのを修正しています。


Remove reference to session_store.rb initializer

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

既に存在しないinitializer(config/initializers/session_store.rb)に言及している箇所があったのを削除しています。

rails commit log流し読み(2018/06/11)

2018/06/11分のコミットです。

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


Fix alias confliction when joining same table on has many through with left_joins

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

has many through + left_joinsで同じテーブルをjoinした場合に、そのテーブルに同じaliasが使われてしまい、結果エラーになるSQLが生成されてしまうバグがあったのを修正しています。


Merge pull request #33093 from rails/use-rack-to-dump-query

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

ActionController::TestRequestクラスでqueryを生成するのにHash#to_queryメソッドを使用していたのを、Rack::Utils.build_nested_queryを使用するよう修正しています。

Hash#to_queryはメソッド内で値をソートしてしまっており、結果、送信したparamsと生成されれる内容が一致しない、という問題があった為、Rack::Utils.build_nested_queryを使用するようにしています。


Merge pull request #32956 from Shopify/i18n_activemodel_errors_full_message

activemodel/lib/active_model/errors.rbactivemodel/lib/active_model/railtie.rbの修正です。

ActiveModel::Errors#full_messageメソッドで出力するエラーメッセージのフォーマットを変更出来るよう修正しています。

元々、:"errors.format"で上書き出来るようになっていましたが、これは全体に影響がある設定で、attribute個別の上書きは出来ませんでした。で、今回左記以外のkeyで、フォーマットの上書きが出来るようになっています。具体的には、

activemodel.errors.models.person/contacts/addresses.attributes.street.format
activemodel.errors.models.person/contacts/addresses.format
activemodel.errors.models.person.attributes.name.format
activemodel.errors.models.person.format

のように、model + attributes + format、又は、model + formatのkeyを追加で見るようになっています。

なお、このkeyは、config.active_model.i18n_full_messageにtrueを指定した場合にだけ見に行くようになっています。


Remove redundant accessors

actioncable/test/stubs/test_adapter.rbの修正です。

不要なsubscribe_called accessorを削除しています。

rails commit log流し読み(2018/06/10)

2018/06/10分のコミットです。

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


Update config.active_storage.variable_content_types default value in guides [ci skip]

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

config.active_storage.variable_content_typesのデフォルト値についての説明を最新の内容に更新しています。


:scissors:

activerecord/CHANGELOG.mdの修正です。

不要なスペースを削除しています。

rails commit log流し読み(2018/06/09)

2018/06/09分のコミットです。

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


Inherit all actioncable's test classes from ActionCable::TestCase

Action Cableのテストの修正です。

各テストクラスの親クラスにActiveSupport::TestCaseを指定している箇所テストがあったのを、ActionCable::TestCaseを使用するよう統一しています。


Include ActiveSupport::Testing::MethodCallAssertions to ActionCable::TestCase

Action Cableのテストの修正です。

テストクラス毎にActiveSupport::Testing::MethodCallAssertionsをincludeしていたのを、ActionCable::TestCaseでincludeするよう修正しています。


Remove extra include ActiveSupport::Testing::MethodCallAssertions

activesupport/test/testing/method_call_assertions_test.rbの修正です。

ActiveSupport::Testing::MethodCallAssertionsのincludeを削除しています。

テスト実行前にActiveSupport::TestCaseActiveSupport::Testing::MethodCallAssertionsをinclude済みの為。


Include ActiveSupport::Testing::MethodCallAssertions in railties/test/isolation/abstract_unit.rb

railtiesのテストの修正です。

ActiveSupport::TestCaseActiveSupport::Testing::MethodCallAssertionsをincludeするよう修正しています。


Merge pull request #27577 from maclover7/jm-fix-27547

actioncable/lib/action_cable/subscription_adapter/postgresql.rbの修正です。

Action CableでadapterにPostgreSQL adapterを使用している場合に、Active Recordで管理しているDBのconnectionをそのまま使いまわしていたのを、connectionを取得した際そのconnectionをAction Recordの管理から外し、Action Cable側で管理するよう修正しています。

Active Recordで管理しているconnectionをそのまま利用していると、Active Record側でconnectionを破棄した際に、Aciton Cable側のconnectionも予期せず破棄されてしまう為。


Merge pull request #33087 from bogdanvlviv/document-CompareWithRange

activesupport/lib/active_support/core_ext/range/compare_range.rbのdocの修正です。

CompareWithRange moduleで定義されているメソッド(===include?cover?)がAPI docに表示されるよう:nodoc:を削除しています。これらのメソッドは既にguideに記載されており、publicメソッドな為。


Avoid Node.js v10.4.0 for now

.travis.ymlの修正です。

rails-ujsのテストで使用するNode.jsのバージョンを10.3.0に固定しています。10.4.0だと何故かエラーになってしまう為。


Merge pull request #33078 from bogdanvlviv/add-remove-require

Active Supportの修正です。

不要なrequireの削除、及び、不足していたrequireの追加を行っています。

rails commit log流し読み(2018/06/08)

2018/06/08分のコミットです。

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


Refactor activestorage/test/models/attached_test.rb

activestorage/test/models/attached_test.rbの修正です。

attachmentテストのリファクタとして、使用していないActiveJob::TestHelperのincludeを削除、テストでUserクラスに追加したメソッドをテストの後処理で削除するよう修正、及び、remove_methodメソッドを呼び出すのにsendを使用していたのを、send無しで呼ぶよう修正しています。

が、remove_methodがpublicになってのはRuby 2.5からで、Ruby 2.4ではsendが必要な為、後ほどrevertされています。


Fix example of index_with

rails guideのActive Support Core Extensionsの修正です。

index_withメソッドのexampleで、レシーバーの指定が漏れていた箇所があったの、及び、不要な配列の指定があったのを修正しています。


Revert "Merge pull request #33085 from bogdanvlviv/refactor-attached_test.rb"

attachmentテストのリファクタを行った、Refactor activestorage/test/models/attached_test.rbをrevertしています。


Refactor activestorage/test/models/attached_test.rb

activestorage/test/models/attached_test.rbの修正です。

attachmentテストのリファクタのリトライです。remove_method以外の対応だけ行うようにしています。