なるようになるブログ

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

rails commit log流し読み(2016/02/13)

2016/02/13分のコミットです。

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

activerecord/CHANGELOG.md


use rails instead of rake

actionpack/CHANGELOG.mdactiverecord/CHANGELOG.mdの修正です。

CHANGELOG内のexampleコードで、rakeコマンドを使用している箇所があったのをrailsコマンドを使用するよう修正しています。


[ci skip] Fix enqueuing spelling to maintain consistency

Active Jobのdocの修正です。

doc内でenqueueingと記載していた箇所をenqueuingを使用するよう修正しています。

enqueueingが間違いという訳では無いのですが、module名にEnqueuingを使用している為、enqueuingを使用するよう統一したとの事です。


Use correct path in documentation.

docの修正です。

doc内でproduction.rbのpathがconfig/production.rbになってしまっている箇所があったのをconfig/environments/production.rbにまとめて修正しています。


Flesh out request encoding + response parsing changelog entry.

actionpack/CHANGELOG.mdの修正です。

ActionDispatch::IntegrationTestのbody parse処理についての詳細な説明を追加しています。


Add fixes accidentally removed.

Action Packの修正です。

先日行われたActionDispatch::IntegrationTestのbody parse処理に関するコミットで、諸々ミスがあったのをまとめて修正しています。


Merge pull request #23611 from abhishekjain16/routes_options

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

rails routesタスクの-g(grep)オプションでgrepする対象がcontrollerとactionだけだったのを、verb、name、pathもgrepするよう修正しています。


use kwargs to avoid hash slicing

actionview/lib/action_view/digestor.rbの修正です。

ActionView::Digestor.newメソッドの引数がoptions hashだけだったのを、必須パラメータ(namefinder)はキーワード引数を使用するよう修正しています。


use assert_not_equal so there will be better error messages

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

値が一致しない事を確認するテストのassertionにassertを使用していたのを、assert_not_equalを使用するよう修正しています。assert_not_equalを使用した方が、エラーになった際のエラーメッセージがわかりやすい為、との事です。

-      assert previous_digest != digest(template_name, options), "digest didn't change"
+      assert_not_equal previous_digest, digest(template_name, options), "digest didn't change"

Don't search in locals for cache_options.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

ActionView::CollectionCaching.fetch_or_cache_partialメソッドcache_optionsをlocalsから取得していたのを止めてします。

top levelのcache_optionsのみサポートしている為、との事です。


Remove single_template_render? method.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

@templateを返すだけのsingle_template_render?メソッドを削除し、直接@templateを参照するよう修正しています。


use a real LookupContext in the digest tests

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

digestのテストで、templateのfind処理をテスト用の独自実装で行っていたのを、ActionView::LookupContextを使用するよう修正しています。


the lookup context looks in the cwd, so prefix isn't necessary

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

FixtureFinder.newメソッドActionView::LookupContextインスタンスを生成する際、prefixは指定しないよう修正しています。

cwdで処理を行う際はprefixは不要な為。


Test collection caching with callable cache key.

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

cache keyにProcを指定した場合にcollection cachingが正しく行われる事のテストを追加しています。


Remove useless callable_cache_key? check. https://github.com/rails/rails/commit/61b03f37d8117c71ede59b335e493fd8016c414a

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

ActionView::CollectionCaching.automatic_cache_eligible?メソッドからcallable_cache_key?のチェック処理を削除しています。

automatic_cache_eligible?が呼ばれるのが@optionsから:cache keyが取得出来なかったときだけで、その場合callable_cache_key?は必ずfalseになる為、チェックする必要が無い為、との事です。


Use Ruby 1.9 hash syntax

railties/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.ttの修正です。

application_controller.rbのテンプレートファイルで、protect_from_forgeryメソッドの引数の指定にRuby 1.9のHash記法を使用するよう修正しています。


Check partial_rendered_times to clarify expectations.

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

