なるようになるブログ

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

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

2014/04/15分のコミットです。

respond_toanyを指定した際の挙動が4.0.4と4.1で変わってしまっていたバグの修正が含まれています。使われている方は、ご注意を。


[ci skip] Added link to ruby-lang.org installation.

rails guideの修正。

Rubyのインスールについての参考リンク先をhttps://www.ruby-lang.org/en/downloads/からhttps://www.ruby-lang.org/en/installation/に修正しています。


Refine tests for assert_select failure messages

テストコードの修正です。 エラーメッセージの確認をするテストで、文字列の先頭に"\A"、終端に"$"を追加して、より正確に確認するようにしています。

before
  assert_failure(/Expected at least 1 element matching \"p\", found 0/) { assert_select "p" }

after
  assert_failure(/\AExpected at least 1 element matching \"p\", found 0\.$/) { assert_select "p" }

終端チェックを"\z"で実施してないのが少し気になります。


Fix subscriptions not being unsubscribed.

テストコードの修正です。

ActiveSupport::Notifications.subscribeの戻り値を配列に格納し、teardownの際にその配列の値をunscribeするよう修正しています。


Use inheritance chain instead of callbacks to increment counter caches after create

昨日あったcounter cacheのバグ修正リファクタリングです。

counter cacheの作成処理をCounterCacheconcern内に移動しています。

callbackからメソッドチェーンに移動したので、処理漏れが無くなった、という事でしょうか。すいません、大分怪しいです…。


Use inheritance chain instead of callbacks to increment counter caches after destroy

上記コミットの削除処理対応です。


Remove outdated comment

現状の仕様と異なるコメントの削除。


Return null type format when format is not know

#anyを使用している際に、認識出来ないformatでリクエストがあった際に、ActionController::UnknownFormatが発生してしまうバグの修正。

    def my_action
      respond_to do |format|
        format.json { head :ok }
        format.any { render text: 'Default response' }
      end
    end

上記の用にメソッドが定義されていた際に、my_action.phpにリクエストを投げると、エラーになってしまっていました。

rails 4.0.3では問題なく、rails 4.0.4でエラーが発生するようになってしまっています。

4-0-stableにバックポートされているので、該当の処理を記載されている方はご注意下さい。


:scissors:

テストコードの修正。不要なスペースを削除しています。


Make console and generators blocks works at Application instance level

consolegeneratorsブロックがApplication instance生成時に動作するよう修正しています。

Example:

MyApplication::Application.configure do
  console do
    require "pry"
    config.console = Pry
  end
end

こちらも、rails 4.0.xで動いていいて、rails 4.1動作しなくなった処理です。

railties/lib/rails/application.rbconsole及びgeneratorsメソッドを定義して対応しています。


The Association Relation should use empty? and size from Relation.

このコミットでAssociationRelationにsize及びempty?メソッドが定義されましたが、それにより結果が変わってしまうバグが発生してしまっていました。

Example:
  # Given an author that does have 3 posts, but none of them with the
  # title 'Some Title'
  Author.last.posts.where(title: 'Some Title').size
  # => 3

AssociationRelationからsize及びempty?メソッドを削除し、Relationのメソッドが呼ばれるようにして対応を行っています。


Make sure the column_name is different from 'all'.

上記コミットの続きです。

通常のカラム名を指定した場合と、:allを指定した場合とで、calcurationsの挙動が異なるので、:allが指定された際に適切なメソッドが呼ばれるよう、カラム名のチェック処理を追加しています。


[ci skip] Add missing end in one of the examples in Migrations.md.

rails guideの修正。exampleにendが足りてなかったのを追加しています。


use YAML.load_file in database tasks example

activerecord/lib/active_record/tasks/database_tasks.rbのコメントの修正です。

YAMLのload処理の記述をYAML.load_fileを使うよう修正しています。

before
  DatabaseTasks.database_configuration = YAML.load(File.read('my_database_config.yml'))

after
  DatabaseTasks.database_configuration = YAML.load_file('my_database_config.yml')