なるようになるブログ

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

rails commit log流し読み(2018/01/16)

2018/01/16分のコミットです。

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

activerecord/CHANGELOG.md


Fix relation merger issue with left_outer_joins

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

left_outer_joinsをrelationのmergeに指定した場合に、正しく動作しないバグがあったのを修正しています。


Extract content types from blob data

Active Storageの修正です。

blobからcontent typeを取得するようにし、upload等の処理ではその取得したcontent typeを使用するよう修正しています。

もともとはブラウザから送信されたcontent typeをそのまま使用していたのですが、ブラウザからは誤ったcontent typeが送信されることがまあまああり、そのまま使うと正しく動作しなかった為、独自に取得するようにしたとの事です。

実際のcontent typeの取得処理には、marcelというBasecamp製のgemを作っています。


Fix constant reference

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

Digest::SHA2クラスの指定が相対での指定になっていたのを、トップレベルからの指定に修正しています。

        def truncate_key(key)
           if key.bytesize > max_key_bytesize
-            suffix = ":sha2:#{Digest::SHA2.hexdigest(key)}"
+            suffix = ":sha2:#{::Digest::SHA2.hexdigest(key)}"

rails commit log流し読み(2018/01/15)

2018/01/15分のコミットです。

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

activerecord/CHANGELOG.md


Merge pull request #28313 from sandrew/master

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

left_outer_joinsメソッド(及びそのaliasのleft_joins)をunscope出来るよう修正しています。


create_database should not add default charset when collation is given

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

MySQLでDB作成時、collationが指定された場合、自動でCHARACTER SETも指定するようになっていたのを、指定しないよう修正しています。

MySQLではcharsetはデフォルトのcollationを検索するために使われるもので、collationが明示的に指定されている場合は不要な為。


Don't allow destroyed object mutation after save or save! is called

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

削除済みのオブジェクトに対して、save、また、save!メソッドを呼び出した場合に、frozen済みだったattributesがunfrozenに戻ってしまう、というバグがあったのを修正しています。

rails commit log流し読み(2018/01/14)

2018/01/14分のコミットです。

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


Don't pass garbage args to alias tracker

activerecord/lib/active_record/associations/alias_tracker.rbactiverecord/lib/active_record/relation/finder_methods.rbの終了です。

join dependency構築する際に、alias trackerに使用しないオブジェクト(Arel::Nodes::Joinインスタンス以外のオブジェクト)も渡すようになっていたのを、Arel::Nodes::Joinインスタンスのみ渡すよう修正しています。


Don't need to pass manager to convert_join_strings_to_ast

activerecord/lib/active_record/relation/query_methods.rbの終了です。

convert_join_strings_to_astメソッドから不要なtable引数を削除しています。

RelationがArel tableの情報を保持しており、そちらを使用すれば良いため。


Change test case name to FormatValidationTest

activemodel/test/cases/validations/format_validation_test.rbの修正です。

validates_format_ofメソッドについてのテストを記載しているテストのクラス名がPresenceValidationTestになっていたのをFormatValidationTestに修正しています。

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

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

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


Merge pull request #31675 from Dorian/fix-some-broken-links-in-guides

rails guideの修正です。

各guideのリンクで壊れている箇所があったのを修正しています


Fix doc typo [ci-skip]

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

Testing Jobsの項でタイポしている箇所があったのを修正しています。


Merge pull request #31651 from eugeneius/use_sha1_digests

Active Support、railtiesの修正です。

ETag header等で使用するhash fuctionにMD5ではなく、SHA1を使用するかどうかを指定する為のconfig(config.active_support.use_sha1_digests)を追加しています。

デフォルトfalseですが、load_default 5.2するとtrueになるようになっています。


deep_dup is used in AttributeSet#deep_dup

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

activemodel/lib/active_model/attributes.rbから不要なdeep_dupのrequireを削除し、activemodel/lib/active_model/attribute_set.rbに不足していたdeep_dupのrequireを追加しています。


Merge pull request #31572 from kami-zh/fix-template

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

initializersについて説明している箇所に、initializers配下のファイルはframeworkをgemがロードされた後にロードされる旨説明を追加しています。

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

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

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


Merge pull request #31671 from larskanis/pg-1.0

