なるようになるブログ

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

rails commit log流し読み(2015/01/02)

2015/01/02分のコミットです。

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

railties/CHANGELOG.md

activerecord/CHANGELOG.md

actionview/CHANGELOG.md


Stop passing the column to the connection adapter when quoting defaults

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

connection adapterのquoteメソッドにカラムの情報を渡すのを止めています。

カラムはtype cast処理でしか使用してないので、削除していく方針のようです。


Stop using the column for type information in sanitization

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

quote_bound_valueメソッドの引数から"column"を削除しています。

先と同じく、カラム情報削除対応。代わりに、quote_bound_valueを呼び出す前にtype_cast_for_databaseを呼び出すよう対応しています。


Don't load an entire table into memory to copy it on SQLite

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

copy_table_contentsメソッドで、最初に"SELECT"クエリーを発行してデータを取得してから"INSERT"していたのを、ひとつのSQL("INSERT INFO SELECT ")で行うよう修正しています。


Don't rely on the column for type information in uniquness validations

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

connection adapterのtype_castメソッドにカラムの情報を渡すのを止めています。 代わりに、type_castにvalueを渡す前にtype_cast_for_databaseを呼び出すよう対応しています。


💣 I forgot to commit the arity change

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

ConnectionAdapters#Quoting#type_castメソッドの第二引数のcolumnにデフォルト引数を設定しています。先のコミットでtype_castメソッドでカラムを渡さないようにしたのですが、呼び出さき側の方の対応が漏れていたので、対応しています。


Stop relying on columns in sqlite quoting tests

activerecord/test/cases/adapters/sqlite3/quoting_test.rbの修正です。

sqliteのquotingのテストで、type_castメソッドにカラム情報を渡すのを止めています。


Stop relying on columns in mysql quoting tests

activerecord/test/cases/adapters/mysql/quoting_test.rbの修正です。

MySQLのquotingのテストで、type_castメソッドにカラム情報を渡すのを止めています。


Stop relying on columns for type information in mysql2 casting tests

activerecord/test/cases/adapters/mysql2/boolean_test.rbの修正です。

MySQL2ののテストで、type_castメソッドにカラム情報を渡すのを止めています。


Stop depending on columns for type information in PG quoting tests

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

PostgreSQLのquotingのテストで、type_castメソッドにカラム情報を渡すのを止めています。


Stop explicitly passing nil as the column to type_cast

activerecord/test/cases/adapters/sqlite3/quoting_test.rbの修正です。

先に行ったsqliteのquotingのテストの修正で、type_castメソッドの第二引数にnilを渡すよう修正していたのですが、そもそも第二引数を渡さないよう修正しています。type_castメソッドの第二引数はデフォルト引数が設定されているので、そもそも渡す必要が無いから、ですかねえ。


Check by @v before converting the entry on expired?

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

Entry#expired?メソッドで`convert_version_4beta1_entry!を行うかどうかチェックする変数を"@value" -> "@v"に修正しています。

Rails3.xから4.0の間にcacheに使用するインスタンス変数が"@v"から"@value"に変更になっており、cacheに関する各メソッドで変数のマイグレーション処理が行われていたのですが、 本来"@v"の方の変数があるか見なくてはならない所が、"@value"の方を見てしまい、expired?メソッドRailsバージョンアップ時に正しくデータのコンバージョンが行われないバグが起きてしまっていたので、その対応です。 割と今更感ある気もしますが…。 4-2-stable ブランチにバックポート済み。


Remove conversion code for old Rails cache entry

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

先に説明したcacheのコンバージョンに関する処理をすべて削除しています。Rails 5系のコードには不要な為との事。


Fix test description to match the test behaviour

railties/test/generators/scaffold_generator_test.rbの修正です。

scaffoldのテストで、テスト内容とテスト名が一致してなかったテストがあったので、テスト名を修正しています。


Fix scaffold generator with --helper=false option

railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rbの修正です。

--helper=falseオプションを設定した場合に、helperファイルが生成されないようgeneratorを修正しています。


Add --skip-action-mailer (or -M) to rails generate

generatorの修正です。

generatorに--skip-action-mailerオプションを追加しています。名前の通りで、設定すると、appのgenerate時にActionMailerに関するファイルをインクルードしないようにしてくれます。 オプションは"-M"でもOK。


Do not run integration tests for the test adapter

activejob/Rakefileの修正です。

test用のadapterではintegration testを実施しないよう修正しています。


Do not check only for the Rails constant

activerecord/lib/active_record/migration.rbactivesupport/lib/active_support/core_ext/kernel/debugger.rb activesupport/lib/active_support/deprecation/behaviors.rbの修正です。

