なるようになるブログ

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

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

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


Add singular and plural form for some validation messages

length validator'sのデフォルトのメッセージに単数形のパターンを追加しています。

以下コミットログの抜粋。

-      too_long: "is too long (maximum is %{count} characters)"
-      too_short: "is too short (minimum is %{count} characters)"
-      wrong_length: "is the wrong length (should be %{count} characters)"
+      too_long:
+        one: "is too long (maximum is 1 character)"
+        other: "is too long (maximum is %{count} characters)"
+      too_short:
+        one: "is too short (minimum is 1 character)"
+        other: "is too short (minimum is %{count} characters)"
+      wrong_length:
+        one: "is the wrong length (should be 1 character)"
+        other: "is the wrong length (should be %{count} characters)"

元々は複数形のパターンだけだったのに、単数形が追加されています。

i18n対応で少し追随が必要そう。


eliminate repetition in guide links for past releases [ci skip]

rails guideの修正です。

_welcome.html.erbから過去のバージョンのguideページへのリンクを削除して、最新のバージョンへのリンクを載せるようにしています。


passing a nil should always raise an ArgumentError

ActionDispatch::Routing::PolymorphicRoutes#polymorphic_urlメソッドの修正です。

polymorphic_urlの第一引数にnilが含まれていた場合に、ArgumentErrorがraiseするよう修正しています。

元々は、compactメソッドを使ってnilを除去していたのですが、compactメソッドの呼び出しを削除しています。


push up bind params on "simple" subquery calculations


make db:structure:load listed with rake -T

activerecord/lib/active_record/railties/databases.rakeの修正です。

db:structure:loadタスクをrake -Tコマンドに表示されるよう修正しています。

db:structure:loadはstructure.sqlからDBを作り直す為のコマンドのようです。

structure.sql使った事無かったのですが、生のSQLになるので、schema.rbで管理しきれない特殊なケースの時は良いのかもしれないですね。


passing a nil in the polymorphic array is not supported. remove nils before you call the method

ActionDispatch::Routing::PolymorphicRoutes#polymorphic_urlメソッドの修正です。

polymorphic_urlの第一引数にnilが含まれていた場合に、ArgumentErrorがraiseするよう修正しています。

passing a nil should always raise an ArgumentErrorのコミットは、実際のArgumentErrorは呼び出し先のメソッドで起きていたのですが、こちらのコミットではpolymorphic_url内でnilチェックを行い、nilが含まれていたらpolymorphic_urlでArgumentErrorを発生するように対応しています。


Move dup destroyed test to specific file that tests dup logic

test_dup_not_destroyedのテストメソッドをactiverecord/test/cases/persistence_test.rbからactiverecord/test/cases/dup_test.rbに移動しています。

dup_test.rbにある方がテスト内容を考えると適切だからですかね。


Add branch to arel on Gemfile to allow local bundle config [ci skip]

Gemfileのarelbranch: 'master'を追記しています。


Add missing require to fix test :bomb:

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

require 'models/reply'を追加しています。 requireが足りてなくてテストがコケてたようです。


Use #include? instead of #any?, make it simpler

先にあったpolymorphic_urlnilのチェックの処理を

-          if record_or_hash_or_array.any?(&:nil?)
+          if record_or_hash_or_array.include? nil

のように修正しています。この場合だと、確かにinclude?使った方がわかりやすい気がします。


Test typecasting on instance rather than class itself

activerecord/test/cases/adapters/sqlite3/quoting_test.rbtest_quoted_idメソッドの修正です。

newメソッドの呼び出しを追加して、インスタンスを生成するようにしています。

classよりも、インスタンスの方が良い、というより、そもそもインスタンスでテスト行わないとダメそうな。


Merge pull request #14924 from eric-chahin/issue_13854

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

autosave associationsを指定していて、validationを行う際、contextの判定がおかしかったバグを修正しています。

テストコード抜粋。

pirate = FamousPirate.new
pirate.famous_ships << ship = FamousShip.new
assert_equal true, pirate.valid?
assert_equal false, pirate.valid?(:conference)
assert_equal "can't be blank", ship.errors[:name].first

FamousShipon: :conferenceでvalidationを設定しているので上記動作が期待されるのですが、元々は4行目のpirate.valid?(:conference)もtrueになってしまっていたようです。