なるようになるブログ

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

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

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

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

actionview/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #29349 from robertomiranda/responsive-images

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

image_tagメソッドにsrcset属性を指定する為のsrcsetオプションを追加しています

image_tag("icon.png", srcset: { "icon_2x.png" => "2x", "icon_4x.png" => "4x" })
# => <img src="/assets/icon.png" srcset="/assets/icon_2x.png 2x, /assets/icon_4x.png 4x">

image_tag("pic.jpg", srcset: [["pic_1024.jpg", "1024w"], ["pic_1980.jpg", "1980w"]], sizes: "100vw")
# => <img src="/assets/pic.jpg" srcset="/assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw">

参考:srcset属性について - Qiita


Merge pull request #29506 from pat/frozen-string-literals

Acitve Supportの修正です。

Frozen string literals指定してもエラーにならず動作するよう、Stringを変更する箇所でdupを呼び出すよう修正しています。


Merge pull request #29540 from kirs/rubocop-frozen-string

RubocopのStyle/FrozenStringLiteralCommentを有効にし、各ファイルの先頭にfrozen_string_literal: trueを追加しています。

が、テストが通らなくなってしまった為、revertされています。


Revert “Merge pull request #29540 from kirs/rubocop-frozen-string”

というわけで、直前のStyle/FrozenStringLiteralCommentの対応をrevertしています。


Avoid shadowed variable

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

ローカル変数と同名の変数を、ブロックパラメータで指定していた箇所があったので、別の変数名を使用するよう修正しています。


Deprecate and replace set_state method

ActiveRecord::ConnectionAdapters::TransactionState#set_stateメソッドがdeprecateになりました。

代わりに、明示的にstateを指定する為のrollback!commit!nullify!メソッドが追加されたので、stateを変更したい場合は左記メソッドを使う必要があります。

Transactionのstateを明示的に変更したいのって、どういう時なんだろう。


Apply record state based on parent transaction state

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

transactionをネストしている、かつ、親のtransactionでrollbackした際に、子のtransaction内のオブジェクトがpersistedされた状態とみなされていたのを、左記のような場合でもpersistedとみなされないよう修正しています。

Post.transaction do
  post_one.save # `post_one`の`persisted?`はfalseを返す

  Post.transaction(requires_new: true) do
    post_two.save # 元々は、`post_two`の`persisted?`がtrueを返してしまっていたのを、falseを返すよう修正
  end

  raise ActiveRecord::Rollback
end

Fix removed version 5.2 to 6.0 in the deprecation message

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

ActiveRecord::ConnectionAdapters::TransactionState#set_stateメソッドのdeprecate message内のメソッドを削除するRailsのバージョンが5.2になっていたのを6.0に修正しています。


Move test related to tmp:clear task to tmp_test.rb

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

tmp:clear タスクに関するテストをtest/application/rake/tmp_test.rbに移動しています。


Merge pull request #29566 from eugeneius/wrap_parameters_query

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

既に同じkeyがparamsにある場合は、wrap処理を行わないよう修正しています。


:warning: “Use assert_nil if expecting nil. This will fail in Minitest 6.”

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

assert_equalメソッドのexpected引数にnilを指定していたテストを、assert_nilを使用するよう修正しています。

Minitest 5.10から上記使い方がdeprecateになり、nilを期待する場合はassert_nilが使用する必要がある為。


Expectation first

Action ViewとAcitve Supportのテストの修正です。

assert_equalの引数の順番がおかしかった(expectedとactualが逆だった)テストを修正しています。

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

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

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

railties/CHANGELOG.md


Add CHANGELOG for #29630 [ci skip]

actionpack/CHANGELOG.mdの修正です。

先日コミットされた、ActionController::Parameters#to_sHash#to_sdelegateする対応について、CHANGELOGにエントリーを追加しています。


Delete stale comment for AR::Associations::Builder::CollectionAssociation

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

