なるようになるブログ

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

rails commit log流し読み(2014/07/17)

2014/07/17分のコミットです。

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

activesupport/CHANGELOG.md

actionview/CHANGELOG.md

activerecord/CHANGELOG.md


Fix decimal_test module and add new test for object responding to to_d

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

to_dメソッドのテストを追加しています。


Don't accept parameters as argument for redirect to [via @homakov]

actionpack/lib/action_controller/metal/redirecting.rbの修正です。

redirect_toの第一引数にActionController::Parametersクラスの値を指定した場合に、ActionControllerErrorをraiseするよう修正しています。

redirect_to params[:url]という処理を行った時に、

1) XSS using url[status]=200&url[protocol]=javascript&url[f]=%0Aeval(name)

2) way to steal httponly session cookie url[status]=1

という問題が発生する可能性があり、その対応のようです。成る程。


nodoc enum hooks [ci skip]

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

非公開APIに:nodoc:を設定しています。


Revert "Rename to test_mysql_strict_mode_disabled_dont_override_global_sql_mode"

MySQLのConnectionAdapterのテストの修正をrevertしています。

対象のコミットはこちら。2年近く前のコミットですねえ。

MySQL 5.7.4-m14でテストがコケてしまうからrevertしたようです。


Added truncate_words method to activesupport strings

String#truncate_wordsメソッドを追加しています。

文字数ではなく、単語数でtruncate処理を行うメソッドです。任意のセパレータで区切られている部分までを単語として扱って処理しています。セパレータはデフォルトではスペース。

"Hello Big World!".truncate_words(2)
# => "Hello Big..."

"Hello<br>Big<br>World!".truncate_words(2, separator: '<br>')
# => "Hello<br>Big..."

"Hello Big World!".truncate_words(2, omission: "[...]")
# => "Hello Big[...]"

"これは、テスト、メッセージ".truncate_words(2, separator: '')
# "これは、テスト..."

ちょっとおもしろいですね。使い道ありそうな。


Remove unused fixtures

actionpackのtestの修正です。使用していないfixturesを削除しています。


Added PartialIteration class used when rendering collections

actionviewの修正です。

collectionsをrenderする際に使用する為のPartialIterationクラスを追加しています。

render partial: "customer_iteration", collection: [ Customer.new("david"), Customer.new("mary"), Customer.new('christine') ]

上記のようにrenderをした場合に、

# _customer_iteration.erb

<%= customer_iteration_iteration.size %>-<%= customer_iteration_iteration.index %>: <%= customer_iteration.name %><%= '-first' if customer_iteration_iteration.first? %><%= '-last' if customer_iteration_iteration.last? %>

#{template_name}_iteration変数でオブジェクトが呼び出せます。また、first?last?メソッドも使用出来るようになっています。


No need to have a file to PartialIteration class

actionviewPartialIterationクラスの修正です。

上記コミットでPartialIterationクラスをactionpack/lib/action_view/partial_iteration.rbに新規追加していたのですが、他で使用してない為、クラスの定義をactionview/lib/action_view/renderer/partial_renderer.rbに移動しています。

別ファイルのままで良さそうな気もしましたが、railsだとファイル数多くなりすぎるんですかねえ。


Build only one PartialIteration object for loop

まだPartialIterationの修正です。

ループ処理でPartialIterationインスタンスを一度だけ作成するよう改善しています。


Document the PartialIteration object

まだまだPartialIterationの修正です。

PartialIterationクラスの各メソッドにdocを追加しています。


Add CHANGELOG entry for PartialIteration.

そしてPartialIterationの対応について、CHANGELOGに追記しています。


Fix typo on the variable name

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

変数名のタイポを修正しています。


Merge pull request #15718 from chancancode/regression_from_15694

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

クラスメソッドallocateメソッドを使用しています。

allocateメソッドを使用してインスタンスを生成した場合に、処理が大分遅くなってしまっていて、その改善の為の対応との事です。


