なるようになるブログ

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

rails commit log流し読み(2016/01/07)

2016/01/07分のコミットです。

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

actionpack/CHANGELOG.md


[close #22917] Don't output to STDOUT twice https://github.com/rails/rails/commit/3d10d9d6c3b831fe9632c43a0ffec46104f912a7

Active Supportの修正です。

loggerの出力先にSTDOUTを指定していた場合に、rails consolerails serverを使用した場合に同じログが2回 STDOUTに出てしまう問題があったのを対応しています。

railsのデフォルトの挙動として、ActiveSupportLogger.broadcastを使用してloggerに設定した出力先 + STDOUTにログを出力するようになっていた為問題が発生していたようです。loggerの出力先がSTDOUTになっている場合に、ActiveSupportLogger.broadcastを使用してのログ出力を行わないようチェック処理を追加し対応しています。


Remove unused instance variable

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

使用していないインスタンス変数を削除しています。


Refactor connection.insert_sql

Active Recordの修正です。

#insert_sqlメソッド#insertメソッドリファクタリングを行っています。

処理がほぼ同じ内容だった為、処理を#insert_sqlによせて、#insert#insert_sqlを呼び出すだけにしているようです。


Remove delete_sql in sqlite3 adapter

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

SQLite3Adapter#delete_sqlメソッドを削除しています。

データ全てを対象にする為に、sqlWHERE 1=1"を追加するよう実装されていたのですが、現状のsqlite3ではこのようなハックは不要な為、削除したようです。


Typo in Contributing.md documentation

rails guideのHow to contribute to Ruby on Railsの修正です。

Did you find a bug?のグラマーの修正を行っています。


Suppress warning (instance variable @persisted not initialized)

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

テスト内で@persistedが初期化されてないのに使用していた事によりRubyのwarningが出てしまっていたので、persistedの初期化処理を追加し対応しています。


Allow AC::Parameters as an argument to url_helpers

actionpack/lib/action_dispatch/routing/route_set.rbの修正です。

URL helper methodsにActionController::Parametersインスタンスを渡せるよう修正しています。なお、permitされてない値が渡された場合は、ArgumentErrorがraiseするようになっています。


Remove splat operator warning from ssl_test

actionpack/test/dispatch/ssl_test.rbの修正です。

sslのテストで、*' interpreted as argument prefixのワーニングが出ていたので、メソッド呼び出すに丸括弧を追加し対応しています。

-    assert_cookies *DEFAULT.split("\n")
+    assert_cookies(*DEFAULT.split("\n"))

Kept overridden root method and removed original method

actionpack/lib/action_dispatch/routing/mapper.rbの修正です。

ActionDispatch::Routing::Mapper::Base#rootメソッドを削除、及びActionDispatch::Routing::Mapper::Base#rootメソッドにあったdocをActionDispatch::Routing::Resources#rootに移動しています。

元々はBases#rootで処理を実装していたのですが、のちほどResources#rootメソッドをオーバーライドするようになり、実際の処理はResources#rootで行われるようになっていました。

これにより、Base#rootのdocに書いてある内容は実際はResources#rootで実装される、という状態になってしまい、実装とdocが離れてしまった為、実際に実装があるResources#rootにdocを移動し、Base#rootメソッドは削除(Base#rootで行っていた処理は別メソッドに移動)する、という対応を行っています。


Merge pull request #22949 from schneems/schneems/request-id

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

新規railsアプリでは、production環境でログにrequest_idを出力するようデフォルトの設定を変更しています。

request_idが無い状態だと、複数のリクエストが同時に発生した場合に、どのリクエストによるログがわかりずらい為、デフォルトでrequest_idを設定するようにしてしまって良いのでは、という事で変更になったようです。

request_idありなしのログの違いは下記のような感じ。

# `request_id`無し
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:21 +0000
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:22 +0000
Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:23 +0000
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Processing by WelcomeController#index as HTML
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
Processing by WelcomeController#index as HTML
  Rendered welcome/index.html.erb within layouts/application (0.1ms)
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
  Processing by WelcomeController#index as HTML
Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
# `request_id`あり
[c6034478-4026-4ded-9e3c-088c76d056f1] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:21 +0000
[c6034478-4026-4ded-9e3c-088c76d056f1]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:22 +0000
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c] Started GET "/" for 72.48.77.213 at 2016-01-06 20:30:23 +0000
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[c6034478-4026-4ded-9e3c-088c76d056f1] Processing by WelcomeController#index as HTML
[c6034478-4026-4ded-9e3c-088c76d056f1] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Processing by WelcomeController#index as HTML
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ]  Rendered welcome/index.html.erb within layouts/application (0.1ms)
[abuqw781-5026-6ded-7e2v-788c7md0L6fQ] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c]  Processing by WelcomeController#index as HTML
[acfab2a7-f1b7-4e15-8bf6-cdaa008d102c] Completed 200 OK in 5ms (Views: 3.8ms | ActiveRecord: 0.0ms)

Better error message when running rake routes with CONTROLLER arg:

actionpack/lib/action_dispatch/routing/inspector.rbの修正です。

rake routesコマンドで、CONTROLLER引数に指定されたcontrollerが存在しなかったエラーメッセージが、その旨わかるよう改善しています。

# before
$ ./bin/rails routes CONTROLLER=MissingController
You don't have any routes defined!

Please add some routes in config/routes.rb.

For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.
# after
$ ./bin/rails routes CONTROLLER=MissingController
The controller MissingController does not exist!
For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.

合わせて、CONTROLLER引数に複数の形式(Rails::WelcomeController, Rails::Welcome, rails/welcome)で値をわたせるよう対応しています。