なるようになるブログ

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

rails commit log流し読み(2018/04/21)

2018/04/21分のコミットです。

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #23868 from gsamokovarov/debug-exceptions-interceptors

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

ActionDispatch::DebugExceptionsにinterceptorを登録出来るようにしています。

interceptorはregister_interceptorメソッドを使用して登録出来るようになっており、登録されたinterceptorはException発生時に実行されます。

ActionDispatch::DebugExceptions.register_interceptor do |request, exception|
  HypoteticalPlugin.capture_exception(request, exception)
end

[ci skip] Improve #find_in documentation.

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

SourceAnnotationExtractor#find_inメソッドのdocで、アノテーションの対象となるファイルの拡張子をベタで記載していたのを、Rails::SourceAnnotationExtractor::Annotation.extensionsで取得出来る値が対象である旨説明を修正しています。

元々記載されいたのではRailsがデフォルトで対応している拡張子だけだったのですが、実際は各gemによりもっと異なる拡張子が登録されており、誤解を招くだろうということで修正されています。


[ci skip] Prefix class name with Rails:: in docs

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

各メソッドのdoc内のexampleコードで、deprecateになった古いクラスSourceAnnotationExtractorが使用されていたのを、新しいクラス(Rails::SourceAnnotationExtractor)を使用するよう修正しています。


Don't include bootsnap by default in apps generated under JRuby

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

JRubyを使用している場合に、rails newで生成されるGemfileにbootsnapを含まないよう修正しています。

bootsnapJRubyをサポートしていない為。


Merge pull request #32572 from nao0515ki/add_optional_true_to_self_joins_section

rails guideのActive Record Associationsの修正です。

Self Joinsの項にあるexampleコード内のbelongs_toを使用している箇所に、optionalオプションの指定が不足していたのを修正しています。


Merge pull request #29286 from vinistock/create_missing_exact_template_exception

Action Packの修正です。

ブラウザからのアクセス、かつ、renderするテンプレートが内場合にraiseするエラークラスをActionController::UnknownFormatからActionController::MissingExactTemplateに変更しています。

また、デフォルトのエラーテンプレートにActionController::MissingExactTemplate用のテンプレートを追加し、ActionController::MissingExactTemplateが発生した場合に適切なエラーページを表示するよう修正しています。


Merge pull request #31513 from fatkodima/relation-touch_all

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

ActiveRecord::Relationtouch_allメソッドを追加しています。

例。

Person.where(name: "David").touch_all(time: Time.current)

Can preload associations through polymorphic associations

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

polymorphic association経由でassociationをpreloadする場合、対象となるassociationが存在しなくてもエラーにならないよう修正しています。

例。

class Review < ActiveRecord::Base
  has_many :media, polymorphic: true
end

class Movie < ActiveRecord::Base
  has_one :director
end

class Book < ActiveRecord::Base
  has_one :author
end

上記のようなクラス構成で、mediaMovie、または、Bookのどちらかになる場合に、media+ その先のassociationをまとめてpreloadしようとすると(Review.includes(media: [:author, :director]))エラー(ActiveRecord::AssociationNotFoundError`)になっていました。で、これをエラーとせず、まとめてpreload出来るよう修正しています。


Relax assertions in connection config tests

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

connection configのテストがbin/testツールを使うとエラーになっていたのを、エラーにならないよう修正しています。

rake testを実行した場合は問題無かったのですが、bin/testを使うとRails.rootが定義されてしまい、その影響で結果が異なるようになってしまっていました。


Fix typo in the touch_all doc [ci skip]

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

Relation#touch_allメソッドのdoc内のexampleコードでtouchメソッドを使用していたのを、touch_allメソッドを使用するよう修正しています。


Add test case for collection.size with dirty target

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

dirty targetを含むcollectionに対するsizeメソッドのテストを追加しています。


target in CollectionAssociation is always an array

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

CollectionAssociation#sizeメソッドでtargetArrayかどうかチェックしていたのを、チェックしないよう修正しています。CollectionAssociationではtargetは必ずArrayの為。