なるようになるブログ

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

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

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

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

actionview/CHANGELOG.md

activerecord/CHANGELOG.md


Merge pull request #21791 from sonalkr132/persistence-doc

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

ActiveRecord::Persistence moduleのdocのグラマーの修正を行っています。


Fix typos in asset_pipeline.md

rails guideのThe Asset Pipelineの修正です。

guide内に複数あったタイポをまとめて修正しています。


Update ActiveJob adapter for sucker_punch 2.0

Active Jobの修正です。

sucker_punch 2.0のAPIに合わせてSuckerPunchAdapterクラスを修正しています。

sucker_punch 2.0では、async.performperform_asyncに変更、及び遅延処理用のメソッド(perform_in)が追加されており、これによりsucker_punchでもenqueue_atメソッドが使用出来るようになっています。


Do not use default attributes for STI when instantiating a subclass

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

STIを使用している、かつ、typeにデフォルト値を設定しているクラスがある場合に、その子クラスのインスタンス生成処理でエラーになってしまうバグがあったのを修正しています。

issueより。

ActiveRecord::Schema.define do
  create_table :resources, force: :cascade do |t|
    t.string   :type,       null: false, default: 'Resource'
    t.datetime :created_at, null: false
    t.datetime :updated_at, null: false
  end
end

class Resource < ActiveRecord::Base
end

class Channel < Resource
end

Channel.new # => ActiveRecord::SubclassNotFound: Invalid single-table inheritance type: Resource is not a subclass of Channel

子クラスのインスタンス生成時には、defaultの値を使用しないよう対応しています。


Fix img alt attribute generation when using Sprockets >= 3.0

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

Sprockets 3系ではdigestの生成にMD5ではなくSHA256を使用するようになりました。その為、生成digestの桁数が64桁になったのですが、image_altメソッドでその事の考慮が入っていなかった為、digestが64桁でも正しくaltを生成出来るよう修正しています。

      def image_alt(src)
-        File.basename(src, '.*'.freeze).sub(/-[[:xdigit:]]{32}\z/, ''.freeze).tr('-_'.freeze, ' '.freeze).capitalize
+        File.basename(src, '.*'.freeze).sub(/-[[:xdigit:]]{32,64}\z/, ''.freeze).tr('-_'.freeze, ' '.freeze).capitalize
       end

Fix typo in strong params hash deprecation message

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

StrongParameterで使用できなくなったメソッドを使用した場合に出力されるdeprecatedメッセージで、vulnerabilityvulunerabilityにタイポしている箇所があったのを修正しています。


Add tests to #23288

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

先ほどコミットされたimage_altの対応について、テストを追加しています。


Remove celluloid from the Gemfile

Gemfileの修正です。

先ほどコミットされたsucker_punchの2.0対応で、誤ってGemfileにcelluloid追加されてしまったので、削除しています。


Update sucker_punch adapter's description

activejob/lib/active_job/queue_adapters/sucker_punch_adapter.rbのdocの修正です。

SuckerPunchAdapterクラスのdoc内に、celluloidを使用している旨説明があったのですが、sucker_punch 2系dではcelluloidを使用していないで、該当箇所を修正しています。


change @text_xml_idx to an lvar and cache it on the stack

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

text/xmlのindex管理にインスタンス変数を使用していたのを、ローカル変数を使用するよう修正しています。

インスタンス変数の参照はメソッド経由で行っており、値が初期化されてるかどうかの確認の為毎回||=が実行されていたのですが、この対応によりインスタンス変数を減らせる + ||=のチェックも無くせる為との事です。


change @app_xml_idx to an lvar and cache it on the stack

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

Mime[:xml]のindex管理にインスタンス変数を使用していたのを、ローカル変数を使用するよう修正しています。 上記はほぼ同上。


remove useless private methods

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

[]メソッドのaliasとしてtext_xmlapp_xmlメソッドを定義していたのを削除し、[]メソッドを使用するよう修正しています。


remove == from AcceptItem

Mime::Type::AcceptItem#==メソッドを削除しています。

Mime::Type::AcceptItem#==メソッドではnameの比較処理のみ行っており、オブジェクトの同一性のチェックを行ってない、かつ、nameからitemを取得したい時にだけ利用しており、それようの別メソッドを作成すれば済む為、別途find_item_by_nameメソッドを追加し、Mime::Type::AcceptItemは削除を行っています。


English explanation to multi-level nested join

rails guideのActive Record Query Interfaceの修正です。

Joining Nested Associations (Multiple Level)の項に、他の項同様に英語でのJOIN処理の説明を追加しています。


Merge pull request #18928 from bogdan/unreversable-order

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

ActiveRecord::Relation#reverse_orderがreverse出来ない場合、及びprimary keyが無いテーブルで対してメソッドを使用した場合に、ActiveRecord::IrreversibleOrderErrorをthrowするよう修正しています。

元々、ActiveRecord::Relation#reverse_orderはとてもシンプル実装になっており、正しく実行出来ないようなSQLを生成してしまう事もあったのですが、多少厳密にチェックを行い、単純にreverse出来ないような処理の場合に、不正なSQLを生成する代わりにエラーをthrowするように処理が変更になっています。

例(CHANGELOGより)。

Topic.order("concat(author_name, title)").reverse_order
# Before: SELECT `topics`.* FROM `topics` ORDER BY concat(author_name DESC, title) DESC
# After: raises ActiveRecord::IrreversibleOrderError

Edge.all.reverse_order
  # Before: SELECT `edges`.* FROM `edges` ORDER BY `edges`.`` DESC
  # After: raises ActiveRecord::IrreversibleOrderError

Consistently warn that passing an offset to find_nth is deprecated

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

Merge pull request #22053 from Empact/first-loaded · rails/rails@0d2675ffind_nthoffsetを渡すのがdeprecateになったのですが、recordがload済みの場合にfind_nthoffsetを渡した場合でもdeprecated messageが出ないようになってしまっていました。

で、これを、recordがload済みの場合にもdeprecated messageを出すよう修正しています。


:arrow_left: indentation

activesupport/lib/active_support/core_ext/module/deprecation.rbのdocの修正です。

deprecateメソッドのdoc内のexampleのインデントがおかしくなっていたのを修正しています。


Merge pull request #23237 from gsamokovarov/new-welcome-page

railtiesの修正です。

welcome pageのデザインをリニューアルしています。

old

rails_welcome.png (789×592)

new

rails_welcome.png (1154×1110)

大分シンプルなページになりました。


Fix a bug with initialize schema_migrations table

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

schema_migrations テーブル用のinsert分のエスケープ処理に誤りがあり、データ挿入時にエラーになってしまうバグがあったのを修正しています。

-          execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| '(#{v})'}.join(', ') }"
+          execute "INSERT INTO #{sm_table} (version) VALUES #{inserting.map {|v| "('#{v}')"}.join(', ') }"