なるようになるブログ

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

rails commit log流し読み(2016/11/05)

2016/11/05分のコミットです。

CHANGELOGへの追加はありませんでした。


Update sqlite3

Gemfile.lockの修正です。

sqlite3のバージョンを1.3.11から1.3.12に更新しています。1.3.11ではOSX 10.12(Sierra)でSIGABRTが発生してしまう問題がある為。


Use different name for main and thread connection variable.

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

connection poolのテストで、メインプロセスとスレッドでコネクションを保持する変数が同じだったのを、異なる変数で保持するよう修正しています。

      def test_checkout_behaviour
         pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec
-        connection = pool.connection
-        assert_not_nil connection
+        main_connection = pool.connection
+        assert_not_nil main_connection
         threads = []
         4.times do |i|
           threads << Thread.new(i) do
-            connection = pool.connection
-            assert_not_nil connection
-            connection.close
+            thread_connection = pool.connection
+            assert_not_nil thread_connection
+            thread_connection.close
           end

同じ変数で保持してしまうと、一つ値を更新してしまうと他のconnection poolにも影響が出てしまう、という問題がJRubyで発生する為修正したとの事です。


Less method invocation

activesupport/lib/active_support/duration/iso8601_serializer.rbの修正です。

ActiveSupport::Duration::ISO8601Serializer#serializeメソッドでtime変数が空かどうかチェックするのにif + present?を使用していたのを、unless + empty?を使用するよう修正しています。

-        output << "T#{time}"  if time.present?
+        output << "T#{time}" unless time.empty?

present?よりempty?の方がメソッドの呼び出し回数が少なくて済む(present?を使用すると、present? -> blank? -> respond_to?で最終的にempty?がよばれる)為のようです。


Show what was the error when assertion has failed

actionpack/test/controller/test_case_test.rbの修正です。

test_should_not_impose_childless_html_tags_in_xmlのテストで、assertの引数にerr.inspectを追加し、エラーの内容を表示するよう修正しています。

このテストがRuby 2.4でfailしており、エラーの内容を調査するために、との事です。


Tweaking some test data due to sprintf behavior change in 2.4

activesupport/test/core_ext/duration_test.rbの修正です。

iso8601メソッドに関するテストの、テストに使用する値の調整を行っています。

-        [nil, "P1Y1MT5.55S",  1.year + 1.month + (5.55).seconds ],
-        [0,   "P1Y1MT6S",     1.year + 1.month + (5.55).seconds ],
-        [1,   "P1Y1MT5.5S",   1.year + 1.month + (5.55).seconds ],
-        [2,   "P1Y1MT5.55S",  1.year + 1.month + (5.55).seconds ],
-        [3,   "P1Y1MT5.550S", 1.year + 1.month + (5.55).seconds ],
+        [nil, "P1Y1MT8.55S",  1.year + 1.month + (8.55).seconds ],
+        [0,   "P1Y1MT9S",     1.year + 1.month + (8.55).seconds ],
+        [1,   "P1Y1MT8.6S",   1.year + 1.month + (8.55).seconds ],
+        [2,   "P1Y1MT8.55S",  1.year + 1.month + (8.55).seconds ],
+        [3,   "P1Y1MT8.550S", 1.year + 1.month + (8.55).seconds ],

Ruby 2.3と2.4で %f で指定の精度に丸める時の挙動が変わった(%f で指定の精度に丸める時に、ちょうど半分の時に丸める方向をその上の桁が偶数になるように丸めるように変更になった)為、値の調整を行ったようです。

参考:ruby-trunk-changes r56551 - r56558 - PB memo


Use local variable instead of instance variable [ci skip]

rails guideのLayouts and Rendering in Railsの修正です。

Using Partialsの項にあるexampleコードで、partial templateでインスタンス変数を直接参照していたのを、ローカル変数を使用するよう修正しています。