なるようになるブログ

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

rails commit log流し読み(2014/04/18)

2014/04/18分のコミットです。


Bring SQLite3Adpter init API closer to others

sqlite3_adapterの修正です。initializeの引数にconnection_optionsを追加しています。

-      def initialize(connection, logger, config)
+      def initialize(connection, logger, connection_options, config)

他のアダプタ(MySQL/Postgresql)とフォーマットを合わせる為の修正ですね。


Implement to_io as an alias

action_dispatch/http/upload.rb:tempfileのaliasとして:to_ioを追加しています。

to_ioメソッド知らなかったのですが、Objectクラスのメソッドとして定義されているんですね。マニュアルはこちら


Change the method description

上記to_ioの追加の、テストメソッド名を修正しています。


Add CHANGELOG entry for #14755 [ci skip]

上記to_ioの追加について、CHANGELOGに追記しています。


Merge pull request #14738 from tilsammans/pull/11407

hidden_fieldsメソッドで生成されるhtmlからdivタグを削除しています。

HTML 4.01/XHTMLでは、formタグの直下にinputタグを書いてはいけなかったため、生成されるHTMLに<div style="display:none">を追加していましたが、HTML5では直下にinputタグを記載するのがOKなので、divタグを除去している、との事です。


Update Request forgery tests to remove input wrappign div

上記コミットに伴い、Request forgery確認のテストから不要になったdivタグを削除しています。


Remove wrapper div for inputs in button_to

こちらもhidden_fieldsの修正に伴うテストの修正です。button_toメソッドのテストからdivタグを削除しています。


Include default rails protect_from_forgery with: :exception

rails guideの修正です。

CSRFが発生した場合、execeptionを発生させ、適切にハンドリングするのが良いのではないか、という事で、rails guideのprotect_from_forgeryの箇所をprotect_from_forgery with: :exceptionに修正しています。

rails 4.0からデフォルトで生成されるコードもprotect_from_forgery with: :exceptionになっているので、そちらと合わせる形かと。


Optimize select_value, select_values, select_rows and dry up checking whether to exec with cache for Postgresql adapter

Postgresのadapterの修正です。select_value, select_values, select_rowsの最適化が行われています。

共通処理のexecute_and_clearへの切り出し、及び、不要なActiveRecord::Resultの生成を行わないようにしています。

select_valueは8% ips程度の向上(before: 4729.1 (±3.1%) i/s after: 5139.9 (±3.3%) i/s) 、 select_valuesは18%程度の改善(before 2085.1 (±4.3%) i/s after 2476.3 (±4.2%) i/s)したそうです。(あくまで参考値)


Fix spelling and proper nouns

rais guideの修正です。細かなスペルの修正、空白の削除等を行っています。


Singularize association names before camelization

activerecord/lib/active_record/reflection.rbderive_class_nameメソッドで、camelizeする前にsingularizeするよう修正しています。

これだけだと良く分からないので、テストコードを参考に。

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'plural_irregular', 'plurales_irregulares'
end
reflection = AssociationReflection.new(:has_many, 'plurales_irregulares', nil, {}, ActiveRecord::Base)
assert_equal 'PluralIrregular', reflection.class_name

複数の単語が複数形で定義されている場合(上記例だと、plurales_irregulares)に、has_many associationで適切なクラス名が取得出来ず、エラーになってしまっていたのを修正しています。

ActiveSupport::Inflector.inflectionsinflectionのルールの追加が出来るんですね。詳しくはapi.rubyonrails.org参考。


Regression test for irregular inflection on has_many

上記コミットについて、テストコードを追加しています。


:uglify -> :uglifier

rails guideの修正です。asset pipelineの項で、指定するgemの名前が誤っていたのを修正しています。

-config.assets.js_compressor = :uglify
+config.assets.js_compressor = :uglifier

タイポですね。