なるようになるブログ

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

rails commit log流し読み(2016/04/04)

2016/04/04分のコミットです。

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

activesupport/CHANGELOG.md

actionpack/CHANGELOG.md


Update Rails 5 release notes [ci skip]

rails guideのRuby on Rails 5.0 Release Notesの修正です。

重複していた各entryを削除しています。


Prevent void context warnings

activesupport/test/autoloading_fixtures/raises_arbitrary_exception.rbactivesupport/test/autoloading_fixtures/throws.rbの修正です。

autoloadingのテスト用fixtureで、定数宣言をした際に値を_に代入するよう修正しています。

void context のwarningが出るのを防止するため、との事です。


Use block form of Dir.mktmpdir to ensure tidy up

activesupport/test/file_update_checker_shared_tests.rbの修正です。

テスト用に作成したtmp directoryを、テストの後処理で削除していたのを、Dir.mktmpdirのblock内で処理を行うよう修正しています。

テストを途中で中断した場合にも、確実にtmp directoryを削除出来るようにする為。


Call super instead of returning nil for DateTime#<=>

activesupport/lib/active_support/core_ext/date_time/calculations.rbの修正です。

DateTime#<=>メソッドで、引数のobjectがInfinityでない、かつ、to_datetimeメソッドが実装されてない場合にnilを返していたのを、superを呼び出すよう修正しています。

  def <=>(other)
-    if other.kind_of?(Infinity)
-      super
-    elsif other.respond_to? :to_datetime
+    if other.respond_to? :to_datetime
       super other.to_datetime rescue nil
     else
-      nil
+      super
     end

RubyオリジナルのDateTime#<=>では、引数がNumericが渡された場合も比較処理が行われる(ユリウス通日を使用しての比較処理が行われる)為、引数がDateTime以外の場合も動作するよう、修正したとの事です。


Match String#to_time's behaviour to ruby

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

不正なStringに対してto_timeメソッドを呼び出した際に、今日のdate(時間は0:00)のインスタンスが返していたのを、nilを返すよう修正しています。

# before
'010'.to_time
# => 2016-04-04 00:00:00 +0900

# after
'010'.to_time
# => nil

Ruby本体の挙動に合わせる為、との事です。


Merge pull request #24247 from ypxing/refactor_substitute_values

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

ActiveRecord#substitute_valuesメソッドで、引数のvaluesに対して2回ループを行っていたのを、一度で済むようリファクタリングを行っています。


Fixes #24239

actionpack/lib/action_controller/metal/cookies.rbの修正です。

ActionController::APIActionController::Cookies moduleをincludeした場合に、エラーになってしまう場合があったのを、正常に動作するよう修正しています。

ActionController::Cookies moduleでhelper_methodを使用しているのですが、ActionController::APIはデフォルトではAbstractController::Helperをincludeしておらず、helper_methodが定義されてない為、エラーになってしまっていました。helper_methodを使用する前に、helper_methodが定義済みかどうかチェックを入れるよう修正しています。

    included do
-      helper_method :cookies
+      helper_method :cookies if defined?(helper_method)
     end