なるようになるブログ

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

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

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

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

actionpack/CHANGELOG.md

activestorage/CHANGELOG.md


Merge pull request #31650 from rosa/master

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

Blob#service_urlでURLを生成する際に、filenameをメソッドの引数で指定出来るよう修正しています。


Fix attaching blobs to optimistically-locked records

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

attachment用のassociationを宣言する際に、inverse_ofオプションを指定するよう修正しています。

同一のインスタンスを参照出来るようにしておかないと、optimistic lockを使用しているmodelでのsave処理実行時にエラーになってしまう事がある為。


Work around Firefox's refusal to dispatch events on disabled elements. Fixes #31393

activestorage/app/javascript/activestorage/helpers.jsの修正です。

element.dispatchEventを実行する際に、try句で囲むようにし、element.dispatchEventでエラーがおきても処理を継続するよう修正しています。

disabled elementsに対してdispatchEventメソッドを呼び出すとエラーになる、というバグ(?)がFirefoxにあり、その為のワークアラウンドとの事です。

参考:329509 - Do not prevent event dispatching even if there is no prescontext or (form) element is disabled


Rebuild activestorage.js

activestorage/app/assets/javascripts/activestorage.jsの修正です。

activestorage.jsの再生成を行っています。先に行ったFirefox向けの修正を入れたJSを作成する為。


Add 'Referrer-Policy' header to default headers set

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

デフォルトで設定するheaderにReferrer-Policy(値はstrict-origin-when-cross-origin)を追加しています。


Change Active Storage destroy callbacks

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

attachmentsをpurgeする際、purge_laterメソッドを呼び出すのにbefore_destroy callbackを使用していたのを、after_destroy_commit callbackを使用するよう修正しています。

before_destroyだと、ユーザがmodelに処理をabortするcallback(e.g. before_destroy { throw(:abort) })をmodelに定義していた場合に、attachmentは削除されないがblobは削除される、という状態になってしまう為、それを避ける為にafter_destroy_commitを使用するようにしています。

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

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

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


Document automatic width-height swapping [ci skip]

activestorage/lib/active_storage/analyzer/video_analyzer.rbのdocの修正です。

Analyzer::VideoAnalyzerクラスのdocにvideoのangleが90、または、270度の場合に、videoの幅と高さをスワップする旨説明を追加しています。


Improve the deprecation message for using subclass of Rails::Application to start the Rails server

railties/lib/rails/commands/server/server_command.rbrailties/CHANGELOG.mdの修正です。

config.rurunメソッドにRails::Applicationのサブクラスを指定した場合に表示されるdeprecationメッセージのグラマーの修正を行っています。


Fix deleting through records when using has_many through with source_type

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

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

has_many through associationsを使用していて、associations経由でrecordsを削除する場合に、source_typeに指定した値が無視されるバグがあったのを修正しています。


Added release notes for Action Cable [ci skip]

rails guideのRuby on Rails 5.2 Release Notesの修正です。

Action Cableの項にRemovalsNotable changesについての説明を追加しています。


Added deprecations and removals notes for Action Pack [ci skip]

rails guideのRuby on Rails 5.2 Release Notesの修正です。

Action Packの項にRemovalsNotable changesについての説明を追加しています。


Added deprecation and removal notes for Action View [ci skip]

rails guideのRuby on Rails 5.2 Release Notesの修正です。

Action Viewの項にRemovalsNotable changesについての説明を追加しています。


Fix the desc for image_alt change [ci skip]

rails guideのRuby on Rails 5.2 Release Notesの修正です。

imageタグを生成する際、デフォルトではalt属性を生成しないようにした対応の説明を修正しています。


Allow use_authenticated_message_encryption to be set in new_framework_defaults_5_2.rb

activesupport/lib/active_support/message_encryptor.rbactivesupport/lib/active_support/railtie.rbの修正です。

config/initializers/new_framework_defaults_5_2.rbconfig.active_support.use_authenticated_message_encryptionを指定した際に、指定した値が使用されないバグがあったのを修正しています。


