なるようになるブログ

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

rails commit log流し読み(2014/05/27)

2014/05/27分のコミットです。

CHANGELOGにのったコミットは以下の通りです(詳細は本文参照)。

activerecord/CHANGELOG.md

railties/CHANGELOG.md


Add missing test case for quoting behavior

DBAdapterのテストケースの追加です。

クォートされた値を引数に指定した場合のテストを追加しています。

テストを見て気付いたのですが、findメソッドで文字列でも動作するんですね。

Todo.find("1-a") # SELECT  "todos".* FROM "todos" WHERE "todos"."id" = ? LIMIT 1  [["id", 1]]

うーん。エラーになって欲しい気もする。


print generators on failed generate

railties/lib/rails/generators.rbの修正です。

generate失敗時に出力するエラーメッセージが改善されています。前回revertされたのが、再度コミットされたようです。

# before
  rails g migrate add_click_to_issue_assignment

  # Could not find generator migrate.

# after

  rails g migrate add_click_to_issue_assignment

# Could not find generator 'migrate'. Please choose a generator below.
# Rails:
#   assets
#   controller
#   generator
#   helper
#   integration_test
#   jbuilder
#   mailer
#   migration
#   model
#   resource
#   scaffold
#   scaffold_controller
#   task
#
# Coffee:
#   coffee:assets
#
# Jquery:
#   jquery:install
#
# Js:
#   js:assets
#
# TestUnit:
#   test_unit:generator
#   test_unit:plugin

便利。


Remove checks against column.type in abstract adapter quoting

ConnectionAdaptersの修正です。

クォート処理を改善しているのは判るのですが、理由は良く分かりませんでした…。


remove unwanted to_sym call.

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

不要なto_symメソッドを削除しています。


Refactor the type casting of booleans in MySQL

MySQLのConnectionAdapterの修正です。

unquoted_trueが1を、unquoted_falseが0を返すようメソッドを追加しています。MySQLのBoolean型って、TINYINT(1)と等価だった筈なので、その為でしょうか。


Correct Documentation for asset_tag_helpers

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

生成されるHTMLのパスが誤っていたのを修正しています。


update the recommended ruby version

railties/lib/rails/ruby_version_check.rbの修正です。

Rubyの推奨バージョンが2.0から2.1 or newerに修正されています。


correct doc for (audio|video)_tag [ci skip]

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

audio_tagvideo_tagで生成されるHTMLのサンプルが誤っていたのを修正しています。


Escape user input before showing in the page.

actionpack/lib/action_dispatch/middleware/templates/routes/_table.html.erbの修正です。

ユーザがインプットした値のエスケープ処理が抜けてたのを追加しています。

ルーティングエラー時に表示される画面なので、本番環境で表示される事は無いはずなので、セキュリティ上は問題無い、という見解です。


Skip individual tests upon Dalli::RingError

actionpack/test/dispatch/session/mem_cache_store_test.rbの修正です。

各テストケース毎にrescue Dalli::RingErrorを追加して、エラーが起きた際に詳細情報表示するよう修正しています。


correct docs for (asset|image)_path [ci skip]

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

asset_pathimage_pathメソッドで生成されるHTMLのサンプルが誤っていたのを修正しています。


Refactor the handling of arrays in where predicates

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

配列の扱いについてリファクタリング


Refactoring .reflections public method.

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

reflectionsメソッドリファクタリングしています。

has_and_belongs_to_manyを使用していた場合に、内部的にはhas_manyとして扱っていたので、reflectionsメソッドで確認した場合にhas_manyと表示されてしまっていたとの事です。

今回のリファクタリングhas_and_belongs_to_manyと表示されるよう修正しています。


[ci skip] Add benchmark your code section to contributing to ruby on rails guide.

rails guideのContributing to Ruby on Railsの修正です。

ベンチマークのとり方についての説明を追加しています。

benchmark/ipsを使用した場合のサンプルですね。便利。


Extract types which don't require additional typecasting to a method

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

type cast処理が不要な型については、cast処理を行わないよう修正しています。


Allow empty arrays in where predicates

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

whereメソッドで空配列を許容するよう修正しています。


Add a public API to allow users to specify column types

column typeにユーザが任意のクラスを指定出来るよう修正しています。

docから抜粋。

# db/schema.rb
create_table :store_listings, force: true do |t|
  t.decimal :price_in_cents
end

# app/models/store_listing.rb
class StoreListing < ActiveRecord::Base
end

store_listing = StoreListing.new(price_in_cents: '10.1')

# before
store_listing.price_in_cents # => BigDecimal.new(10.1)

class StoreListing < ActiveRecord::Base
  property :price_in_cents, Type::Integer.new
end

# after
store_listing.price_in_cents # => 10

独自クラスを指定する事も当然可能。

class MoneyType < ActiveRecord::Type::Integer
  def type_cast(value)
    if value.include?('$')
      price_in_dollars = value.gsub(/\$/, '').to_f
      price_in_dollars * 100
    else
      value.to_i
    end
  end
end

class StoreListing < ActiveRecord::Base
  property :price_in_cents, MoneyType.new
end

継承するAPIについてはActiveRecord::Properties::Type::Valueを参照。

なお、マージされた後にDHHが登場して、まだPRで議論が続いています。修正が入りそうな感じかなあ。


Replace double quotes with single quotes while adding an entry into Gemfile

railties/lib/rails/generators/actions.rbの修正です。

Gemfileに記載される文字列について、ダブルクォートからシングルクォートに変換しています。


Add description of ActionMailer::TestHelper module [ci skip]

ActionMailer::TestHelperの修正です。docを追加しています。


Use "Action Mailer" as canonical name in documentation [ci skip]

ActionMailer::TestHelperの修正です。

直ぐ上のコミットで追加されたdocをActionMailer -> Action Mailerに修正しています。


Remove unnecessary branch from quoting in Mysql

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

不要なクォート処理を削除しています。


Pass through AM documentation re: 02d048d [ci skip]

actionmailer/lib/action_mailer/base.rbのdocの修正です。

こちらでもActionMailer -> Action Mailerに修正しています。


Typo in AR CHANGELOG [ci skip]

activerecord/CHANGELOG.mdの修正です。

typoの修正。


Merge pull request #15301 from zzak/issue_15212

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

associationがロード済みの場合に、処理をスキップするよう修正しています。


Add test case for b13d260

activerecord/test/cases/associations/eager_test.rbへのテストの追加です。

このコミットに対するテストですね。


Move test to the proper file

ActiveRecordのテストの修正です。

preloadeのテストをactiverecord/test/cases/associations/eager_test.rbに移動しています。


Fix syntax error from 5eae77c

activerecord/test/cases/associations/eager_test.rbの修正です。

doが抜けてたのを追加しています。


Remove require 'active_support' from individual modules

ActiveSupportのmoduleから、require "active_support"を削除しています。

ActiveSupportのmoduleを使用したい場合、ユーザが最初にrequire "active_support"するようにとの事です。rails guide参照。


Fix redefine a has_and_belongs_to_many inside inherited class

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

同じhas_an_belongs_to_manyを複数回定義した場合に、エラーになるバグを修正しています。

継承関係がある場合に、継承先のクラスで同じhas_and_belongs_to_manyを定義した際に保存出来ない、というのがまずいのか。


Deprecate decimal columns being automatically treated as integers

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

現状、decimalについてはintegerとして取り扱うように内部的にはなっているのですが、将来これを辞めるらしく、deprecateのメッセージを出力するよう修正しています。