なるようになるブログ

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

rails commit log流し読み(2015/04/09)

2015/04/09分のコミットです。

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

activerecord/CHANGELOG.md


Allow AS::Cache::FileStore#clear without cache directory

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

ActiveSupport::Cache::FileStore#clearメソッド全体にrescue Errno::ENOENTを追加し、clear対象のファイル・ディレクトリが存在しない場合にエラーにならないよう修正しています。

新規にrailsのアプリをクローンした場合等、clear対象のファイル・ディレクトリが無い場合があり、その際にエラーにならないよう対応したとの事です。


Fix uniqueness validation with out of range value

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

build_relationメソッドRangeErrorをrescueし、noneを返すよう修正しています。

class A < ActiveRecord::Base
  PG_MAX_INT = 2147483647
  validates :number, uniqueness: true, inclusion: { 0..PG_MAX_INT }
end

a = A.create(number: (A::PG_MAX_INT + 1))
# before
RangeError: 2147483648 is out of range for ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer with limit 4

# after
a.errors[:number] =>
['is not included in the list']

カラムにinteger型等を使用し、その型の最大値以上の値を指定した場合に、RangeErrorがそのままアプリ側にthrowされてしまっていた為、他のvalidation エラー同様errorsで値を参照出来るようにする為に修正したようです。


Batch touch parent records

ActiveRecordの修正です。

belongs_to associationを使用している場合に、複数レコードに対するtouch処理が一度だけ行われるよう修正しています。

class LineItem < ActiveRecord::Base
  belongs_to :invoice, :touch => true
end
class Invoice < ActiveRecord::Base
  has_many :line_items, :autosave => true
end
line_item = LineItem.create!(amount: 1)
line_item2 = LineItem.create!(amount: 2)
Invoice.create!(line_items: [line_item, line_item2])

# `touch`処理は一度だけ行われる
LineItem.transaction do
  line_item.touch
  line_item2.touch
end

# transaction処理が無い場合、通常通り2回
line_item.touch
line_item2.touch

無駄なqueryが発行されないように、との事で改善したようです。コミットログにAdd more tests and small method rename とあるので、もう少し改善が入りそうな感じです。


fix documentation for SchemaStatements#add_foreign_key

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

foreign keyの名前がRails 4.2.0ではランダムな値だったのが、Rails 4.2.1ではtable名 + カラム名から生成されるようになったのですが、ドキュメントが古いまま(ランダムな値を生成する)になっていたのを、修正しています。


Merge pull request #19633 from y00rb/sort_router_parameters_duplicated_keys

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

マッチするルーティングが無い場合に表示するエラー(UrlGenerationError)用エラーメッセージの生成時にArgumentErrorが発生してしまっていたのを修正しています。

# routes
get 'test/:name', :to => "test#test", :as => 'test'


# console
app.test_path(:foo => 'bar', 'foo' => 'bar')
# => ArgumentError: comparison of Array with Array failed

一つのHashにkeyがSymbolとString混在してしまいエラーになってしまったようで、keyを強制的にStringに変換するよう修正しています。


Merge pull request #19685 from vngrs/actionview_parent_layout_bug

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

親クラスで指定したlayoutが使用されないバグがあったのを修正しています。

class ApplicationController < ActionController::Base
   layout "bootstrap_v1"
end

class HomeController < ActionController::Base
   layout "parallax_v1", only: [:index]
end

上記のコントローラーがあった場合に、HomeControllerindex以外のアクションを作成した場合、親クラスのApplicationControllerで定義したbootstrap_v1がレイアウトに指定されるべきなのですが、親クラスに指定された値が反映されず、デフォルトのレイアウト(application)が使用されてしまう、というバグだったようです。


Disable Active Job intregration tests.

.travis.ymlの修正です。

一時的にActiveJobのテストを無効にしています。

Fix activejob integration test by troter · Pull Request #19470 · rails/rails で対応予定との事です。


A shorter and more concise version of select..size

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

shallow_nesting_depthメソッドで、ネスト数を取得するのにselect(..).sizeを使用していたのを、count(..)を使用するよう修正しています。


redcarpet 3.2.2 has an XSS vulnerability

GemfileGemfile.lockの修正です。

rails guideで使用しているredcarpetのバージョンを3.2.3に更新しています。

3.2.2以下のバージョンにはXSS脆弱性がある為バージョンアップしたとの事です。脆弱性についての詳細はoss-security - redcarpet <=3.2.2 (and related ruby gems) allow for possible XSS via autolinking of untrusted markdown ご参照。