Active RecordやAction Cableでpg gemのバージョンロック(gem "pg", "~> 0.18")をしていたのを、修正(gem "pg", ">= 0.18", "< 2.0")しています。

pg gem 1.0がリリースされており、それを使用出来るようにする為。

参考:ged/ruby-pg / History.rdoc


Use my fork instead of an thrid-party fork

Gemfileの修正です。

先のpg gemの対応の都合上、queue_classic gemを使用するのにforkしたリポジトリを使用しているのですが、そのリポジトリにrafaelfrancaのリポジトリを使用するよう修正しています。

元々はPRを出した方のリポジトリになっていたのですが、それだとその人が誤ってリポジトリを消してしまった場合にbuildがコケてしまう為。


Fix typos, update documentation

各docのタイポ(url -> URL等)の修正をまとめて行っています。


Use complete variable names rather than single-letter abbreviations for style

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

content_security_policyを設定する変数名が一文字の変数(p)になっていたのを、意味のある変数名(policy)に修正しています。


Add note about having to restart when modifying initializer

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

ファイルの先頭に、ファイルを変更した場合serverのrestartが必要である旨説明を追加しています。


Use unsafe_inline as the default for script_src CSP until we get a nonce alternative

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

script_srcの設定にunsafe_inlineを追加しています。

unsafe_inlineの指定が無いとSJRやTurbolinksのりダイクレと処理が動作しない為。

ただ、これは一時対応で、ちゃんとした対応は別途やりたい(Upgrade CSP script_src default from unsafe_inline to nonce approach)との事です。

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

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

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

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


[ci skip] setting :inverse_of works with :as, :through and :polymorphic options, and is needed for bi-directionality with a scope

activerecord/lib/active_record/associations.rbのdoc、及び、rails guideのActive Record Associationsの修正です。

:inverse_of:as:throughオプションを指定した場合に動作しない旨説明が記載されていたのですが、実際は動作するようになっているので、その旨説明を修正しています。


Extract Analyzable and Representable concerns

Active Storageの修正です。

ActiveStorage::Blobクラスの中で定義されていた analyze / representation等に関する処理をmodule(Analyzable / Representable)に切り出しています。


Correct comment [ci skip]

activestorage/app/models/active_storage/blob/representable.rbのdocの修正です。

ActiveStorage::Blob::Representable#variantメソッドのdoc内でメソッド名をタイポしていたのを修正しています。


Add missing # frozen_string_literal: true

Active Storageの修正です。

先ほど追加したAnalyzable / Representable moduleの先頭にfrozen_string_literal: trueが不足していたのを追加しています。


Update error names in docs [ci skip]

activestorage/app/models/active_storage/blob/representable.rbのdocの修正です。

先のmoduleの切り出しの影響によりUnpreviewableErrorクラスのnamespaceが変更になっていたのですが、docが古いままになっていたので修正しています。


Make relation.exists? more performant when using eager loading

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

eager load + relationに対するexists?メソッドを実行した場合に、不要なSELECT queryが実行されてしまっていたのを、実行されないよう修正しています。


Use apply_join_dependency instead of meaningless named find_with_associations

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

Relation#to_sqlメソッドでJoinDependencyを組み立てるのにfind_with_associationsという名前のメソッドを使用していたのを、apply_join_dependencyメソッドを使用するよう修正しています。

find_with_associationsという名前にも関わらず、やっている事は JoinDependencyの組み立てだけで、findingに関する処理は無かった為、名前と処理が一致していませんでした。ただ、JoinDependencyとrelationを返してもらう必要はあった為、apply_join_dependencyの方でそれらを返せるようにし、find_with_associationsメソッドは削除しています。


Remove the deprecated :conditions option in INVALID_AUTOMATIC_INVERSE_OPTIONS

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

deprecateになっていたINVALID_AUTOMATIC_INVERSE_OPTIONS:conditionsオプションを削除しています。


Fix typos [ci skip]

各guideのタイポ、不要なスペース等をまとめて削除しています。


Merge pull request #23146 from piotrj/issue_18424

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

has_many :through associationsを使用している場合に、_idsメソッドでidを更新する際、scopeに定義されたコンディションが無視されてしまっていたのを、コンディションを使用するよう修正しています。


