なるようになるブログ

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

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

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

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

activerecord/CHANGELOG.md


Remove @connection in StatementPool

Active Recordの修正です。

ConnectionAdapters::StatementPoolクラスから@connection変数を削除しています。

@connection変数はPostgresでのみ必要な変数の為、PostgreSQLAdapter配下のStatementPoolクラスでのみ値を持つようにしています。


s/seperator/separator/g

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

separatorseperatorにタイポしていた箇所があったのを修正しています。


Should test both mysql adapters

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

幾つかのテストがMysqlAdapterの場合のみ実行されないようになっていたのw,Mysql2Adapterでもテストを実行するよう修正しています。


Correctly dump composite primary key

Active Recordの修正です。

複合主キーを使用している場合に、schemaファイルにプライマリキーの情報が正しく出力されるよう対応しています。

出力例。

create_table :barcodes, primary_key: ["region", "code"] do |t|
  t.string :region
  t.integer :code
end

String#strip_heredocs doesn't need Object#try

activesupport/lib/active_support/core_ext/string/strip.rbの修正です。

Improve String#strip_heredoc により不要になったactive_support/core_ext/object/tryのrequireを削除しています。


Added beanstalkd to Travis so ActiveJob integration tests for beanstalkd can run

.travis.ymlの修正です。

Active Jobのインテグレーションテストで使用する為に、前処理でbeanstalkdをインストールするよう修正しています。今まではbeanstalkdを使用するテスト、実行されていなかったんですねえ。


Added new lines to run title for easy log reading

activejob/test/support/integration/helper.rbの修正です。

Active Job のインテグレーションテストの結果を見やすくする為に、テスト実行時のログに改行を追加しています。


Merge pull request #21677 from ronakjangir47/send_file_headers_test

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

content typeがnilの場合に、send_file_headersメソッドを使用した場合のテストを追加しています。


Merge pull request #21664 from kamipo/reduce_call_create_table_info

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

create tableに関する情報を変数にキャッシュし、不要なSQLを実行されないように修正しています。


Merge pull request #21608 from kamipo/eliminate_duplicated_options_include_default_method

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

SchemaCreationSchemaStatementsそれぞれで同じ内容のoptions_include_default?メソッドを定義してしまっていたのを、SchemaCreationクラスの方のメソッドは削除し、SchemaStatementsの方を使用するよう修正しています。


Merge pull request #21607 from kamipo/remove_unnecessary_display_width

Active Recordの修正です。

MySQLで、int型の値のカラムを生成する際、int(11)という風にサイズを指定していたのを、削除しています。

例。

-    #     id int(11) NOT NULL auto_increment,
-    #     account_id int(11) default NULL,
+    #     id int NOT NULL auto_increment,
+    #     account_id int default NULL,

(xx)の値はストレージサイズには関係が無く、表示用の幅を指定するためだけの項目の為、削除したとの事です。詳細は Proposal to deprecate MySQL INTEGER display width and ZEROFILL | Master MySQL 参照。


Merge pull request #21609 from kamipo/do_not_dump_view_as_table

Active Recordの修正です。

connection adaptersに、viewsview_exists?メソッドを追加しています。

sqlite3, mysqlとmysql2 adaptersでDBをダンプする際、viewについてもtableと同じようにダンプされてしまっており、それを避ける為に、メソッドを追加したとの事です。


Merge pull request #21589 from kamipo/eliminate_duplicated_visit_table_definition

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

重複していたvisit_TableDefinitionメソッドを削除しています。


Merge pull request #20645 from kamipo/fix_mysql_set_type_bug

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

MySQLのSET型を使用していた場合に、値が正しくマッピングされないバグがあったのを修正しています。

SET型を使用した場合のルックアップ処理がそもそも正しく実装されていなかったようです。


Merge pull request #19086 from kamipo/move_explain_into_abstract_mysql_adapter

Active Recordの修正です。

MysqlAdapter、 Mysql2Adapter両方で使用するexplainメソッドを親クラスのAbstractMysqlAdapterクラスに移動しています。


Merge pull request #17696 from kamipo/unsigned_integer_support

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

MySQLunsigned numericデータタイプをマイグレーションファイルに使用出来るよう対応しています。

例。

create_table :foos do |t|
  t.unsigned_integer :quantity
  t.unsigned_bigint  :total
  t.unsigned_float   :percentage
  t.unsigned_decimal :price, precision: 10, scale: 2
end

primary keyに使用したい場合は、unsignedオプションを指定する事で使用出来るとの事です。

create_table :foos, id: :bigint, unsigned: true do |t|
  …
end

remove association reload option from guide [ci skip]

rails guideのActive Record Associationsの修正です。

Deprecate force association reload by passing trueでdeprecateになったassociationメソッドのreloadオプションについての説明を削除しています。


Support for foreign keys in create table

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

create table SQL実行時に外部キーを設定出来るよう対応しています。

create_table :testings do |t|
  t.references :testing_parent, foreign_key: true
end

上記のようなマイグレーションファイルがあった場合、

元々は、

CREATE TABLE "testings" ("id" serial primary key, "testing_parent_id" integer);
ALTER TABLE "testings" ADD CONSTRAINT "fk_rails_a196c353b2" FOREIGN KEY ("testing_parent_id") REFERENCES "testing_parents" ("id");

このように、CRATE TABLEとALTER TABLEが別に実行されていたのですが、これが、

CREATE TABLE "testings" ("id" serial primary key, "testing_parent_id" integer, CONSTRAINT "fk_rails_a196c353b2" FOREIGN KEY ("testing_parent_id") REFERENCES "testing_parents" ("id"));

CREATE TABLE実行時に、FOREIGN KEYの設定も行えるようになりました。クエリーが減って、ちょっと効率的に。


Refactor table_exists? in AbstractMysqlAdapter

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

AbstractMysqlAdapter#table_exists?メソッドリファクタリングを行っています。

引数にdbname.tblnameが渡された場合にtablesが2回呼ばれてしまっていたのを必ず一度しか呼ばれないよう修正、tablesメソッドから不要な引数を削除、の対応を行っています。


fix application_controller require_dependency path generated by the scaffold generator

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

Fixed the application_controller require_dependency path generated by the app generator で、namespace付きのcontrollerを生成する際に、namespaceに関わらず必ず同じapplication_controllerを読み込むようcontrollerを生成するよう対応していたのですが、controllerのgeneratorのみ対応されており、scaffoldのgeneratorの方が対応されていなかった為、同じ内容を対応しています。


correcting word smpt -> smtp in ActionMailer guide [ci skip]

rails guideのAction Mailer Basicsの修正です。

smtpsmptにタイポしている箇所があったのを修正しています。


fix to_time output in ActiveSupport guide. Since https://github.com/rails/rails/commit/48583f8bf74d1cefefea3cd6591bd546a9eaff6c , to_time returns times formatted as YYYY-MM-DD HH:MM:SS UTC [ci skip]

rails guideのActive Support Core Extensionsの修正です。

to_timeメソッドのexampleの実行結果が、実際の結果と異なっている箇所があったのを修正しています。