Remove meaningless check

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

active_support.set_hash_digest_class initializerから不要なconfig.active_support.hash_digest_classのチェックを削除しています。


Fix rubocop space before comma

activesupport/test/core_ext/object/blank_test.rbの修正です。

テスト内でrubocopの規約に違反している箇所があったのを修正しています。

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

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

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


Revert commit 4ec5b0d6b4d8a57e034b1014942356e95caf47aa in favor of #28379

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

SQLite3 adapterでintegerのデフォルトが4 bytesとして扱われていたのを8 bytesとして扱うよう修正した、SQLite3 valid integer value should be 8 bytes (64-bit signed integer)により不要になったsql_typeがbigintの場合の特別な処理を削除しています。


Fix pluck with eager loading to respect offset

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

pluck + eager load + offsetを使用した場合に、offsetに指定した値が使用されないバグがあったのを修正しています。


Fix last with offset to behave consistently with loaded relation

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

load済みのrelationに対して、last + offsetを使用した場合、offsetに指定した値が正しく取得出来ないバグがあったのを修正しています。


Make find_nth_from_last more performant when using reversible order

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

FinderMethods#find_nth_from_lastメソッドで結果を返すのに毎回全レコードをloadしていたのを、必要なレコードのみloadするよう修正しています。


Tweak engine for readability

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

適切な位置にスペースの追加、Arrayを定義するのに[]を使用していたのを、%w()を使用するよう修正しています。


Simply use scope.delete_all instead of constructing delete manager

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

HasManyThroughAssociation#delete_recordsメソッドでレコードを削除するのにArel::DeleteManagerを使用して削除用のSQLを組み立ていたのを、scope.delete_allを使用して削除処理を行うよう修正しています。


Remove redundant sentences [ci skip]

activestorage/lib/active_storage/analyzer/image_analyzer.rbactivestorage/lib/active_storage/analyzer/video_analyzer.rbのdocの修正です。

Analyzer::ImageAnalyzerクラス、Analyzer::VideoAnalyzerクラスのdocから不要と思われる説明を削除しています。

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

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

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

activestorage/CHANGELOG.md


Force content disposition to attachment for specific content types

Active Storageの修正です。

service_urlメソッドのdispositionオプションのデフォルトが:inlineになっていたのを、inlineで表示すべきではないファイル(text/htmlapplication/x-shockwave-flash等々)は:attachmentとして扱うよう修正しています。

htmlやjavascriptはinlineで表示してしまうと、XSSが実行されてしまう可能性がある為。デフォルトを:attachmentとして扱いたいcontent typeはconfig.active_storage.content_types_to_serve_as_binaryで指定可能になっています。

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

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

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


Partial revert the changing default value of readonly_value

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

