なるようになるブログ

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

rails commit log流し読み(2014/06/25)

2014/06/25分のコミットです。

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

activerecord/CHANGELOG.md


Merge pull request #15828 from yuki24/add-warning-about-rescue-from-exception

rails guideのAction Controller Overviewの修正です。

rescue_fromについての注意事項を追加しています。rescue_from Exception又はrescue_from StandardErrorしてはダメだよー、という内容です。


Improves readability...

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

説明の改善を行っています。


Deal with regex match groups in excerpt

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

excerptメソッドで引数の正規表現のマッチグループが含まれていた場合に、結果がおかしくなるバグを修正しています。

以下サンプル。

# before 
  excerpt('This is a beautiful? morning', /\b(beau\w*)\b/i, :radius => 5) # "...is a beautifulbeaut..."  

# after 
  excerpt('This is a beautiful? morning', /\b(beau\w*)\b/i, :radius => 5) # "...is a beautiful? mor..."

Add a '--skip-routes' flag for the Controller generator.

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

controller generatorに--skip-routesオプションが追加されました。

get "foo/bar" をroutesに追加するのをスキップする事が出来ます。不要な事も割とあるので、個人的には結構嬉しいオプション。


Fix a bug where NameError#name returns a qualified name in string

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

NameError#nameが qualified nameをStringでreturnするバグを修正しています。

Ruby本来の動きとしてSymbolをreturnするのが正しい動きとの事です。

NameError。なる程。


Merge pull request #15836 from DNNX/router-swap-select-sort actionpack/lib/action_dispatch/journey/router.rbの修正です。

sort_by!してからselect!しているのをselect!してからsort_by!するよう修正しています。

データ量が多い場合に、selectしてからsortした方が、速度的に良いからとの事。確かに。


preload preserves readonly flag on associations. #15853

activerecord/lib/active_record/associations/preloader/association.rb

preload処理でreadonlyフラグを保持していなかったバグを修正しています。

issueに貼られていた再現手順から抜粋。

class Post < ActiveRecord::Base
  belongs_to :author
  belongs_to :read_only_author, -> { readonly }, class_name: 'Author', foreign_key: :author_id
end
 
class Author < ActiveRecord::Base
  has_many :posts
end
 
class BugTest < Minitest::Test
  def test_eager_load_read_only_association
    Post.create!(author: Author.create!)
    post = Post.includes(:read_only_author).first!
    assert_raises(ActiveRecord::ReadOnlyRecord) { post.read_only_author.save! }
  end
end

read_only_authorreadonlyを設定しているので、ActiveRecord::ReadOnlyRecordがraiseすべきなのですが、flagが受け渡されてなくて、raiseしなかったんですね。