always transcode the file to utf-8

actionpack/lib/action_dispatch/http/upload.rbの修正です。

Http::UploadedFileクラスのoriginal_filenameエンコードUTF-8を指定しています。

なので、ShiftJISのファイルをアップロードした場合でも、@original_filenameエンコードは必ずUTF-8になっています。


Merge pull request #16183 from goddamnhippie/fix-psych-warning

activerecord/lib/active_record/connection_adapters/postgresql/oid/uuid.rbの修正です。

PostgreSQLのUUID型に不正な値を指定した場合に、nilが設定されるよう対応しています。

バリデーションは、RFC4122に準じています。


extract inner options before delegating to the helper

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

callメソッドにinner optionsを追加しています。helperにdelgateする前にoptionの値を取り除く為のようです。


Merge pull request #15917 from luke-gru/actionview_perf

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

DetailsKey::getメソッドから不要なSet.new処理を削除しています。性能改善。


Use &= instead of select with include?

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

selectとinclude?の組み合わせの代わりに&=を使用するよう修正しています。

-          syms    = Mime::SET.symbols
-          details[:formats] = details[:formats].select { |v|
-            syms.include? v
-          }
+          details[:formats] &= Mime::SET.symbols

性能的には殆ど変わらないのですが、処理的に分り易いよね、という事で修正されています。


Fix typos in string_ext_test.rb [ci skip]

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

テストメソッド名にtypoがあったのを修正しています。


Remove unused 1:1 association :remote option

activerecord/lib/active_record/associations/builder/singular_association.rbの修正です。

使用していない:remoteオプションを削除しています。 pre-1.0からずっとあったオプションらしいです。


we should be checking if the app is a class

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

app_nameメソッドappのクラスチェック処理を修正しています。

本来はapp.is_a?(Class)であるべき箇所が、app.class.is_a?(Class)となってしまっていたようです。


app should always be a class (I suppose)

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

先ほどクラスチェック処理を修正していたのですが、appは必ずクラスだろう、という事で、クラスチェック処理を削除しています。


Rails-ish apps should descend from Rails::Railtie

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

appにroutesメソッドが定義されてるかどうかチェックしていたのを、クラスでチェックするよう修正しています

-            return unless app.respond_to?(:routes)
+            return unless app.is_a?(Class) && app < Rails::Railtie

Module#< のチェックの仕方を初めて知りました。比較演算子で継承関係確認出来るんですねえ。


push rails app testing up

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

appのチェック処理を一度だけ行うよう修正しています。


we do not need to dup the options hash, it is private and a new object each call

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

不要なdup処理を削除しています。


only extract :params from the options hash once

actionpack/lib/action_dispatch/http/url.rbの修正です。

Hashのparamsキーの参照を一度だけ行うよう修正しています。


break out path building logic to methods

actionpack/lib/action_dispatch/http/url.rbの修正です。

パラメータの組み立て処理をメソッドに切り出しています。


extract path building to a method

actionpack/lib/action_dispatch/http/url.rbの修正です。

pathの組み立て処理をpath_forメソッドからurl_forメソッドに移動しています。


subclass Rails::Engine

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

テストで使用するappをRails::Engineのサブクラスにしています。


Fix broken list formatting [ci skip]

actionview/lib/action_view/helpers/rendering_helper.rbのdocの修正です。

RenderingHelperのdocのlist formatが壊れてしまっていたのを、修正しています。


Remove need for macro instance var

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

インスタンス変数のmacroを削除して、代わりにmacroメソッドを追加しています。

associationが設定されてない場合にNotImplementedErrorをraise出来るように、メソッド変えたようです。


Remove "profile and benchmark" line from command line guide

rails guideのThe Rails Command Lineの修正です。

"profile and benchmark"行を削除しています。

プロファイリング用ツールベンチマーク用のツールも提供されて無いので削除しています。