ActiveRecord::Associations::Builder::CollectionAssociationのdocに、has_manyhas_many_and_belongs_to_many associationsのclassがCollectionAssociationを継承している旨コメントがあったのですが、has_and_belongs_to_manyCollectionAssociationをもう継承していない為、コメントを削除しています。


Fix format of ActionController::Parameters#to_s doc [ci skip]

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

ActionController::Parameters#to_sメソッドのフォーマットが崩れていたのを修正しています。


Merge pull request #29629 from koic/fix_next_version_of_rails

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

Deprecation#initializedeprecation_horizon引数のデフォルト値を5.3から6.0に変更しています。5.2の次は6.0になる為。


Merge pull request #29536 from nickrivadeneira/fix-yaml

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

Active RecordのobjectをYAML.dumpしたデータををYAML.loadで戻した際に、元のattributeの値がfalseだった場合に、nilになってしまうバグがあったのを修正しています。


Merge pull request #28808 from fschwahn/fix-polymorphic-automic-inverse

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

polymorphic associationを使用している場合に、associationのbuildメソッドでインスタンスの生成が正しく行えないバグがあったのを修正しています。


Merge pull request #29644 from wilson/unify-route-helper-visibility

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

directメソッドで登録されたnamed helperを専用の変数(@custom_helpers)に登録していたのを、他のnamed helperと同じ変数に値を登録するように修正しています。

専用の変数に登録してしまうと、route_defined?等のメソッドで値を正しくチェック・取得が出来ない為との事です。


Merge pull request #29634 from kamipo/dont_cache_queries_for_schema_statements

Active Recordの修正です。

schema statementsでquery cacheを使用しないよう修正しています。

schema statementsの実行の際にquery cacheが使用されてしまう事により不安定なテストがある為、それを回避する為に対応したようです。


Merge pull request #29631 from kamipo/should_be_clear_association_ids

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

collection associationに新しいレコードを追加した際に、association_idsメソッドの値が更新されないバグがあったのを修正しています。


Add source code and changelog link to railties.gemspec

railties/railties.gemspecの修正です。

railtiesのgemspecに、metadataとしてsource_code_urichangelog_uriを設定しています。

Merge pull request #29588 from greysteil/add-gemspec-linksの対応漏れ。


Merge pull request #29534 from y-yagi/clear_screenshots_in_tmp_clear_task

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

tmp:clear taskがtmp/screenshotsディレクトリ配下のファイル(system testが生成するスクリーショットのファイル)を削除するよう修正しています。


SystemTestCase undef some IntegrationTest methods because it’s confused to use.

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

System Testでhttp verb method(getpost等)を使えないようにする為に、左記メソッドをundef_methodするよう修正しています。

System TestではCapybaraのAPIを使用する事が推奨されている為。

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

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

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

actionpack/CHANGELOG.md


Merge pull request #29623 from kamipo/should_use_same_connection_in_query_cache

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

query cacheを使用する際、LogSubscriberでも同じconnectionを使用するよう修正しています。


Merge pull request #29618 from diasjorge/patch-1

rails guideのLayouts and Rendering in Railsの修正です。

Rendering Textの項、exampleのextension名をタイポしていたのを修正しています。


[ci skip] run migration before looking at schema

rails guideのGetting Started with Railsの修正です。

Generating a Modelの項、db/schema.rbについて説明している箇所をmigration実行後に確認するよう説明を修正しています。


Add system tests to generate scaffold

railtiesの修正です。

system testのtemplateを生成する際、indexメソッド用のテストがしか生成されていなかったのを、createupdatedestroyについてのテストも生成するよう修正しています。


Fallback Parameters#to_s to Hash#to_s

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

ActionController::Parameters#to_sを呼び出した場合、Hash#to_sdelegateするよう修正しています。

FormTagHelperのメソッド(e.g. text_field_tag)にparamsを渡した場合に正しく値が表示されるようにする為、との事です。

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

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

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