cacheから値を読み込んだ際に順序が保持されている事を確認するテストで、partial_rendered_timesの値もチェックするよう修正しています。


Only write to collection cache if we have a callable cache key.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

ActionView::CollectionCaching.fetch_or_cache_partialメソッドで呼び出し可能なcache keyを保持している場合のみ、collection cacheの書き込みを行うよう修正しています。


Write to collection cache where the template is rendered.

actionview/lib/action_view/renderer/partial_renderer.rbactionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

collection cacheの書き込み処理をtemplateのrender処理を行っているメソッドと同じメソッドで呼び出すよう修正しています。

local template 変数にアクセスしている処理をまとめるためのようです。


Inline fetch_or_cache_partial.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

partialのcacheまたはfetch処理を行うfetch_or_cache_partialメソッドを削除し、メソッドで行っていた処理は呼び出し元でそのまま行ってしまうよう修正しています。


Stop mutating return value.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

rendered partialsの値を取得するのにdup + shiftを使用していたのを、indexを指定し取得するよう修正しています。

-        rendered_partials = @collection.any? ? yield.dup : []
+        rendered_partials = @collection.any? ? yield : []

+        index = 0
         keyed_collection.map do |cache_key, _|
           cached_partials.fetch(cache_key) do
-            rendered_partials.shift
+            rendered_partials[index].tap { index += 1 }
           end

rendered_partialsはArrayであり、参照する為に値を変異させる必要は無い為、


Prefer empty? to any?.

actionview/lib/action_view/renderer/partial_renderer/collection_caching.rbの修正です。

cache_collection_renderメソッドで、collectionに値があるかどうかチェックするのにany?を使用していたのを、empty?を使用するよう修正しています。

-        rendered_partials = @collection.any? ? yield : []
+        rendered_partials = @collection.empty? ? [] : yield

不要なループ処理を減らす為のようです。


Fix expected hash syntax.

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

Use Ruby 1.9 hash syntaxapplication_controller.rbのテンプレートファイルで、protect_from_forgeryメソッドの引数の指定にRuby 1.9のHash記法を使用するよう修正したのですが、テストのほうの修正が漏れていた為、テストについても同様に修正しています。


push kwargs up to the user facing API

Action Viewの修正です。

ActionView::Digestor.newメソッドの引数にキーワード引数を使用していたのをやめて、ユーザが実際に使用するAPI(ActionView::Digestor.digestメソッド)の引数にキーワード引数を使用するよう修正しています。


Make ActiveRecord::Relation#last to reverse SQL order

Active Recordの修正です。

Revert "Merge pull request #16400 from bogdan/last-with-sql" でrevertされたActiveRecord::Relation#lastリファクタリングを再度コミットしています。

  1. relationがロード済みの場合、SQLは発行せずロード済みの値を使用するよう修正
  2. relationにlimitを指定していない場合、relationをロードせずreverse order SQLを使用するよう修正
  3. 自動的にreverse出来ないようなSQLを発行するのはdeprecateになった(Rails 5.1ではActiveRecord::IrreversibleOrderErrorがthrowされる)

CHANGELOより。

Topic.order("title").load.last(3)
  # before: SELECT ...
  # after: No SQL

Topic.order("title").last
  # before: SELECT * FROM `topics`
  # after:  SELECT * FROM `topics` ORDER BY `topics`.`title` DESC LIMIT 1

Topic.order("coalesce(author, title)").last
  # before: SELECT * FROM `topics`
  # after:  Deprecation Warning for irreversible order

Add the missing author name [ci skip]

activerecord/CHANGELOG.mdの修正です。

Allow joins to be unscoped. の対応のentryで対応者名が記載されてなかったので、追記しています。


Fix grammar a to an [ci skip]

docの修正です。

冠詞にanを使うべきところでaを使ってしまっていた箇所を、まとめてanに修正しています。


add missing name option to flash test example [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

Testing flash noticesの項で、テスト名を指定してテストを実行するexampleで、オプション(-n)の指定が漏れていたのを追加しています。