なるようになるブログ

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

rails commit log流し読み(2018/02/27)

2018/02/27分のコミットです。

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

actionview/CHANGELOG.md

activemodel/CHANGELOG.md


Avoid specifying content types for direct uploads to Google Cloud Storage

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

Google Cloud Storageにdirect uploadする際に、content typeを指定しないよう修正しています。

content typeが指定された状態だと、本来指定したいcontent type(signed URLsのparamに指定したresponse-content-type)が指定されない為。

参考:Fix customizing Content-Type via GCS service URLs


Never attempt to write virtual attributes to the database

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

partial_writesがfalseの場合に、databaseへの値の保存処理で virtual attributesも保存しようとしてしまっていたのを、保存しないよう修正しています。


Ensure we don't write virtual attributes on update, too

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

partial_writesがfalseの場合に、更新処理でvirtual attributesも保存しようとしてしまっていたのを、保存しないよう修正しています。


Partly revert 91b30a001b79096b60d9424a4664a417dce0b767

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

polymorphic associationに対してreflection.klassを取得しようとした場合にArgumentErrorをraiseするよう修正した、Merge pull request #31895 from kamipo/do_not_attempt_to_find_inverse_…の対応で、合わせてklass._reflect_on_associationNameErrorが起きた際に、そのエラーを無視するよう修正したのですが、そのNameErrorが起きた際に無視する、という挙動に依存しているテストがActive Recordのテスト内に多数あった為、NameErrorについては無視するよう処理を戻しています。


Update test to reflect direct upload header changes

activestorage/test/controllers/direct_uploads_controller_test.rbの修正です。

先のGoogle Cloud Storageにdirect uploadする際にcontent typeを指定しないよう修正した対応が、テストの修正が漏れていたので修正しています。


add private: true option for ActiveSupport delegate

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

delegateメソッドに、delegateしたメソッドの可視性をprivateとして扱うかどうかを指定する為のprivateオプションを追加しています。

class User < ActiveRecord::Base
  has_one :profile
  delegate :first_name, to: :profile
  delegate :date_of_birth, :religion, to: :profile, private: true

  def age
    Date.today.year - date_of_birth.year
  end
end

User.new.age # 2
User.new.first_name # Tomas
User.new.date_of_birth # NoMethodError: private method `date_of_birth' called for #<User:0x00000008221340>
User.new.religion # NoMethodError: private method `religion' called for #<User:0x00000008221340>

上記例だと、first_nameはアクセスできるのですが、privateオプションが指定されているdate_of_birth、及び、religionは可視性がprivateになる為、アクセスしようとするとNoMethodErrorになるようになっています。


Clear Blob's type before sending it

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

direct uploadでblobを送信する前にblob typeをクリアーするよう修正しています。

古いバージョンのChromeでBlob typeから取得したcontent type headerを勝手に追加する、という挙動が確認されたので、それを避ける為クリアーするようにした、ようです。


Remove extra changelog added by #31944

activesupport/CHANGELOG.mdの修正です。

add private: true option for ActiveSupport delegateの対応の際に関係ないエントリーまでCHANGELOGに追加されてしまったのを削除しています。


Change translation key of submit_tag from module_name_class_name to module_name/class_name

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

submit tagのvalueを生成する際に、i18n_keyを使用するよう修正しています。

元々はi18n_keyを使わずobject_nameを使用してvalueを生成していたのですが、それだとnamespaceの区切りに/が使えない(e.g. blog/post)為、i18n_keyを使うよう修正しています。


Merge pull request #32115 from avneetmalhotra/routing_bound_parameters_guide_fix

rails guideのRails Routing from the Outside Inの修正です。

Bound Parametersの項、exampleコードでtoオプションに指定する値に誤りがあったのを修正しています。


[ci skip]Change requring order of files in doc

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

Loading Railsの項に記載されているrailties/lib/rails/all.rbの内容が実際の内容と異なっていたのを修正しています。


Merge pull request #31189 from tgxworld/raise_error_when_advisory_lock_is_not_releases

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

migrationでadvisory lockのリリースに失敗した場合に、その状況がわかるエラーメッセージをraiseするよう修正しています。


add :nodoc: to ActionView::Helpers::FormBuilder#emitted_hidden_id?

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

内部用APIActionView::Helpers::FormBuilder#emitted_hidden_id?メソッドに:nodoc:の指定を追加しています。


Merge pull request #32005 from maschwenk/ar-distinct-order-count-regression

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

eager load + orderに任意のカラムを指定 + distinct + count or sizeを指定した場合に正しく値が取得出来ないバグがあったのを修正しています。


Merge pull request #28270 from mmangino/dont_ignore_seralization_options

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

serializationのincludesオプションに複数のHash(e.g. serializable_hash(include: [address: { only: "street" }, friends: { only: "name" }]))を指定した場合に、最初のHashに紐づく値しか取得されなかったのを、すべての値が取得されるよう修正しています。