activerecord/CHANGELOG.md


Merge pull request #29595 from fatkodima/result_lambda_class_checking

actionpack/lib/abstract_controller/callbacks.rbactivesupport/lib/active_support/callbacks.rbの修正です。

callback処理の中で引数がProcがどうかチェックしていたのを削除しています。渡される値は必ずProcであり、チェックが不要な為。


Merge pull request #29588 from greysteil/add-gemspec-links

コンポーネントのgemspecに、metadataとしてsource_code_urichangelog_uriを設定しています。

s.metadata = {
  "source_code_uri" => "https://github.com/rails/rails/tree/v#{version}/activemodel",
  "changelog_uri"   => "https://github.com/rails/rails/blob/v#{version}/activemodel/CHANGELOG.md"
}

こんなの書けるんですねえ。知らなかった。参考:Leverage metadata to populate gems urls v2 by kbrock · Pull Request #1234 · rubygems/rubygems.org

因みにPRを投げた方は、Dependabot - Automated Dependency UpdatesでPRを投げる際のリンクに使用する予定だそうです。


Merge pull request #29600 from kamipo/show_query_cache_keys

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

test_exceptional_middleware_clears_and_disables_cache_on_errorでテストに失敗した際にquery cacheのkeyを表示するよう修正しています。

test_exceptional_middleware_clears_and_disables_cache_on_errorは最近CI上でランダムでエラーになるようになっており、エラーになった際の調査の為に表示するようにしています。


Add a test case for unscoping default_scope in associations

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

associationのdefault_scopeをunscopeした場合のテストを追加しています。


Don’t passing klass.connection to AssociationScope

Active Recordの修正です。

Associations::AssociationScope.scope#scopeの引数からconnectionを削除しています。

上記メソッドは第一引数にassociationを渡しており、associationからconnectionを取得出来る為。


Enable query cache if set a configurations

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

DBへのconnectionがないと、ActiveRecord::Base.cacheを呼び出してもquery cacheが使用されなかったのを、connectionが無い状態でも接続先の情報があればquery cacheが使用されるよう修正しています。


Fix eager loading to respect store_full_sti_class setting

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

eager loadを行う際にstore_full_sti_classの設定内容が無視されていたのを、store_full_sti_classが設定されている場合も正しいtypeをloadするよう修正しています。


Fix grammar for documentation of rails/command.rb [ci skip]

rails guideのThe Rails Initialization Processの修正です。

rails/command.rbの項のグラマーの修正を行っています。


Show query cache keys in test_middleware_caches

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

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

test_middleware_cachesでテストに失敗した際にquery cacheのkeyを表示するよう修正しています。

先ほどのtest_exceptional_middleware_clears_and_disables_cache_on_errorと同様に、ランダムでテストがエラーになってしまう為、調査用。


Remove delegating to arel in a relation

Active Recordの修正です。

Relationで一部処理をarelにdelegateしていたのを、delegateしないよう修正しています。

delegateが必要なのはrelation.bound_attributesを使用する場合だけで、その場合は直接relation.arelを呼ぶようににして対応しています。


Merge pull request #28928 from kamipo/remove_habtm_initialize

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

不要なHasAndBelongsToManyReflection#initializeメソッドを削除しています。


Merge pull request #29076 from kamipo/use_timestamp_attributes_for_update_in_model

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

Timestamp#max_updated_column_timestampメソッドのtimestamp_namesのデフォルト引数を取得するのにtimestamp_attributes_for_updateを使用していたのを、timestamp_attributes_for_update_in_modelメソッド経由で値を取得するよう修正しています。


Merge pull request #29416 from kamipo/remove_unused_subject_model

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

使用していないSubject modelを削除しています。


Merge pull request #29301 from kamipo/receiver_in_scope_should_be_relation

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

Scoping::Named#scopeメソッドでinstance_execを実行するレシーバーがklassになっていたのを、relationになるよう修正しています。

