2015/01/24分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
- Don't remove join dependencies in
Relation#exists?
- Errors raised in
type_cast_for_database
no longer raise on assignment - Move integer range validation to never raise on assignment
activemodel/CHANGELOG.md
- Extracted
ActiveRecord::AttributeAssignment
toActiveModel::AttributesAssignment
- use attribute assignment module logic during active model initialization
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.rb
、
activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
の修正です。
value_for_database
メソッドでexceptionが発生した場合に、エラーをrescueし、original_raw_attributes
にnilを設定するよう修正しています。
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'
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系メソッドの引数に文字列を指定した場合の挙動の説明が実際の動作と異なっている箇所があり、説明を修正しています。