なるようになるブログ

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

rails commit log流し読み(2015/01/24)

2015/01/24分のコミットです。

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

activerecord/CHANGELOG.md

activemodel/CHANGELOG.md


Don't remove join dependencies in Relation#exists?

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

Relation#exists?メソッドがjoinした依存関係の情報を削除してしまっていたのを、削除しないよう修正しています。


Errors raised in type_cast_for_database no longer raise on assignment

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

value_for_databaseメソッドでexceptionが発生した場合に、エラーをrescueし、original_raw_attributesnilを設定するよう修正しています。

SQlite3 adapterを使用し、データに不正なエンコードの値を設定した場合に、Encoding::UndefinedConversionErrorがraiseされてしまっていた問題があった為、対応したようです。

因みにredmineのテストで発覚したらしいです。詳細はこちら


Move integer range validation to never raise on assignment

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

integer型のカラムにinteger範囲外の値を設定した場合に、RangeErrorがアプリ側にthrowされないよう、exceptionのキャッチ処理を追加しています。


Extracted ActiveRecord::AttributeAssignment to ActiveModel::AttributesAssignment

ActiveRecord::AttributeAssignmentモジュールを、ActiveModel::AttributeAssignmentに移動しています。

これにより、以下のような使い方が出来ます。

class Cat
  include ActiveModel::AttributeAssignment
  attr_accessor :name, :status
end

cat = Cat.new
cat.assign_attributes(name: "Gorby", status: "yawning")
cat.name # => 'Gorby'
cat.status # => 'yawning'
cat.assign_attributes(status: "sleeping")
cat.name # => 'Gorby'
cat.status # => 'sleeping'

✂️ and 💅 for #10776

ActiveModel / ActiveRecordの各ファイルの修正です。

先のAttributeAssignmentで対応した各ファイルのフォーマットの修正を行っています。


use attribute assignment module logic during active model initialization

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

ActiveModelインスタンス生成する際、引数に存在しないattributeを指定した場合、これまでNoMethodErrorが発生していたのが、 ActiveModel::AttributeAssignment::UnknownAttributeErrorが発生するよう変更になっています。

User.new(foo: 'some value')
# => ActiveModel::AttributeAssignment::UnknownAttributeError: unknown attribute 'foo' for User.

ActiveModel#initializeインスタンス変数の設定にassign_attributesメソッドを使用するように変更になり、 その影響で発生するExceptionも変更されています。


Fix test failure on PG caused by 7c6f3938dee47f093

activerecord/test/cases/adapters/postgresql/type_lookup_test.rbの修正です。

Move integer range validation to never raise on assignment で対応が漏れていたテストがあったので、追加で対応しています。


Merge pull request #18474 from notEthan/pretty_print_inspect

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

subclassでinspectメソッドを再定義していた場合、pretty_printメソッドinspectを呼び出すよう修正しています。


Fixed duplicating ActiveModel::Errors#details

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

ActiveModel::Errors#detailsの複製を作成する処理で、Errorsクラスの値を元に新規Errorsのデータを作成する際、元データの複製にdupを使用していたのをdeep_dupを使用するよう修正しています。

     def initialize_dup(other) # :nodoc:
       @messages = other.messages.dup
-      @details  = other.details.dup
+      @details  = other.details.deep_dup
       super
     end

detailsのHashはネストしている場合があるので、dupだとちゃんとデータのコピーが出来ていなかったんですねえ。


[ci skip] Fix what is pushed to nesting about eval family

rails guideのAutoloading and Reloading Constantsの修正です。

eval系メソッドの説明をしている箇所で、eval系メソッドの引数に文字列を指定した場合の挙動の説明が実際の動作と異なっている箇所があり、説明を修正しています。