"Rails"定数が定義されているかどうかチェックしている処理を、Rails.envRails.loggerが定義されているか確認するよう修正しています。

rails-html-sanitizer等のgemでRails定数が設定されている場合があり、その場合に期待通りの動作とならない為、チェックする定数を変更したとの事です。


Merge pull request #18080 from korbin/fix_reaping_frequency_configuration

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

Reaperクラスのコンストラクタでオプションのチェックをする際、reaping_frequencyのFloatへの変更処理を追加しています。

reaping_frequencyがStringだった場合に適切に値が設定されないバグがあった為対応しています。具体的には、DATABASE_URLを使用している場合に問題になっていたとの事。


Including links to earlier releases guides (4.1.8 and 4.0.12) [ci skip]

guides/source/_welcome.html.erbの修正です。

Rails 4.1.8、4.0.12の各バージョンのRails Guideのリンクを追加しています。


Add branch to gems pointing to github so that we can use local checkouts

Gemfileの修正です。

jquery-railsarelについてbranch: 'master'の指定を追加しています。


Verify the helper name with plural as it is generated

railties/test/generators/scaffold_generator_test.rbの修正です。

helperファイルが生成されない事を確認するテストで、確認対象のファイル名に誤りがあったのを修正しています。

-    assert_no_file "app/helpers/post_helper.rb"
+    assert_no_file "app/helpers/posts_helper.rb"

Remove warnings

railties/test/generators/scaffold_generator_test.rbの修正です。

" ambiguous first argument; put parentheses or a space even after /' operator'"のwarningが出てたのを対応しています。


Allow precision option for MySQL datetimes.

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

MySQLのdatetime型にprecisionオプションが設定出来るよう対応しています。

t.datetime :written_on, precision: 6

precision、MySQL 5.6.4から設定出来るようになったんですねえ。 MySQLのマニュアルご参照。


Format the datetime string according to the precision of the datetime field.

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

MySQL 5.6からミリ秒を扱えるようになったのですが、カラムで扱える以上の精度を値に指定した場合、自動で四捨五入されてしまいます。

例えば、"2014-08-17 12:30:00.999999"をdatetime型のにカラムに指定した場合、MySQL 5.5では"2014-08-17 12:30"が設定されたのですが、MySQL 5.6では四捨五入されて、"2014-08-17 12:31"が設定されてしまうとの事です。

これは、MySQLの仕様でそうなっているとの事です。Datetime rounding problem

とはいえ、自動で四捨五入されるのは、あまり望まない挙動だよね、という事でprecisionオプションを指定していた場合、四捨五入が行われないようACtiveRecord側で値のフォーマットを行うよう修正しています。

……認識あってるかなあ。


Merge pull request #18290 from lucascaton/guides_updates

各guideの修正です。

Railsのバージョンを表示している箇所を、一通り5.0.0に修正しています。


Merge pull request #11898 from prathamesh-sonpatki/patch-update

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

ActiveRecord::Relation#updateの振る舞いがかわり、引数にidの指定が無くても動作するようになっています。

# Before
# ArgumentError: wrong number of arguments (1 for 2)
Comment.where(group: 'expert').update(body: "Group of Rails Experts")

# After
# Comments with group expert updated with body "Group of Rails Experts"
Comment.where(group: 'expert').update(body: "Group of Rails Experts")

これは割と便利そう。 update_allだとcallbacksとvalidationsが実行されないので、そちらの処理が必要な場合はこの形が良さそう。


Integration requests should work in contexts without setup and teardown

actionpack/lib/action_controller/test_case.rbの修正です。

reset_template_assertionの修正です。

インスタンス変数のクリアーを行う際、インスタンス変数がnilではないかどうか、確認してから削除するよう修正しています。


Merge pull request #15746 from amccloud/auto-inverse_of-in-module

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

automatic_inverse_ofメソッドでネストしているmodelについて正しく値を返してなかったのを修正しています。


Add a hidden_field on the file_field

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

file_fieldを使用した際、自動でhidden_fieldも作成するよう対応しています。

file_field("user", "avatar")
# => <input name="user[avatar]" type="hidden" value="" /><input id="user_avatar" name="user[avatar]" type="file" />

file_fieldだけをフォームに使用した場合、Strong Parameterでのチェック時にActionController::ParameterMissing - param is missing or the value is empty: documentが起きてしまうので、回避策としてhiddenタグを追加しているとの事です。paramsにfileは含まれないからですねえ。なるほど。

因みに、hidden_fieldを生成したくない場合は、include_hiddenオプションにfalseを設定すればOKです。

file_field("user", "avatar", 'include_hidden' => false)