なるようになるブログ

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

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

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

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md


Don't attempt to specify datetime precision unless supported

Active Recordのテストの修正です。

datetime precisionをサポートしていないDB(MySQL 5.6未満等)では、datetime型のカラムにprecisionを指定しないよう修正しています。


0 precision is not the same as no precision

activerecord/test/schema/schema.rbの修正です。

先のコミット同様、datetime precisionをサポートしていないDB(MySQL 5.6未満等)では、datetime型のカラムにprecisionを指定しないよう修正しています。


Don't rely on subsecond precision being applied in tests

Active Recordのテストの修正です。

AR: take precision into count when assigning a value to timestamp attribute の対応のテストで、テスト中に秒の値が変わる事を期待しているのですが、 テストの実行タイミングによっては変わらない事もあるので、travel(1.second)で明示的に秒が変わるよう修正しています。


Further remove reliance on subsecond precision in tests

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

先のコミット同様、テスト中に秒の値が変わる事を期待しているテストで、travel(1.second)で明示的に秒が変わるよう修正しています。


Document Bearer prefix for Authorization header [ci skip]

actionpack/lib/action_controller/metal/http_authentication.rbのdocの修正です。

Have Bearer be valid as well by phoetAuthorization-headerBearerキーワードを指定した場合もauthenticateが動作するよう対応されたのですが、 docの方が更新されていなかったので、Bearerも有効なprefixである旨説明を追加しています。


Removed Mocha from app generators tests

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

generatorsのテストで、mock処理にmochaを使用していたのを、Rails内部のヘルパーメソッドを使用するよう修正しています。


don't mutate a response object after to_a

actionpack/test/dispatch/response_test.rbの修正です。

Response#to_a実行後、response objectの値を変更しないよう修正しています。

to_aメソッドを呼び出す、という事はresponseが確定している状態になっている、という事なので、その後値を書き換えるのはテストとして良くないだろう、という事で修正したようです。


split cookie tests

actionpack/test/dispatch/response_test.rbの修正です。

複数のcookiesを扱うテストと、cookiesを削除するテストを一つのテストでまとめて行っていたのを、テストを分けています。


skipped assertion on datetime seconds precision as it is only valid for newer mysql versions

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

datetime precisionをサポートしていないDB(MySQL 5.6未満等)で、datetime型のカラムにprecisionを指定したテストを行わないようskip処理を追加しています。


don't access the response object before a request was made

actionpack/test/controller/test_case_test.rbの修正です。

ActionController::TestCaseクラスのテストで、リクエスト処理を行う前にresponse objectにアクセスしていたのを、先にリクエスト処理を行うよう修正しています。


Merge pull request #21218 from repinel/fix-as-callback-terminator https://github.com/rails/rails/commit/9c55ff564d21c178979cab126258123fa4b8b52a

Active Supportのcallback処理の修正です。

Active Record, Active Model, Active Model validations の callback処理で、callback処理中にfalseを返してもcallback chainがhaltしないリグレッションがあったのを修正しています。


Fix ActiveRecord::Locking doc [ci skip]

activerecord/lib/active_record/locking/optimistic.rbのdocの修正です。

Optimistic moduleのdocのグラマーの修正を行っています。


Merge pull request #21737 from cllns/make-engine-paths-consistent

rails guideのGetting Started with Enginesの修正です。

Inside an Engineの項、作成したengine製gemのインストールについて説明している箇所で、サンプルのパスがvendor配下になっていたのですが、vendorは既に存在しないパスなので、サンプルとしては不適切だろう、という事でパスを修正しています。


stop applying default headers in ActionDispatch::Response

Action Packの修正です。

ActionDispatch::Response#newメソッドではdefault headersの設定を行わないよう変更しています。

default headersが設定されてないresponse objectを作りたい場合に困る為、との事です。default headersの設定がされたresponse objectが必要な場合、代わりにActionDispatch::Response.createメソッドを使用して下さい、との事です。


test against controller responses

actionpack/test/controller/send_file_test.rbの修正です。

