なるようになるブログ

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

rails commit log流し読み(2017/11/12)

2017/11/12分のコミットです。

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


Remove unused require

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

使用していないactive_support/core_ext/string/strip及びactive_support/core_ext/module/delegationのrequireを削除しています。


Merge pull request #30770 from y-yagi/do_not_create_credential_in_dummy_application

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

dummy applicationではcredentialsを作成しないよう修正しています。credentialsはproduction環境で使用する事を今は想定しており、テストでしか使用しないdummy applicationには不要な為。

rails commit log流し読み(2017/11/11)

2017/11/11分のコミットです。

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


Relation merging should keep joining order

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

複数joinを行った場合に、そのjoinの順序が保持されていなかったのを保持するよう修正しています。joinの順番に意味がある(scopeのmergeの順に意味がある場合等)場合がある為。


Add missing autoload Type (#31123)

Active Modelの修正です。

autoloadの対象にType moduleを追加しています。

Attribute modules (Attribute, Attributes, AttributeSet)はTypeを使用しており、かつ、左記moduleはautoloadされるのですが、左記moduleがautoloadされて使用される状態になってもType moduleがloadされてない事がある為、それを避ける為にTypeもautoloadされるよう対応したようです。


Should test actual error which is raised from the database

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

ER_LOCK_WAIT_TIMEOUTが発生した場合にActiveRecord::TransactionTimeoutがraiseされる事を確認するテストで、SIGNAL 構文を使ってエラーを起こしていたのを、実際にtimeoutが発生する状態を作成しテストをするようにしています。


Raise TransactionTimeout when lock wait timeout exceeded for PG adapter

Active Recordの修正です。

Merge pull request #30360 from gcourtemanche/transaction_timedoutで、ロック待機のタイムアウトの期限が切れた場合にTransactionTimeoutクラスをraiseする対応をMySQL adapterに行ったのですが、同様の対応をPostgresSQL adapterにも行っています。

rails commit log流し読み(2017/11/10)

2017/11/10分のコミットです。

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

actionview/CHANGELOG.md


Fix field_error_proc wrap form select optgroup and divider option tag

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

formでエラーが発生した際に、field_error_procoptgroupタグやseletctタグ内のoptionタグもfield_with_errorsクラスでラップしていたのを、ラップしないよう修正しています。

<select name="post[category]" id="post_category">
  <option value="">Please select</option>
  <div class="field_with_errors">  <!-- ここ -->
    <optgroup label="A">
      <option value="A1">A1</option>
      <option value="A2">A2</option>
    </optgroup>
  </div>
</select>
<select id="post_time_zone" name="post[time_zone]">
  <option value=""></option>
  <option value="Hawaii">(GMT-10:00) Hawaii</option>
  <div class="field_with_errors">  <!-- ここ -->
    <option value="" disabled="disabled">-------------</option>
  </div>
</select>

元々は上記のようはhtmlが生成されていたのですが、selectタグの中にdivを書くのはhtmlの規約的にNGなので、上記ケースではfield_with_errorsを生成しないようにしています。


Merge pull request #31099 from nobu/patch-1

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

cache用のtmpディレクトリを作成するのにDir::Tmpname.make_tmpnameを使用していたのを、Dir.mktmpdirを使用するよう修正しています。

Dir::Tmpname.make_tmpnameは内部用メソッドで、一意性は保証されておらず使用すべきでは無いため、とのことです。


Move Attribute and AttributeSet to ActiveModel

Active Modelの修正です。

Active Record配下にあったAttributeクラス及びAttributeSetクラスをActive Modelに移動しています。

Active Record内にあるattributes APIをActive Modelに移動する対応の一環。


Merge pull request #25346 from bogdan/correct-tags-count-in-fixtures

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

fixturesにcounter cacheの値が正しく指定されていなかったのを修正しています。


Merge pull request #30414 from bogdanvlviv/clear-mysql_database_tasks

Active Recordの修正です。

MySQL用のdatabase作成処理で、Access denied エラーがおきたときに、rootアカウントで再度処理を行う、という処理があったのをまとめて削除しています。

その処理の影響でAccess denied以外のエラーがおきた時にエラーメッセージが見づらくなってしまっていた為と、そもそも余計な事をせずエラーメッセージをそのまま表示した方が良いのでは、という事で削除されたようです。


Merge pull request #31027 from PHedkvist/inflector_test_type

activesupport/test/core_ext/string_ext_test.rbactivesupport/test/inflector_test_cases.rbの修正です。

parameterizeのテストでPreservePreserceにタイポしていたのを修正しています。


Bump RuboCop to 0.51.0

RuboCopのバージョンを0.51.0に更新、及び、copに違反している箇所があったのをまとめて修正しています。


Use -e option to specify the environment in console command [ci skip]

rails guideのThe Rails Command LineConfiguring Rails Applicationsの修正です。

rails consoleコマンドにenvを指定する際に、-eオプションを指定するよう修正しています。

-eオプションを使用しないenvの指定は、Deprecate environment as an argument for dbconsole and consoleでdeprecateになった為。


Add missing requires

activemodel/lib/active_model/attribute.rbactivemodel/test/cases/attribute_set_test.rbの修正です。

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


Remove unused require

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

不要なactive_support/core_ext/kernel/reportingのrequireを削除しています。


Merge pull request #31114 from y-yagi/fix_ruby_warnings_in_active_model

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

Active ModelでRubyのwarnings("warning: instance variable @attributes not initialized"、及び、"warning: assigned but unused variable - name")が出ている箇所があったのを修正しています。


Use new RDoc URL of Ruby core [ci skip]

rails guideのAPI Documentation Guidelinesの修正です。

RDocのURLを正しいURLに修正しています。

-[RDoc](http://docs.seattlerb.org/rdoc/). To generate it, make sure you are
+[RDoc](https://ruby.github.io/rdoc/). To generate it, make sure you are

RDocはruby core配下で管理されてるので、ruby.github.ioが正しいURLなんですねえ。


Use new Rake URL of Ruby core [ci skip]

actionview/RUNNING_UNIT_TESTS.rdocの修正です。

RakeのURLを正しいURLに修正しています。

-Rake can be found at http://docs.seattlerb.org/rake/.
+Rake can be found at https://ruby.github.io/rake/.

こちらも同様にruby.github.io配下。


Remove useless preloader classes

Active Recordの修正です。

ActiveRecord::Associations::Preloader配下の不要なクラス(重複していた実装があった or そもそも実装が無かった)をまとめて削除しています。


Add missing requires

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

不足していたactive_model/typeのrequireを追加しています。


Merge pull request #31065 from bogdan/cleanup-cache-key

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

Cache::Store#expanded_keyメソッドとCache.expanded_keyメソッドの実装が重複していたので、Store#expanded_keyメソッドを削除しCache.expanded_keyの方を使い回すよう修正しています。


Adjust blank lines

railtiesの修正です。

rails newで生成されるGemfile、gitignore、environmentsファイル内のコード間の空行の調整を行っています。


:scissors:

activesupport/CHANGELOG.mdの修正です。

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


Ensure apply_join_dependency for subqueries in from and where

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

PredicateBuilder::RelationHandler#callメソッド、及び、QueryMethods#build_fromメソッドでeager loadを使用している場合に、apply_join_dependencyメソッドを呼び出すよう修正しています。

fromメソッド、及び、whereメソッド内でsubquery + eager loadを使用した場合に正しいSQLを生成出来るようにするため、のようです。


Consolidate duplicated to_ary/to_a definitions in Relation and CollectionProxy

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

RelationCollectionProxyそれぞれに定義されていた同じ値を返すto_ary / to_aメソッドの定義をRelation側にマージしています。


Fix random CI failure due to non-deterministic sorting order

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

test_finding_with_subquery_with_eager_loading_in_whereでassociationを取得する際に、idでsortするよう修正しています。

sortしないと結果が不定になり、seedによってはテストが失敗してしまう為。


Add missing require "active_support/core_ext/hash/indifferent_access"

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

不足していたactive_support/core_ext/hash/indifferent_accessのrequireを追加しています。

rails commit log流し読み(2017/11/09)

2017/11/09分のコミットです。

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

activesupport/CHANGELOG.md


Consolidate redundant if and unless with the same condition

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

同じ条件でunlessifがそれぞれ使われていたのを、if / elseにマージしています。


Mysql2Adapter should pass ConcurrentTransactionTest

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

ConcurrentTransactionTestがMysql2Adapterでも実行されるよう修正しています。


Remove redundant passing --skip-active-storage in test cases

railtiesのテストの修正です。

Do not run active_storage:install when bundle install is skippedの対応により不要になった、テスト内で--skip-active-storageを指定したのを削除しています。


Change output log about skipping instalation of Active Storage

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

Active Storageのインストール処理をスキップした場合(bundle installが実行されなかった場合)のメッセージ内のコマンド表示のエスケープに"'"を使用していたのを、"`"を使用するよう修正しています。


Run ConcurrentTransactionTest if supports_transaction_isolation?

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

ConcurrentTransactionTestを実行するかどうかの判定を、supports_transaction_isolation?メソッドを使用して行うよう修正しています。

Oracle enhanced adapterでも上記テストを実行出来るようにする為。


Correctly kill the server started with ujs test

actionview/Rakefileの修正です。

rails-ujsのテストで、テストで起動したserverを正しくkill出来ていなかったのを修正しています。


Merge pull request #31078 from aeroastro/feature/fix-typo

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

ActionDispatch::HTTP::FilterParameters moduleのdocのグラマーの修正を行っています。


Merge pull request #31077 from gsamokovarov/assert-changes-nil

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

assert_changesassert_no_changesメソッドでassertionにassert_equalassert_nilを使用していたのを、assertを使用するよう修正しています。

-        if before.nil?
-          assert_nil after, error
-        else
-          assert_equal before, after, error
-        end
+        assert before == after, error

Minitest 5.10からassert_equalのexpected引数にnilを指定するのがdeprecateになった為、それを避ける為に、resolve minitest 6 deprecation in assert_no_changesassert_nilを使用するようにしたのですが、他にも同様の問題が発生する可能性があるため、単純にassertを使うように変更したようです。


Should pass test_no_locks_no_wait not only on PostgreSQLAdapter and OracleAdapter

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

test_no_locks_no_waitのテストをPostgreSQLAdapter、OracleAdapterでのみ実行されるようになっていたのを、すべてのadapterで実行されるよう修正しています。


Do not show credentials in generators help

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

rails generatorsのhelpにcredentialsが表示されないよう修正しています。

credentials generatorはcredentialsコマンド(credentials:edit)経由で実行される事を想定しており、generatorを直接実行する事は無い為。


Merge pull request #31081 from rails/allow-include-time-with-zone-range

Active Supportの修正です。

Range#include?ActiveSupport::TimeWithZoneインスタンスを指定出来るよう修正しています。

# before
(1.hour.ago..1.hour.from_now).include?(Time.current)
# => TypeError: can't iterate from ActiveSupport::TimeWithZone

# after
(1.hour.ago..1.hour.from_now).include?(Time.current)
# => true

Ruby 2.3から、Rangeの始点/終点ににTimeオブジェクトを指定出来るようになっており、それならばTimeWithZoneも指定出来ても良いだろう、という事で対応されたようです。

参考:Bug #11113: Time ranges cannot be used in case statements in 1.9+ but they could in 1.8.7

rails commit log流し読み(2017/11/08)

2017/11/08分のコミットです。

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


Do not run active_storage:install when bundle install is skipped

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

bundle installがスキップされた場合、active_storage:installタスクを実行しないよう修正しています。

active_storage:installrailsコマンドを使用して実行されるのですが、bundle installが実行されていない場合railsコマンドは失敗してしまう(可能性がある)為。


Remove unnecessary migration deletion

railtiesのテストの修正です。

テストの各箇所でdb/migrateを削除していたのを、削除しないよう修正しています。

active_storage:installタスクでインストールされたmigrationファイルを削除する為に上記処理を行っていたのですが、先のコミットの影響でテスト中ではactive_storage:installタスクが実行されなくなり、migrationファイルの削除処理が不要になった為。


Fix output of select_tag with include_blank: true [ci skip]

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

select_tagメソッドのdoc内、include_blank: trueを指定した場合のexampleにlabel属性を追加しています。

Add empty label to empty options taglabel属性も強制的に出力するよう挙動が変更になった為。


Use released redis-namespace instead of master version

Gemfileの修正です。

redis-namespaceを使用するのにGitHubのmaterブランチを直接指定していたのを、リリース済みのgemを使用するよう修正しています。


Don't expose internal methods in Preloader::ThroughAssociation

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

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


Don't expose accessors which are internal used only

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

内部でだけで使用する accessorsの可視性をprotectedに変更しています。

rails commit log流し読み(2017/11/07)

2017/11/07分のコミットです。

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

actionpack/CHANGELOG.md

railties/CHANGELOG.md

activemodel/CHANGELOG.md

activerecord/CHANGELOG.md


Refactor Preloader Code

Active Recordの修正です。

though assocationsのpreload処理のリファクタとして、不要なデータ構造やメソッドの削除、アルゴリズムの改善、等を行っています。


Resolve Minitest 6 deprecation in assert_no_changes

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

assert_no_changesメソッドでbeforenilだった場合、assertionにassert_equalではなくassert_nilを使用するよう修正しています。

Minitest 5.10からassert_equalのexpected引数にnilを指定するのがdeprecateになった為。


Properly check transaction in persistence

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

TransactionManager#within_new_transactionメソッドの後処理でcommit_transactionメソッドを呼び出す際に、transactionnilじゃないかどうかチェックするよう修正しています。


Merge pull request #22435 from yui-knk/fix_engine_route_test

Action Packの修正です。

assert_recognizesがmounted engineのpathを扱えないバグがあったのを修正しています。


Merge pull request #30101 from bogdanvlviv/initialization-active_storage

railtiesの修正です。

rails newを実行時に、自動でActive Storageの初期化処理(active_storage:install)を実行するよう修正しています。

合わせて、Active Storageをインストールしないようにする為の--skip-active-storageオプションを追加しています。なお、Active StorageはActive Recordに依存している為、--skip-active-recordを指定した場合、自動でActive Storageもskipするようになっています。


Fix merge conflict and rubocop offences

actionpack/test/dispatch/routing_assertions_test.rbの修正です。

merge conflictがそのままになっていたのを修正、及び、rubocopのルールに違反している箇所があったのを修正していまs.


Merge pull request #31058 from bogdanvlviv/ConfirmationValidator-with_false_value

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

ConfirmationValidator_confirmationにfalseが指定された場合、validationを実行するよう修正しています。

元は実行されていなかったのですが、ドキュメント、nilじゃない場合にvalidationを実行する、と説明が記載されており、それに合わせる為。微妙に非互換な感が。


Remove useless associated_records_by_owner

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

Association#associated_records_by_ownerThroughAssociation#associated_records_by_ownerメソッドを削除しています。

元々はassociated_records_by_ownerは、assocationsのsubclassでカスタマイズした結果を取得するように使われていました。

しかし、Refactored preloading of a though assocations以降、そのような使われ方はされなくなり、ただassociate_records_to_ownerメソッドを呼び出すだけになってしまっていたので、余計なメソッド呼び出しを減らす為に削除したようです。


Fix streaming downloads from S3/Azure Storage

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

S3 / Azure storageを使用している場合に、streaming downloadが正しく動作しないバグがあったのを修正しています。


Merge pull request #30714 from bogdanvlviv/fix-rails_db_migrate_VERSION

Active Recordの修正です。

bin/rails db:migrateに空のVERSIONを指定した場合、VERSIONを指定しない場合と同じ挙動になるよう修正、及び、VERSIONに不正なフォーマットの値を指定した場合に、適切なエラーメッセージ("Invalid format of target version: VERSION=xxx")を表示するよう修正しています。


Merge pull request #31061 from bogdanvlviv/test-if-unless-options-for-validations

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

validation conditionsに複数の条件を指定した場合のテストを追加しています。


Merge pull request #30997 from q-centrix/nofollow-change

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

UrlHelper#add_method_to_attributesメソッドでrelオプションが指定されていない場合に、不要なStringオブジェクトが生成されないようリファクタリングしています。


Fix comment in check_class_collision [ci skip]

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

check_class_collisionメソッド内のコメントでmodule名を誤っている箇所があったのを修正しています。


Remove needless block parameter

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

Service::S3Service#streamメソッドから不要なブロック引数を削除しています。

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

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

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

activesupport/CHANGELOG.md


Ensure apply_join_dependency for collection_cache_key if eager-loading is needed

Active Recordの修正です。

ActiveRecord::CollectionCacheKey#collection_cache_keyメソッドで、eager loadを使用している場合、apply_join_dependencyメソッドを呼び出すよう修正しています。

eager loadしている場合にcollection cache keyを正しく生成出来るようにする為。


Ensure apply_join_dependency for update_all and delete_all if eager-loading is needed

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

update_alldelete_allメソッドでeager loadを使用している場合に、apply_join_dependencyメソッドを呼び出すよう修正しています。

eager loadしている場合に正しいSQLを生成出来るようにする為。


Fix preloading polymorphic association when through association has already loaded

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

has_many + through + polymorphicなassociationをpreloadを行う、かつ、既にthrough先のassociationがload済みだった場合に、source_typeが無視されてしまうバグがあったのを修正しています。


Fix preloading polymorphic multi-level through association

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

polymorphic + multi-levelのthrough associationをpreloadした際に、preloadが正しく行われないバグがあったのを修正しています。


scoping should respect current class and STI constraint (#29199)

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

Scoping::Named::ClassMethods#allメソッドでscopeを取得する際に、selfとcurrent scopeのclassが異なる場合に、relationを再作成するよう修正しています。

STIを使用している場合等で、selfとcurrent scopeのclassが異なる場合があり、そのような場合に正しい値を取得出来るようにする為、のようです。


Explicitly pass window handle to resize_window_to

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

SystemTesting::Driver#register_webkitメソッドでresize_window_toメソッドを呼び出す際に引数が不足していたのを修正しています。


Remove unused require

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

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


Merge pull request #30620 from bogdanvlviv/method_signature_prev-next-day-month-year_for_time

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

Timeクラスのprev_yearnext_yearprev_monthnext_monthprev_daynext_dayに引数(それぞれ年数、月数、日数)を渡せるよう修正しています。Dateクラスの各メソッドと同じ挙動です。


Merge pull request #31066 from Leyka/patch-1

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

parameterizeメソッドのdoc内のexampleコードのtréstrèsに修正しています。

trèsの方が正しい為とのことです。

参考:très — Wiktionnaire


Fix acronym support in humanize

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

humanizeメソッドでacronymに指定した設定が正しく使用されないバグがあったのを修正しています。

issueより。

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym "LAX"
  inflect.acronym "SFO"
end
# Before

"LAX ROUNDTRIP TO SFO".humanize
# => "Lax roundtrip to sfo"


# After
"LAX ROUNDTRIP TO SFO".humanize
# => "LAX roundtrip to SFO"

acronym inflectionsは小文字のkeyで管理されている為、大文字でkeyが指定された場合に正しくヒットしませんでした。値を取得する際にdowncaseを呼び出して必ず小文字にしてから取得するように対応しています。