なるようになるブログ

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

rails commit log流し読み(2016/09/14)

2016/09/14分のコミットです。

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

activerecord/CHANGELOG.md


Merge pull request #26466 from y-yagi/remove_duplicated_fixture_set_names

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

fixture fileのパスを取得した際に、重複したパスを削除するよう修正しています。

取得したパスを元にして、define_methodでfixture用のメソッドを定義しているのですが、重複したパスがそのままだと同じメソッド名のメソッドを複数定義してしまい、Rubyのwarning(warning: method redefined)が出てしまうため、同じ名前のメソッドが定義されるのを避ける為にパスを取得した時点で重複した値を削除するようにしています。


Merge pull request #26314 from frodsan/puma-ar-disconnect

railties/lib/rails/generators/rails/app/templates/config/puma.rbの修正です。

rails newした際に生成されるpumaの設定ファイルの雛形に、before_fork時にActiveRecord::Base.connection_pool.disconnect!を呼ぶexampleコードを追加しています。

# before_fork do
#   ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end

preloadingを使用している場合、forkする為にconnectionをcloseしないと、connectionのleakが発生してしまう可能性があるため、との事です。

参考:disconnect from connection pool before forking still relevant? · Issue #1001 · puma/puma


5-0-backport: activerecord/mysql2: Avoid setting @connection to nil, just close it (#26473)

activerecord/CHANGELOG.mdの修正です。

先日コミットされた、ActiveRecord::ConnectionAdapters::Mysql2Adapter#disconnect!でconnectionのclose処理後、@connectionnilを設定していたのを、設定しないよう修正した対応についてCHANGELOGにentryを追加しています。


Address warning: ambiguous first argument; put parentheses or a space even after/' operator`

activerecord/test/cases/adapters/mysql2/connection_test.rbの修正です。

テスト内でRubyのwarning(warning: ambiguous first argument; put parentheses or a space even after/' operator)が出ていたので、assert_matchの引数を指定する際に()`を指定するようにして対応しています。


Do not point to the 5-0-stable branch

railties/lib/rails/generators/app_base.rbの修正です。

rails newedgeオプションを指定した場合に、gemの指定にbranch: 5-0-stableが指定されてしまっていたのを、ブランチ名は指定しないよう修正しています。

edgeオプションを指定した場合は、master ブランチが参照されるのが正しいため。


fix broken generators test

railties/test/generators/app_generator_test.rbrailties/test/generators/plugin_generator_test.rbの修正です。

先のrails newedgeオプションを指定した場合にmasterブランチを参照するよう修正した対応の影響でコケてしまったテストがあったのを修正しています。


Move comment about disconnecting pool close to comment about preload

railties/lib/rails/generators/rails/app/templates/config/puma.rbの修正です。

先に追加されたbefore_fork時にActiveRecord::Base.connection_pool.disconnect!を呼ぶexampleを、on_worker_bootのcallbackのexampleの前に移動しています。before_forkの方が先に実行されるブロックのため。


Fix broken comments indentation caused by rubocop auto-correct [ci skip]

rubocopの対応(normalizes indentation and whitespace across the project · rails/rails@80e66cc)でコメントのインデントも調整されてしまっていたのを、Style/CommentIndentationの設定を追加しコメントの位置はメソッドの位置と揃うよう調整しています。


Override the github git source instead of changing manually all entries

Gemfileの修正です。

Use :git for specifying dependencies from github with https protocolGemfileでgem先の指定にgithubショートハンドを使用していたのを明示的にhttpsのURLを指定するよう修正したのですが、再度githubショートハンドを使用するよう修正しています。

合わせて、warningが出ないようGemfileの中でgithubショートハンドを使用した場合httpsプロトコルを使用するようオーバーライドするよう処理を追加しています。

処理内容は下記の通り。

# Gemfile
git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end

Fix test for the edge generator

railties/test/generators/app_generator_test.rbの修正です。

先のrails newedgeオプションを指定した場合にmasterブランチを参照するよう修正した対応の影響でコケてしまったテストがあったのを修正しています。