ActiveRecord::Relationに設定及び取得を行う為のメソッド(#set_value、#get_value)を追加した、Remove over meta programming in AR::Relationの対応でWhereChainクラスのDEFAULT_VALUESも変更していたのを元に戻しています。default valueを変更する必要はなかった為。


Move the options for deliver_later up near to the example [ci skip]

actionmailer/lib/action_mailer/message_delivery.rbのdocの修正です。

deliver_later!及びdeliver_laterメソッドのdocでメソッドのオプションについての説明を、exampleの後に移動しています。


Remove passing argument to singular and collection association readers

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

association reader用メソッドから使用していない引数を削除しています。


Add missing require for strip_heredoc

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

不足していたactive_support/core_ext/string/stripのrequireを削除しています。


Consolidate queue_adapter= and interpret_adapter

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

Provides friendlier way to access queue adapters of a job.以降、`ActiveJob::QueueAdapter#queue_adapter=メソッドがinterpret_adapterメソッドを呼び出すだけになってしまっていたので、interpret_adapterメソッドを削除し、queue_adapter=メソッドの方で処理を定義するよう修正しています。

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

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

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

activesupport/CHANGELOG.md


Move config.action_view.cache_template_loading to proper section in configuring.md [ci skip]

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

config.action_view.cache_template_loadingについての説明がRails General Configurationの項に定義されていたのを、Configuring Action Viewの項に移動しています。


Correctly handle infinity value in PostgreSQL range type

activerecord/lib/active_record/connection_adapters/postgresql/oid/range.rbactiverecord/lib/active_record/connection_adapters/postgresql/quoting.rbの修正です。

PostgreSQLのRange typにFloat::INFINITYを指定した場合にエラーになってしまうバグがあったのを修正しています。


Configure previewer/analyzer command paths centrally

Active Storageの修正です。

各クラスで保持していたコマンド(ffprobeffmpegmutool)のパスをActiveStorage moduleでまとめて保持するよう修正しています。

他のconfig(previewersanalyzers)と合わせる為、のようです。


Deprecate valid_alter_table_type? in sqlite3 adapter

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

sqlite3 adapterのvalid_alter_table_type?メソッドをdeprecatにしています。

元々内部でだけ使用する想定のメソッドだったのですが、誤ってpublic APIになてしまっていたので、まずはdeprecateするようにしています。


Merge pull request #31594 from yuki24/refactor-request-test

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

requestのtestで結果を検証するのにモックを使用していたのを、実際にqueryやpath_infoをrequestに指定して検証を行うよう修正しています。


Fix newly added reflection order when redefining association

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

associationを再定義した際に、reflection orderも再定義するよう修正しています。

reflectionも再定義をしないと、順序がずれてしまいエラーになってしまう事がある為。


Merge pull request #31011 from danielma/dma/assert-changes-with-to-should-still-assert-change

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

assert_changesメソッドが、expressionオプションの値を評価後、tofromオプションの値に関わらず必ずassertを実行するよう修正しています。


Merge pull request #31049 from gwincr11/cg-blank

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

String#blank?メソッドをUTF-8以外のエンコードのStringで呼び出すとエラーになっていたのを、エラーにならないよう修正しています。

# before
" ".encode("UTF-16LE").blank?
#=> Encoding::CompatibilityError (incompatible encoding regexp match (US-ASCII regexp with UTF-16LE string))


# after
" ".encode("UTF-16LE").blank?
#=> true

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

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

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

activerecord/CHANGELOG.md


Merge pull request #29018 from willbryant/missing_attributes_after_save

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

save / save!メソッド実行後、元々assignされていたattributesの情報が失われてしまっていたのを、元の情報を保持するよう修正しています。


Merge pull request #27561 from fishbrain/count-all-in-has-many-association

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

associationに対してcount + selectで任意のカラムを指定したときに、不正なSQLが生成されてしまうバグがあったのを修正しています。


Remove undefined track_deletion callback [ci skip]

activesupport/lib/active_support/core_ext/module/concerning.rbのdocの修正です。

Module::Concerning moduleのdoc内のexampleコードから、存在しないtrack_deletionメソッドを呼び出している箇所を削除しています。


Merge pull request #25456 from ojab/master

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rbactiverecord/test/cases/connection_pool_test.rbの修正です。

ConnectionHandler#retrieve_connectionメソッドでpool.connectionの戻り値をチェックし、nilだったらConnectionNotEstablishedをraiseする、というコードがあったのを削除しています。

connectionが取得出来なかった場合はconnectionメソッド内でConnectionNotEstablishedをraiseするようになっていて、nilをreturnする事は無い為。


Merge pull request #31331 from dinahshi/postgresql_bulk_update

activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rbactiverecord/lib/active_record/connection_adapters/postgresql_adapter.rbの修正です。

PostgreSQL adapterにbulk alterのサポートを追加しています。

これにより、PostgreSQLでもchange_tablebulk: trueオプションを指定した場合、一つのALTER TABLEでSQLが実行されるようになっています。


Exclude ActiveStorage::SetBlob from API docs [ci skip]

activestorage/app/controllers/concerns/active_storage/set_blob.rbのdocの修正です。

内部でだけ使用するActiveStorage::SetBlob moduleに:nodoc:を指定しています。