default_scopeやassociationのscope処理ではレシーバーがrelationになっており、合わせる為に、との事です。


Merge pull request #29129 from kamipo/prevent_extra_through_scope

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

reset_associationメソッド内でthrough_scopeを呼び出していたのを、reset_associationの引数にthrough_scopeを渡すようにして、不要な呼び出しを行わないよう修正しています。


Merge pull request #29612 from kamipo/use_quote_method_rather_than_single_quote

Active Recordの修正です。

カラムやテーブルのクォート処理に'を指定している箇所があったのを、quoteメソッドを使用するよう修正しています。


Merge pull request #28932 from kamipo/remove_method_missing_in_relation_delegation

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

呼び出される事の無いRelation::Delegationmethod_missingを削除しています。


Merge pull request #29569 from kamipo/fix_to_scoping_is_correctly_restored

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

STI subclassが、parent classのunscoped blockの中でunscopedを使用した場合に、blockの外に出ても元のscopeに正しく戻されないバグがあったのを修正しています。


Merge pull request #29616 from kamipo/remove_unused_aliased_table_name

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

使用していないAssociationaliased_table_nameメソッドを削除しています。


Deprecate delegating to arel in Relation

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

Relationareldelegateしていたメソッドがdeprecateになりました。

現状、areldelegateするメソッドがどれかが不明確な状態になっています(klassdelegateするメソッドとareldelegateするメソッドが混在している)。不明確な状態をなくす為に、arelへのdelegateは無くす方向で考えいるようで、その前段階として、delegateが行われた場合、deprecateメッセージが表示されるよう対応しています。


Fix the next version of Rails from 5.3 to 6.0

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

deprecateメッセージで表示する次のRailsのバージョンを5.3から6.0に更新しています。5.2の次は6.0になる予定の為。

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

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

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

actioncable/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #29528 from padi/actioncable_redis_alt_config_with_password

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

Acton Cableのredis adapterを使用している場合、cable.ymlhostportdbpasswordを指定出来るよう修正しています。


Merge pull request #29556 from kamipo/extract_ordered_relation

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

FinderMethods moduleの各メソッドでそれぞれ行っていたrelationのorder処理をordered_relationメソッドに切り出してそちらで行うよう修正しています。


Merge pull request #29551 from Edouard-chin/integration-test-follow-redirect

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

follow_redirect!メソッド呼び出し後にhtml_documentのキャッシュがクリアされないバグがあったのを修正しています。


Merge pull request #29518 from ragesoss/master

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

callbackの:if及び:unlessオプションにStringを渡した場合に表示されるdeprecateメッセージに、Stringの代わりにSymbol、lambda等を渡すよう説明を追加しています。


Fix typo in callback deprecation message

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

callbackの:if及び:unlessオプションにStringを渡した場合に表示されるdeprecateメッセージで、lambdaをlamdbaにタイポしていたのを修正しています。


Merge pull request #29533 from jdelStrother/missing_url_formats

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

path helperにformatオプションを指定した後に、formatオプションを指定せずに同じhelperを呼び出した場合に、結果のpathにformatが設定されないバグがあったのを修正しています。


ActiveRecord: do not create “has many through” records that have been removed

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

has_many :through associationを使用している場合に、子associationをbuildし、かつ、親をsaveする前にその子associationを削除した場合に、正しく削除されないバグ(削除しても親をsaveするとデータが作成されてしまう)があったのを修正しています。


Use reload in test_find_first_after_reload

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

reloadに関するテストでresetを呼んでいたいのを修正、及び、テストに失敗した場合に表示するエラーメッセージの内容に誤りがあったのを修正を行っています。


Fix ids_reader to respect case sensitive primary key

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

CollectionAssociation#ids_readerでprimary keyのエスケープ方法に誤りがあったのを修正しています。


:scissors:

