なるようになるブログ

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

rails commit log流し読み(2017/02/02)

2017/02/02分のコミットです。

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


explicitly require listen in EventedFileUpdateCheckerTest (#27867)

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

EventedFileUpdateCheckerのテストの前処理でlistenをrequireするよう修正しています。後処理でlistenのメソッドを使用している為。


Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+

Active Recordの修正です。

migrationにMySQLのgenerated columns、及び、MariaDBのvirtual columnsを使用出来るよう対応しています。virtualメソッドを使用する事で定義出来るようになっています。

CHANGELOGより。

create_table :generated_columns do |t|
  t.string  :name
  t.virtual :upper_name,  type: :string,  as: "UPPER(name)"
  t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true
  t.index :name_length  # May be indexed, too!
end

storedオプションを指定すると、実データが保持される(STOREDキーワードが指定された状態)ようになります。

参考:


bin/test for Active Job and Action Cable tests

actioncable/bin/testactivejob/bin/testの修正です。

Action Cable、Active Jobのテストにtest runnerを使用する為のbin/testスクリプトを追加しています。


DRY fake models for testing

actionview/test/actionpack/controller/render_test.rbactionview/test/lib/controller/fake_models.rbの修正です。

renderのテストで使用するテスト用のmodelを、テストファイルに直接定義していたのを、他と合わせてmodel定義用のファイル(fake_models.rb)で定義するよう修正しています。


module Blog; class Post appears twice in AV tests

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

polymorphic routesのテストで使用するテスト用のmodelのmodule名をBlog -> Weblogに修正しています。同名のmoduleが別の箇所で使われており、名前がバッティングするのを避ける為にこちらを変更したようです。


Properly escape test names

actionpack/test/journey/path/pattern_test.rbの修正です。

path patternのテストを動的に定義する際に、テスト名をRegexp.escapeでescapeするよう修正しています。

-          define_method(:"test_to_regexp_#{path}") do
+          define_method(:"test_to_regexp_#{Regexp.escape(path)}") do

pathには正規表現が含まれおり、escapeせずに値を使用するとRegexpErrorが発生してしまう事がある為、との事です。再現しなかった…。


Fix test failures only seen when executed via bin/test

actionview/test/template/render_test.rbの修正です。

sub_template_messageメソッドのテストで、sub_template_messageの戻り値からRails.rootの値を消すよう修正しています。

-    assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb")}", e.sub_template_message
+    assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb").sub("#{Rails.root}/", "")}", e.sub_template_message

sub_template_messageの戻り値はRails.rootにより変わるようになっています。また、bin/testでテストを実行するとRails.rootが定義された状態になります。そのため、bin/testでテストを実行した場合とrakeでテストを実行した場合とで結果が変わる事になり、その差異を無くす為に、Rails.rootの値を消すよう修正したようです。

が、rake経由でテストを実行した場合、そもそもRails.rootが定義されておらず、NoMethodErrorでエラーになってしまう為、後ほどassert_matchを使用するよう修正しています。


Fix CI failure caused by aa647b46cce55ec12f5895e403c0d1b85502c8e0

actionview/test/template/render_test.rbの修正です。

さきほどのコミットによりCI上でテストが壊れるようになってしまった為、Rails.rootを消すのではなく、正規表現で確認するよう修正しています。

-    assert_equal "Trace of template inclusion: #{File.expand_path("#{FIXTURE_LOAD_PATH}/test/sub_template_raise.html.erb").sub("#{Rails.root}/", "")}", e.sub_template_message
+    assert_match %r{Trace of template inclusion: .*test/sub_template_raise.html.erb}, e.sub_template_message