なるようになるブログ

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

rails commit log流し読み(2015/03/24)

2015/03/24分のコミットです。

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

activerecord/CHANGELOG.md


Remove alias for i_suck_and_my_tests_are_order_dependent.

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

使用していないi_suck_and_my_tests_are_order_dependent!エイリアスmy_tests_are_order_dependentを削除しています。

randomにテストを実行したくない場合に設定する為の値だったのですが、後からtest_order=が入り、そちらを設定するようになった為、こちらは不要の為削除しています。


Make sure Array#to_sentence always returns a String

activesupport/lib/active_support/core_ext/array/conversions.rbの修正です。

Array#to_sentenceメソッドが必ずStringクラスを返すよう修正しています。

# before
[ActiveSupport::SafeBuffer.new("foo")].to_sentence.class # => ActiveSupport::SafeBuffer
[ActiveSupport::SafeBuffer.new("foo"), "bar"].to_sentence.class # => String

# after
[ActiveSupport::SafeBuffer.new("foo")].to_sentence.class # => String
[ActiveSupport::SafeBuffer.new("foo"), "bar"].to_sentence.class # => String

html_safeのバリデーションする/しない等の差異が出てしまう為、統一されるようにしたとの事です。


Pass wrapped class name to Sidekiq for logging purposes

activejob/lib/active_job/queue_adapters/sidekiq_adapter.rbの修正です。

Sidekiq::Client.pushメソッドの引数のwrappedにクラス名を渡すよう修正しています。

         Sidekiq::Client.push \
-          'class' => JobWrapper,
-          'queue' => job.queue_name,
-          'args'  => [ job.serialize ]
+          'class'   => JobWrapper,
+          'wrapped' => job.class.to_s,
+          'queue'   => job.queue_name,
+          'args'    => [ job.serialize ]

sidekiqのログにクラス名が表示されるようにする為との事。


Small doc fix. [CI SKIP]

activesupport/lib/active_support/testing/time_helpers.rbのdocの修正です。

TimeHelpers moduleの説明のグラマーの修正を行っています。


[ci skip] Remove unacceptable method name

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

remove_referenceのdocにreferenceを削除する為のメソッドの一覧が表示されているのですが、そこに存在しないメソッド(remove_references)が記載されていたのを削除しています。


Fix incorrect description for assert_nothing_raised.

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

assert_nothing_raisedメソッドの説明に誤りがあった(何も例外が起こらなかった場合にエラーになるメソッドなのに、例外が起きた際にエラーになる、となっていた)のを修正しています。


Merge pull request #19493 from larskanis/add_infinity_test

activerecord/test/cases/adapters/postgresql/infinity_test.rbの修正です。

"Infinity" 文字列をfloat型のカラムに設定した場合のテストを追加しています。


Merge pull request #19452 from pinglamb/fix-referencing-wrong-alias-when-joining-tables-of-has-many-through-association

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

has_many through associationを設定しているクラスをjoinし、カルキュレーション系のメソッド(countなど)を呼び出した際に、 実際のテーブル名ではなく、through joinの際にエイリアスが使用されてしまい、エラーになってしまうバグがあったのを修正しています。

class Shop < ActiveRecord::Base
  has_many :categories
  has_many :products, through: :categories
end

class Category < ActiveRecord::Base
  belongs_to :shop
  belongs_to :reseller
  has_many :products
end

class Product < ActiveRecord::Base
  belongs_to :category
end

class Reseller < ActiveRecord::Base
  has_many :categories
end


shop = Shop.first
shop.products.includes(category: :reseller).where(resellers: { id: 1 }).count
# Rails 4.0.x
SELECT
  COUNT(DISTINCT `products`.`id`)
FROM `products`
LEFT OUTER JOIN `categories` `categories_products`
  ON `categories_products`.`id` = `products`.`category_id`
LEFT OUTER JOIN `resellers`
  ON `resellers`.`id` = `categories_products`.`reseller_id`
INNER JOIN `categories`
  ON `products`.`category_id` = `categories`.`id`
WHERE `categories`.`shop_id` = 1
  AND `resellers`.`id` = 1
# Rails 4.1.x, 4.2.x
SELECT
  COUNT(DISTINCT `products`.`id`)
FROM `products`
LEFT OUTER JOIN `categories` `categories_products`
  ON `categories_products`.`id` = `products`.`category_id`
LEFT OUTER JOIN `resellers`
  ON `resellers`.`id` = `categories`.`reseller_id`
INNER JOIN `categories`
  ON `products`.`category_id` = `categories`.`id`
WHERE `categories`.`shop_id` = 1
  AND `resellers`.`id` = 1