actionview/CHANGELOG.mdactivemodel/CHANGELOG.mdの修正です。

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

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

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

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


Merge pull request #29519 from Edouard-chin/ec-structure-flags-order

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

MySQLのdump / load処理で、structure_dump_flags / structure_load_flagsに指定したオプションを最初にコマンドに渡すよう修正しています。

mysqlではオプションを渡す順番に意味があり、たとえば--no-defaultsのようなオプションは他のオプションより先に渡す必要がある為との事です。

参考:MySQL :: MySQL 5.7 Reference Manual :: 4.2.7 Command-Line Options that Affect Option-File Handling


Merge pull request #29511 from jhawthorn/clear_offsets_cache_on_collection_proxy

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

CollectionProxy#reset / CollectionProxy#reloadfind_nthで取得したレコードのキャッシュをクリアーするよう修正しています。


Update security.md

rails guideのRuby on Rails Security Guideの修正です。

Brakeman - Rails Security Scannerへのリンクの後にスペースを追加しています。


Merge pull request #29560 from fatkodima/remove_unnecessary_tap_call

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

DefaultMiddlewareStack#build_stackActionDispatch::MiddlewareStackをnewした結果をtapしていたのを、tapを削除しています。

ActionDispatch::MiddlewareStack#initializeの中でblockのyields処理が行われており、tapする必要は無い為。


Merge pull request #29568 from kamipo/ensure_using_correct_alias_tracker

Active Recordの修正です。

Associations::AliasTrackerクラスでtype casterに誤ったクラスが指定されてしまうバグがあったのを修正しています。


Merge pull request #29557 from kamipo/extract_build_scope_and_predicate_builder

Active Recordの修正です。

build_scope及びpredicate_builderReflectionmoduleに切り出しています。


Merge pull request #29571 from kamipo/fix_extracting_references_via_order_values

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

WhereChain#preprocess_order_argsメソッドでreferencesを取得する際に、テーブル名をquoteしている場合に、テーブル名が正しく取得出来ないバグがあったのを修正しています。


Ignore public/assets

railties/lib/rails/generators/rails/app/templates/gitignoreの修正です。

デフォルトで生成されるgitignoreに/public/assetsを追加しています。

assets precompileでのファイル生成は各環境で行うべきであり、バージョン管理に追加すべきではない為。そういえば何で今までで追加されてなかったんだろう。


ActiveJob::Core#serialize stores provider_job_id (fixes #26581).

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

ActiveJob::Core#serializeメソッドでprovider_job_idを含むよう修正しています。

serialize対象に入っていないと、after_enqueuebefore_perform等のcallbackで値が取得出来ない為。


Document ActiveRecord’s PostgreSQL-specific support for JSONB datatype in RailsGuides

rails guideのActive Record and PostgreSQLの修正です。

JSONの項をJSON and JSONBに修正し、jsonbを使用した場合のexampleを追加しています。


Skip instantiating NullPreloader if assoc.klass is nil

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

assoc.klassnilの場合に、不要なNullPreloaderインスタンス生成処理を行わないよう修正しています。


Move constructing polymorphic type to join_scope in Reflection

Active Recordの修正です。

JoinAssociation#join_constraintsで行っていた polymorphic typeの生成処理を、Reflection moduleのjoin_scopeメソッドで行うようリファクタリングしています。


Move building constraint to join_scope in Reflection

Active Recordの修正です。

JoinAssociation#join_constraintsで行っていたconstraintの生成処理を、Reflection moduleのjoin_scopeメソッドで行うようリファクタリングしています。

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

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

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

railties/CHANGELOG.md


Add railtie.rb to the plugin generator

railtiesの修正です。

rails pluginを生成する際にRails::Railtieを継承したRailtieクラスを定義したファイルを生成するよう修正しています。

rails pluginでRailtieクラス使うのどういうケースだろう。


Remove needless gitignore

使用していないactivejob/.gitignoreを削除しています。