なるようになるブログ

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

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

2年越しのバグが修正されたたり、routing error画面の修正が入ったり、割と盛りだくさん。

個人的には、asset precompileの設定がinitializerに移動した修正が嬉しいえす。


Fix error for aggregate methods with select, see issue #13648

selectメソッドと一緒にaggregate methods(empty?, any?, count) を呼び出し際に、rails4.1からエラーになっていたのを、エラーにならないよう修正しています。

具体的には以下のような感じですね。

posts = Post.select(:title, :body)
posts.count # ここでエラー

selectで複数カラム指定している状態でCOUNTを呼び出しているので、SQLの構文エラーになります。

Postgreだと下記エラーがおきます。

ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR:  function count(integer, character varying) does not exist

SQL的に考えると正しい動きのような気もしますが、rails 4.0.xまでは正常に動いていたようなので、動くよう処理を直しています。

[追記]countを呼び出した際にSQL構文エラーになるのは変わらないのですが、aggregate methods(empty?, any?, count) でエラーにならないよう、対応、が正しいです。なので、sizeだと正常に値が取得出来ます。[/追記]


Merge pull request #11656 from emre-basala/xml_mini_test

ActiveSupport:XmlMini#to_tagのテストコードを追加しています。

コードの追加のコミットが見当たらないと思ったら、9ヶ月までに作られたPRでした。


Require action_controller before any other action_controller file

action_controllerクラスのrequireを他のaction_controllerファイルより先に行うよう修正しています。

sass-railsの方で、テストが動かない問題が起きてたらしく、その為の対応。


No need to call send

不要なsendメソッドの削除。


Merge branch 'rm-uuid-fixtures'

fixtureでデータを作成する際、columnがuuid型だった場合に、自動でUUID形式のデータを作成するよう対応しています。

UUIDについてはwiki参照。

UUID型を提供しているRDMSはPostgresだけなので、今のところ影響があるのはPostgresだけです。


Remove warning of unused variable

使用してない変数の削除。


Add after_commit/after_rollback to callback list

rails guideの修正。 Active Record Callbacksのlistにafter_commit/after_rollbackが含まれていなかったのを追加しています。

after_commit/after_rollbackが入ったの大分前なので、長らく放置されていたのですね。


ci skip Remove false documentation

こちらもrais guideの修正。redefine_methodに関する説明を修正しています。


Merge pull request #12829 from iantropov/issue_insert_via_hmt_scope_3548

has_many :throughassociationをscope付きで使った場合に、レコードが保存されないバグの修正。

issueでは以下のようになっています。

has_many :developers, :through => :project_users, :source => :user,
         :conditions => {:project_users => {:role => :developer}}

@project.developers << @user
# Results in: INSERT INTO "project_users" ("created_at", "project_id", "role", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?)  [["created_at", Mon, 07 Nov 2011 10:37:00 UTC +00:00], ["project_id", 1], ["role", nil], ["updated_at", Mon, 07 Nov 2011 10:37:00 UTC +00:00], ["user_id", 1]]
@project.developers
# Returns the user from @user
@project.reload
@project.developers
# Returns an empty array

issue作成されたのが2年以上前なので、大分昔からあるバグだったんですねえ。


docs, make association autosave: true examples runnable. Closes #14700

activerecord/lib/active_record/autosave_association.rbのdocの修正です。割と致命的に誤っていて、exampleが全く動いかたないモノになっていたようです。


Minor fixes in the rails debugging guide

rails guideの修正。typoの修正です。いつのまにか、debug用gemの説明がbyebugになっているんですね。気付かなかった。


PostgreSQL, adapter automatically reloads it's type map. Closes #14678.

識別出来ないOIDがあった場合に、自動的に再読み込みを行うよう修正しています。

Enum型を使った場合に発生していたらしい。


PostgreSQL, warn once per connection per missing OID. Closes #14275.

識別出来ないOIDがあった際に、OIDを生成して、warningが一回しか出ないよう対応しています。


Implement fuzzy matching for route search on routing error html page.

routing error画面の修正。

Path検索画面で、あいまい検索の改善を行っているようです。


Improve CSS styling for routing error html page.

こちらもrouting error画面の修正。cssの改善を行っています。


Split search results into 'exact matches' and 'fuzzy matches'.

これもrouting error画面の修正。pathの検索結果の改修を行っているようです。


Only make deeply nested routes shallow when parent is shallow

shallow: trueした場合、nestしたroutesが生成されないのですが、親もshallow : trueになっている場合、nestしたroutesが生成されるように修正されています。


Re-review the debugging guide.

rails guideの修正。debugging guideの説明を修正しています。


Add more test case for #demodulize, Improve documentation

ActiveSupport::Inflector.demodulizeについてのテストコードの追加及びドキュメントの改善です。

ActiveSupport::Inflector.demodulize自体、初めて知りました。

assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")
assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")
assert_equal "Account", ActiveSupport::Inflector.demodulize("::Account")

module部分を除いたクラス名をstringで返すメソッドなんですね。


Move assets precompile (and version) to an initializer

assets precompileの設定をinitializerに移動しています。

staging/productionで同じ設定をしたい場合に、それぞれにassets precompileの設定を書いていたので、個人的にこれは嬉しい修正です。地味に下位非互換な気もします。


Be explicit about allowed constraint values, fixes #14702

rails guideの修正。constraintsを使用した際の説明を追記しています。