なるようになるブログ

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

rails commit log流し読み(2015/11/16)

2015/11/16分のコミットです。

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

railties/CHANGELOG.md


copy edits [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

Testing Time-Dependent Codeの項について、time関する処理についての説明を削除、コードサンプル内にあった実行結果の例の削除、等を行っています。


Remove not needed NATIVE_DATABASE_TYPES entries

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

AbstractMysqlAdapterNATIVE_DATABASE_TYPESから重複して定義されていたblob、及びbigintを。PostgreSQLAdapterのNATIVE_DATABASE_TYPESからbigintbigserial`をそれぞれ削除しています。

bigintbigserialは定義はされていたものの、実際は使われていない(rails 内部ではlimit付きのinteger`にマッピングされている)為、削除したとの事です。


Freeze association foreign keys to reduce allocations

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

Reflection#foreign_keyメソッドで、derive_foreign_keyメソッドから取得した外部キーの値をfreezeするよう修正しています。


Make the static_index config part of the config.public_server config

railties/lib/rails/application/configuration.rbrailties/lib/rails/application/default_middleware_stack.rbの修正です。

インデックスファイル名を指定する為のconfig名を、config.static_index -> config.public_file_server.index_nameに変更しています。

config.serve_static_filesconfig.public_file_server.enabledが変更になったのに合わせて、こちらも変更したとの事です。


Except keys of build_record's argument from create_scope in initialize_attributes

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

collection.buildメソッドでattributesを指定した場合に、そのattributesの値が、scopeで定義されたattributesの値を上書き出来なかったのを上書き出来るよう修正しています。

[2015/11/20 修正]

dbでデフォルト値があるカラムを上書きするようなscopeをもったアソシエーションのbuildに、デフォルト値を与えるときに、上書き出来なかったのを上書き出来るよう修正しています、との事です。

[/2015/11/20 修正]

issueより。

class Post < ActiveRecord::Base
  has_many :comments_with_scope, -> { active }, class_name: 'Comment'
  has_many :comments_with_hash_condition, -> { where(flag: true) }, class_name: 'Comment'
  has_many :comments_with_sql_condition, -> { where('flag is true') }, class_name: 'Comment'
end

class Comment < ActiveRecord::Base
  belongs_to :post

  scope :active, -> { where(flag: true) }
end
Post.create!.comments_with_scope.build(flag: false).flag
# => 元々`true`になってしまっていたのを、`false`になるよう修正

Use proper syntax for class method reference.

activesupport/CHANGELOG.mdの修正です。

Time.days_in_yearメソッドを追加した対応のエントリーで、メソッド名がインスタントメソッド表記(Time#days_in_year)になってしまっていたのを、クラスメソッド(Time.days_in_year)に修正しています。