send_dataメソッドのテストで、擬似的に作成したcontrollerを使用してresponseのチェックをしていたのを、responseオブジェクト経由で値のチェックをするよう修正しています。


stop constructing a request object in this setter

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

headers=メソッドで、headerを設定する前にActionDispatch::Responseクラスのオブジェクトを生成していたのですが、現状、通常のテストフローであれば自動でresponse objectは生成されるようになっており、ここでresponse objectを生成する必要は無いため、処理を削除しています。


stop directly setting headers on the controller

actionpack/lib/action_controller/metal/testing.rbactionpack/test/controller/send_file_test.rbの修正です。

controllerから直接headersを設定する処理があったのを削除しています。


don't touch the response object until after we call get

actionpack/test/controller/live_stream_test.rbの修正です。

request処理が行われる前にresponse objectを操作する処理があったのを削除しています。


type of response should not matter

actionpack/test/controller/live_stream_test.rbの修正です。

controllerからresponseを設定するテストがあったのですが、controllerから直接response objectを変更するのは好ましく無い為、テスト自体を削除してます。


test framework allocates the controller for us

actionpack/test/controller/live_stream_test.rbの修正です。

test_write_to_streamメソッドから、不要なcontroller objectの生成処理を削除しています。


stop directly referencing the request and response objects

actionpack/test/controller/live_stream_test.rbの修正です。

response / request オブジェクトを、テスト無いで直接参照している箇所があったのを、controller経由で値を参照するよう修正しています。


remove controller construction

actionpack/test/controller/live_stream_test.rbの修正です。

各テストから、不要なcontroller objectの生成処理を削除しています。


call get instead of controller.process

actionpack/test/controller/live_stream_test.rbの修正です。

test_ignore_client_disconnectで、requestを生成するのに、controllerのprocessメソッドを使用していたのを、テスト用のgetメソッドを使用するよう修正しています。


Fix ActiveRecord instance_method_already_implemented docs [ci skip]

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

instance_method_already_implemented?メソッドのdoc内のグラマーの修正を行っています。


Fix out of sync comment

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

db:test:prepareのdescに、 pending migrationsをチェックする、と記載されていたのですが、Rails 4系からpending migrationsのチェックは行わなくなったので、説明を削除しています。


Merge pull request #21740 from cllns/add-jbuilder-notes

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

Jbuilder gemについての説明を記載したJbuilderセクションを追加しています。


Improve readability of docs by using code tag [ci skip]

activesupport/lib/active_support/core_ext/object/inclusion.rbactivesupport/lib/active_support/core_ext/object/try.rbのdocの修正です。

各doc内のクラス名をcode tag(+)で囲むよう修正しています。


Merge pull request #21697 from gdeglin/fix_returning_disabled_default_values_bug

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

PostgresSQL adapterで extract_table_ref_from_insert_sqlでinto queryの判定用正規表現に誤りがあり、insert_returningオプションにfalseを設定している場合に、エラーになってしまうバグがあったのを修正しています。

-          sql[/into\s+([^\(]*).*values\s*\(/im]
+          sql[/into\s("[A-Za-z0-9_."\[\]\s]+"|[A-Za-z0-9_."\[\]]+)\s*/im]

partition tableを使用している場合に問題が起きてしまったようです。


Merge pull request #21550 from didacte/unscope-associations

activerecord/lib/active_record/associations/preloader/association.rbの修正です。

through associationsをpreloadした場合に、unscopeメソッドが呼び出されないバグがあったのを修正しています。

PRより。

class Developer < ActiveRecord::Base
  default_scope -> { where(awesome: true) }
end

class Project < ActiveRecord::Base
  has_and_belongs_to_many :developers, -> { unscope(where: :awesome) },
end

mediocre_dev = Developer.create(awesome: false)
project = Project.create
project.developers << mediocre_dev

project.developers.reload.size
# => 1
Project.where(id: project.id).includes(:developers).first.developers.size
# => 0(本来は1になるべき)