Merge pull request #31624 from y-yagi/fix_minitest_511

activesupport/lib/active_support/testing/isolation.rbrailties/lib/rails/test_unit/reporter.rbの修正です。

Minites 5.11でRailsのtest runner、及び、Testing::Isolation moduleが正しく動作していなかったのを、動作するよう修正しています。


Merge pull request #30268 from ignatiusreza/instrumentation

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

ActiveSupport::Cache::Storeクラスのread_multiメソッドに対するinstrumentation hookが実装されていなかったのを、実装しています。


Instrument preview image drawing

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

ActiveStorage::Previewer#drawメソッドに対してinstrumentation hookを追加しています。


Instrument image transformation

activestorage/app/models/active_storage/variation.rbの修正です。

ActiveStorage::Variation#transformメソッドに対してinstrumentation hookを追加しています。

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

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

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

activerecord/CHANGELOG.md


resolve inconsistencies between first and to_a.first with limit

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

first(n) + limitメソッドを使用した場合に、limitに指定した値が無視されていた(指定した値で結果が制限されていなかった)のを、結果のレコード数がlimitに指定した値になるよう修正しています。

last(n) + limitを使用した場合と挙動を合わせる為。


Merge pull request #31534 from claudiob/kaspth-approach

rails newした際にActive Storage用のmigrationファイルが自動で生成されるようになっていたのを、生成しないよう修正しています。

代わりに、Active Storageを使用しようとして、Active Storage用のテーブルが存在しない場合、エラーメッセージにbin/rails active_storage:installを実行する旨説明を表示するよう修正しています。


Merge pull request #29685 from ayanko/fix-slow-name-error-missing-name

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

NameError#missing_nameメソッドでmessageを取得する際に、original_messageが定義されていれば、そちらの値を使用するよう修正しています。

+    # Since ruby v2.3.0 `did_you_mean` gem is loaded by default.
+    # It extends NameError#message with spell corrections which are SLOW.
+    # We should use original_message message instead.
+    message = respond_to?(:original_message) ? original_message : self.message
+

上記コメントにもある通り、NameError#messagedid_you_meanによるスペル補正が入り、その分遅いためoriginal_messageを使用するようにしたとの事です。


Bring back passing single record support for Preloader

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

Preloader#preloadメソッドのrecords引数に単一のrecordを渡せるよう修正しています。

Rails 5.1までは渡せるようになっていたのですが、PreloaderクラスはRails内部でのみ使用するクラスであり、Rails内部では必ずArrayで渡すようになっていたため、単一のrecordが渡された場合のケア(Array.wrapの呼び出し)は削除されていました。

ただ、Preloader#preloadメソッドを直接使用しているケースがあったらしい為(issueが作成された)、互換性の為に再度単一recordを渡せるよう戻しています。


Fix "the the " [ci skip]

docの修正です。

theが二回連続で記載されている箇所があったのを修正しています。


Clean up railties tests

railties/test/generators/app_generator_test.rbrailties/test/generators/shared_generator_tests.rbの修正です。

Don't include Active Storage migrations in new appsの対応により不要になったactive_storage:installのテスト、及び、不要なmigrationが生成されるかどうかのチェックを削除しています。


Merge pull request #16314 from zoltankiss/allow-nested-has-many-associations-on-unpersisted-parent-instances

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

has_many :through associationをnestして使用している場合に、親のインスタンスが永続化されていないと子のインスタンスから値が取得出来ないバグがあったのを修正しています。

class Post < ActiveRecord::Base
  belongs_to :author
  has_many :books, through: :author
  has_many :subscriptions, through: :books
end

class Author < ActiveRecord::Base
  has_one :post
  has_many :books
  has_many :subscriptions, through: :books
end

class Book < ActiveRecord::Base
  belongs_to :author
  has_many :subscriptions
end

class Subscription < ActiveRecord::Base
  belongs_to :book
end

上記のようなassociationが定義されていた場合に、postが永続化されていない場合にpost.subscriptionsが必ず空になってしまっていたのが、正しく値を取得出来るようになっています。


Fix stale_state for nested has_many :through associations

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

has_many :through associationをnestして使用している、かつ、through先のrecordが変更された場合に、reflectionの情報が正しくreloadされるよう修正しています。