なるようになるブログ

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

rails commit log流し読み(2016/06/03)

2016/06/03分のコミットです。

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

activesupport/CHANGELOG.md


Fix failing tests

Active Recordの修正です。

先日コミットされた、Active Recordのインスタンスyamlに変換した際にyamlに保持してなくても問題無いデータは含まないようした対応( Make Active Record emit significantly smaller YAML)、及びadd_referencesメソッドのforeign_keyオプションにHashを指定した場合にrollback処理でエラーになってしまうのを修正した対応(Respect options passed to foreign_key when reverting add_reference)で、テストが壊れてしまっていたのを、まとめて対応しています。


add missing "as"

rails guideのGetting Started with Enginesの修正です。

What are engines?の項のグラマーの修正を行っています。


Ensure that records with unselected fields can be updated

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

selectで選択しなかったattributesを更新しようとした場合に、NotImplementedErrorがraiseしてしまうバグがあったのを修正しています。

issueより。

ActiveRecord::Schema.define do
  create_table :people, force: true do |t|
    t.string :name
    t.string :color
    t.datetime :created_on
    t.datetime :updated_on
  end
end

class Person < ActiveRecord::Base
end
person = Person.where(name: 'Joe').select(:id, :name).first
person.update(color: 'blue') #=> NotImplementedError

ActiveRecord::Attribute::Uninitializedクラスにoriginal_valueメソッドが無かった為エラーになってしまっていたので、メソッドを追加し対応しています。


Fix debug helper test

actionview/test/activerecord/debug_helper_test.rbの修正です。

先に行われたFix failing testsの対応で、テストの修正漏れがあったので、追加で対応しています。


Don't blank pad day of the month when formatting dates

activesupport/lib/active_support/core_ext/date/conversions.rbの修正です。

Dateクラスのデフォルトのformatで、%eの代わりに%dを使用するよう修正しています。

class Date
   DATE_FORMATS = {
-    :short        => '%e %b',
-    :long         => '%B %e, %Y',
+    :short        => '%d %b',
+    :long         => '%B %d, %Y',
     :db           => '%Y-%m-%d',
     :number       => '%Y%m%d',
     :long_ordinal => lambda { |date|
       day_format = ActiveSupport::Inflector.ordinalize(date.day)
       date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
     },
-    :rfc822       => '%e %b %Y',
+    :rfc822       => '%d %b %Y',
     :iso8601      => lambda { |date| date.iso8601 }
   }

%eだと1桁の日にちのときにスペースが入ってしまい、これは望ましく無い挙動なのでは、との事で修正されたようです。

# before
Date.today.to_formatted_s(:long) #=> "June  3, 2016

# after
Date.today.to_formatted_s(:long) #=> "June 03, 2016"

参考:instance method Time#strftime (Ruby 2.3.0)


[skip ci] Make header bullets consistent in engines.md

rails guideのGetting Started with Enginesの修正です。

先頭の、このguideで学べる事について説明している箇所のリストを、How to〜という言い回しに修正しています。

-* Building features for the engine.
-* Hooking the engine into an application.
-* Overriding engine functionality in the application.
+* How to build features for the engine.
+* How to hook the engine into an application.
+* How to override engine functionality in the application.

他のguideと言い回しを合わせる為、との事です。


Merge pull request #25243 from sukesan1984/add_i18n_validation_test

activerecord/test/cases/validations/i18n_validation_test.rbの修正です。

validationonオプションを指定した場合のテストを追加しています。


[skip ci] Fix grammar

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

Module#thread_mattr_readerModule#thread_mattr_writerのdocのグラマーの修正を行っています。