なるようになるブログ

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

rails commit log流し読み(2017/03/06)

2017/03/06分のコミットです。

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

activerecord/CHANGELOG.md

actionpack/CHANGELOG.md


Fix CI failure due to contain <U+2028>

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

redirect_toメソッドのdocを修正した対応(Merge pull request #28259 from ChakreshwarSharma/redirect_to_doc)で、doc内に不正な文字が含まれてしまっていたのを削除しています。


Fix direct with params example [ci skip]

actionpack/lib/action_dispatch/routing/mapper.rbのdocの修正です。

directメソッド内のexampleコードが動作しないコードになっていたのを修正しています。


Extract SchemaMigration.all_versions

Active Recordの修正です。

migrationの全てのバージョンを取得する為のメソッド(SchemaMigration.all_versions)を追加し、各箇所でそのメソッドを使用するよう修正しています。


Merge pull request #28295 from kamipo/fix_deserialize_with_json_array

activerecord/lib/active_record/connection_adapters/postgresql/oid/array.rbの修正です。

JSON arrayに対するdeserialize処理が正しく行われないバグがあったのを修正しています。


Fix malformed asset_url when rendering template with ActionController::Renderer

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

ApplicationController.rendererを使用してasset urlを含むviewをrenderした際に、asset urlが不正な値(e.g. http://://example.org:80/)が生成されてしまうバグがあったのを修正しています。


Add CHANGELOG entry for #28250

actionpack/CHANGELOG.mdの修正です。

先のApplicationController.rendererメソッドの対応についてCHANGELOGにエントリーを追加しています。

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

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

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

activerecord/CHANGELOG.md

railties/CHANGELOG.md


Fix rake db:schema:load with subdirectories

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

db:schema:load タスクが、サブディレクトリにあるmigrationファイルをload出来ないバグがあったのを修正しています。


[ci skip] Fix ParameterMissing exception name in docs

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

StrongParametersのdoc内でActionController::ParameterMissingActionController::MissingParameterにタイポしていたのを修正しています。


Don’t hide method that’s been documented API since Rails 2.1

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

Fix rake db:schema:load with subdirectoriesの対応でprivate APIに変更されたassume_migrated_upto_versionをpublic APIに戻しています。

内部でしか使用していないのでprivate APIで良いのでは、という事で変更されたのですが、Rails 2.1の頃からpublic APIになっており、いきなりprivate APIにするのは良くないだろう、という事でpublic APIに戻っています。


Remove useless Migrator.schema_migrations_table_name

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

SchemaMigration.table_nameメソッドをラップしていたActiveRecord::Migrator.schema_migrations_table_nameメソッドを削除しています。SchemaMigration.table_nameを直接呼べば良いだろう、という事で削除されています。


Avoid running system tests by default

railtiesの修正です。

bin/rails test、及びbin/rake testコマンドで、デフォルトでsystem testsは実行しないよう修正しています。

system testsは処理が重いため、テストスイート内で実行されるべきではない、という事でデフォルトでは実行されないようになっています。ちょっと違和感が。


Revert “Merge pull request #28283 from y-yagi/silence_puma_startup_messages_in_system_test”

actionpack/lib/action_dispatch/system_testing/server.rbの修正です

system testでpumaを起動する際に、pumaのスタートアップメッセージをstdoutに表示しないようにした、Silence puma startup messages in system testをrevertしています。 スタートアップメッセージはスレッド数やポートを確認するのに有用なので、見えた方が良いだろう、という事でrevertされています。


Merge pull request #28264 from y-yagi/do_not_take_screenshot_if_driver_does_not_support_it

actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rbの修正です。

system testで、driverがスクリーンショットをサポートしてない場合、テスト失敗時のスクリーンショットの取得処理を行わないよう修正しています。


Merge pull request #28259 from ChakreshwarSharma/redirect_to_doc

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

redirect_toメソッドのdocに、redirect_toメソッドの後も処理が実行される旨説明を追加、また、即座に処理を終了したい場合は、returnを使う旨説明を追加しています。

rails commit log流し読み(2017/03/04)

2017/03/04分のコミットです。

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

activesupport/CHANGELOG.md

activerecord/CHANGELOG.md


Remove node parameter to join_constraints

activerecord/lib/active_record/associations/join_dependency.rbactiverecord/lib/active_record/associations/join_dependency/join_association.rbの修正です。

JoinAssociation#join_constraintsメソッドから使用されていないnode引数を削除しています。


Move join scopes on to the reflection object

activerecord/lib/active_record/associations/join_dependency/join_association.rbactiverecord/lib/active_record/reflection.rbの修正です。

JoinAssociation#join_constraintsメソッド内でおこなっていたscopeのjoin処理を、Reflectionクラス(AbstractReflectionPolymorphicReflection等)にjoin処理用のメソッド(#join_scopes)を追加し、そちらで処理を行うよう修正しています。


ask reflection for klass join reflection

activerecord/lib/active_record/associations/join_dependency/join_association.rbactiverecord/lib/active_record/reflection.rbの修正です。

JoinAssociation#join_constraintsメソッド内でおこなっていたklass scopeのjoin処理を、Reflectionクラスjoin処理用のメソッド(#klass_join_scope)を追加し、そちらで処理を行うよう修正しています。


Remove unnecessary system test code

railties/lib/rails/test_help.rbの修正です。

不要なaction_dispatch/system_test_caseのrequire、及び、ActionDispatch::SystemTestCasebefore_setupメソッドを削除しています。

実際にActionDispatch::SystemTestCaseを使用される際にクラスはautoloadされる、かつ、before_setupActionDispatch::SystemTestCaseの親クラスであるActionDispatch::IntegrationTestで同じ内容を定義済みであり、SystemTestCaseに別途定義する必要は無いため、削除したとの事です。


Fix spelling

rails guideのActive Model Basicsの修正です。

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


Add ActiveSupport::TimeZone.iso8601 parsing method

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

ISO 8601形式の文字列をパースする為のiso8601メソッドをActiveSupport::TimeZoneに追加しています。

Time.zone = "Hawaii"
Time.zone.iso8601("1999-12-31T14:00:00Z")
# => Fri, 31 Dec 1999 04:00:00 HST -10:00

Time.zone.iso8601("1999-12-31")
# => Fri, 31 Dec 1999 00:00:00 HST -10:00

Add ActiveSupport::TimeZone.rfc3339 parsing method

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

RFC 3339形式の文字列をパースする為のrfc3339メソッドをActiveSupport::TimeZoneに追加しています。

Time.zone = "Hawaii"
Time.zone.rfc3339("1999-12-31T14:00:00Z")
# => Fri, 31 Dec 1999 04:00:00 HST -10:00

Add Time.rfc3339 parsing method

activesupport/lib/active_support/core_ext/time/calculations.rbの修正です。

RFC 3339形式の文字列をパースする為のrfc3339メソッドをこちらはTimeクラスに追加しています。

Time.rfc3339('1999-12-31T14:00:00-10:00')
# => 1999-12-31 14:00:00 -1000

戻り値は当然Timeクラスのインスタンスです。


Add rfc3339 aliases to xmlschema

activesupport/lib/active_support/core_ext/time/conversions.rbactivesupport/lib/active_support/time_with_zone.rbの修正です。

先に追加されたActiveSupport::TimeZone、及びTimerfc3339メソッドのaliasとして、xmlschemaメソッドを追加しています。


refactor so there is only one JoinKeys factory method

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

JoinKeysクラスを生成する為のfactoryメソッドが子クラス(BelongsToReflection)で別途定義されてしまっていたのを、親で定義されているfactoryメソッドを使えるようリファクタリングしています。


join_keys no longer needs a class passed to it

Active Recordの修正です。

Reflectionのjoin_keysメソッドにassociation classを渡していたのを、渡さないで済むようリファクタリングしています。join_keysメソッドでJoinKeysを生成する際は、それぞれのclassで保持している情報をしか使用しておらず、そもそも渡す必要は無かった為、余計な依存関係を無くすようにする為に、削除したようです。


remove unused parameters

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

last_chain_scopenext_chain_scopeadd_constraints各メソッドから使用されていないassociation_klass引数を削除しています。


Merge pull request #28265 from 0oneo/association_guide

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

The has_one Associationの項にあるmigrationでuniqueオプションの指定の仕方に誤りがあったのを修正しています。


A private method can’t be called with self.

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

filename_with_extensionsメソッドでデフォルト引数を指定する際に、privateメソッドをself.付きで呼ぼうとしてエラーになっていた為、self.を削除しています。


Escapes and edits to configuring guide [ci skip] (#28280)

rails guideのConfiguring Rails Applicationsの修正です。

各項目のフォーマット、グラマーの修正をまとめて行っています。


Don’t share options with a reference type column

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

polymorphic reference columnをmigrationで作成する際に、指定されたオプションをid column、type columnに両方に適応したのを、id columnにだけ適応するよう修正しています。

add_reference :posts, :taggable, type: :integer, limit: 2, polymorphic: true

上記のような migrationでpolymorphic columを作成した場合い、limit: 2オプションをがtaggable_typeにも適応されていました。しかし、idとtypeは型が違い、オプションをそのまま適応するのは予想外の振る舞いになる事が多い為、typeにはオプションを適応しないよう修正したようです。


Silence puma startup messages in system test

actionpack/lib/action_dispatch/system_testing/server.rbの修正です。

system testでpumaを起動する際に、pumaのスタートアップメッセージをstdoutに表示しないよう修正しています。


Fx system test example [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

system_testをgenerateするexampleで、system test nameに不要なtestがあったのを削除、及び、生成されるファイルのexampleが実際生成されるファイルと異なっていたのを修正しています。


[ci skip] Add CHANGELOG entry for #28282

activerecord/CHANGELOG.mdの修正です。

先の polymorphic reference columnの対応について、CHANGELOGにエントリーを追加しています。


Fix rake db:migrate:status with subdirectories

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

db:migrate:status タスクが、サブディレクトリにmigrationファイルがある場合にMigration Nameを正しく表示出来ないバグがあったのを修正しています。


Add a changelog entry for #28284 [ci skip]

actionpack/CHANGELOG.mdの修正です。

system testでpumaを起動する際にpumaのスタートアップメッセージをstdoutに表示しないよう修正した対応について、CHANGELOGにエントリーを追加しています。


Fix a wrong pull request reference [ci skip]

actionpack/CHANGELOG.mdの修正です。

先のエントリーを追加した際に、参照するPRのIDに誤りがあったのを修正しています。

rails commit log流し読み(2017/03/03)

2017/03/03分のコミットです。

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

railties/CHANGELOG.md

activesupport/CHANGELOG.md


Merge pull request #28139 from stouset/update-secrets-to-use-modern-crypto

railties/lib/rails/secrets.rbの修正です。

encrypted secretsで使われる暗号化アルゴリズムを、AES-256-CBCからAES-128-GCMに変更しています。

よりセキュアなブロック暗号をデフォルトで使うべきだ、という事でGCMに変更になったようです。


Add back yaml require.

railties/lib/rails/secrets.rbの修正です。

不足していたyamlのrequireを追加しています。


Move key packing into encryptor.

railties/lib/rails/secrets.rbの修正です。

keyのpacking処理をencryptor生成時に行うよう修正しています。


Inline CIPHER constant.

railties/lib/rails/secrets.rbの修正です。

aes-128-gcmを定数で保持していたのを変数で保持するよう修正しています。クラス内でしか使用してないからですかねえ。


[ci skip] Add changelog entry for #28139.

railties/CHANGELOG.mdの修正です。

encrypted secretsで使われる暗号化アルゴリズムがAES-128-GCMに変わった対応についてエントリーを追加しています。

また、アルゴリズム変更に伴い、5.1.beta1で既にencrypted secretsを使用している場合、アップグレード対応が必要になります。アップグレード対応についてはこちら参照。


Merge pull request #28255 from acrich/master

rails guideのActive Record Query Interfaceの修正です。

Calculationsの項のexampleコード内のテーブル名をタイポしていたのを修正しています。


Fix typo in Upgrading Ruby on Rails Guide [skip ci]

rails guideのA Guide for Upgrading Ruby on Railsの修正です。

Upgrading from Rails 5.0 to Rails 5.1の項でcontainingcontaingにタイポしていたのを修正しています。


Fix random failure on system test with ajax

actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rbの修正です。

DBのtansactionをrollbackする前にCapybara.reset_sessions!を呼ぶようメソッドの呼び出し順を調整しています。

ajaxを使用している場合に、transaction後にリクエストがきてしまうのを避ける為。


Merge pull request #28204 from rails/deprecate-implicit-coercion-of-durations

Active Supportの修正です。

NumericからActiveSupport::Durationへの暗黙的な変換がdeprecateになりました。

現状、Numericの加減算メソッドにActiveSupport::Durationの値を指定した場合、暗黙的に秒の値に変更されるようになっていました。

2 * 1.day
# => 172800

しかしこの挙動は混乱を招く事が多く、さらに、Dateに対して処理を行うと、秒ではなく日の値に変更される、という挙動になっていました。

Date.today + 2 * 1.day
# => Wed, 12 Apr 2490

こういう挙動は混乱の元になるだけで良くないだろう、という事でdeprecateになりました。5.2で削除される予定です。

因みに、逆(ActiveSupport::Durationに対してNumericの値を加減算する)は引き続き使用できます。

1.day * 2
# => 2 days

Fix typo in comment

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

メソッドのコメントでDividesDevidesにタイポしている箇所があったのを修正しています。

rails commit log流し読み(2017/03/02)

2017/03/02分のコミットです。

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

activesupport/CHANGELOG.md


Tell users how to assign a $EDITOR.

railties/lib/rails/commands/secrets/secrets_command.rbの修正です。

secrets:editコマンド実行時に、$EDITOR変数が設定されてない場合に$EDITORを設定するむねメッセージを表示するよう修正しています。

No $EDITOR to open decrypted secrets in. Assign one like this:

EDITOR="mate --wait" bin/rails secrets:edit

For editors that fork and exit immediately, it's important to pass a wait flag,
otherwise the secrets will be saved immediately with no chance to edit.

Put it to me straight: just say it.

railties/lib/rails/commands/secrets/secrets_command.rbの修正です。

先の$EDITORについてのメッセージを表示する際に、Kernelのputsメソッドを使用していたのをThorのsayメソッドを使用するよう修正しています。


[ci skip] Add changelog entry for encrypted secrets.

railties/CHANGELOG.mdの修正です。

encrypted secrets(Merge pull request #28128 from rails/revert-28127-revert-28038-encrypted-secrets)の対応について、CHANGELOGにエントリーを追加しています。


Merge pull request #28220 from kamipo/valid_type_accept_only_supported_types

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

type(e.g. integerstring等)がそのadapterでサポートされているかどうかをチェックする為のvalid_type?メソッドがsqlite3 adapterで必ずtrueを返すようになってしまっていたのを、適切にチェック処理を行うよう修正しています。


Update DateTime#change to support usec and nsec

activesupport/lib/active_support/core_ext/date_time/calculations.rbの修正です。

DateTime#changeメソッドで:usec、及び:nsecオプションを使用出来るよう修正しています。


Convert ENV["EDITOR"] to string before check

railties/lib/rails/commands/secrets/secrets_command.rbの修正です。

ENV["EDITOR"]が空かどうかをempty?でチェックする前に、でStringに変換するよう修正しています。ENV["EDITOR"]nilだった場合にNoMethodErrorになってしまう為。

rails commit log流し読み(2017/03/01)

2017/03/01分のコミットです。

CHANGELOGへの追加はありませんでした。


Revert “Dupping a CollectionProxy should dup the load_target”

CollectionProxy#dupが、load_targetdupするよう修正した、Dupping a CollectionProxy should dup the load_targetをrevertしています。

元となったissue(https://github.com/rails/rails/issues/17117)が、dupは元のレコード及びassociationのデータを返すべきである、という指摘だと思い上記対応を行ったのですが、実際は元のデータのコピーを期待していた(Rails 3までの挙動がそうだった)らしい、という事がわかったので一旦revertしたようです。多分。


Merge pull request #28063 from Erol/prioritize-callback-on-action-before-if

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

transaction callbacks で:onオプションの条件に当てはまらない場合、:ifオプションに指定された値が評価しないよう修正しています。

PRより。

class Topic < ActiveRecord::Base
  after_commit :do_something, on: [:create, :update], if: :check_something?
end

topic = Topic.create #=> Calls :check_something?
topic.save #=> Calls :check_something?
topic.destroy #=> No longer calls :check_something?

Merge pull request #28217 from kamipo/create_join_table_respects_reference_key_type

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

create_join_tableメソッドで生成される外部キーのtypeのデフォルトがintegerになっていたのを、referencesメソッドを使用するよう修正しています。

Change Default Primary Keys to BIGINTでデフォルトのPKがBIGINTに変更になっており、integerだとエラーになってしまう為。


Merge pull request #28210 from cefigueiredo/improve_required_test

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

ActiveRecord::Base.belongs_to_required_by_defaultにtrue, falseをそれぞれ明示的に設定した場合のテストを追加しています。


Merge pull request #28120 from vfonic/plugin-generator-skip-turbolinks-dummy

railties/lib/rails/generators/rails/plugin/plugin_generator.rbの修正です。

plugin / engineが生成するdummy applicationが、デフォルトでturbolinksをskipするよう修正しています。


Merge pull request #25296 from kamipo/use_inspect_for_type_cast_for_schema

Active Record / Active Modelの修正です。

date/time及びdecimalの値をschemaにdumpする際に、他の型同様にinspectメソッドを使用するよう修正しています。

PRより。

Before:

  create_table "defaults", force: :cascade do |t|
    t.string   "string_with_default",   default: "Hello!"
    t.date     "date_with_default",     default: '2014-06-05'
    t.datetime "datetime_with_default", default: '2014-06-05 07:17:04'
    t.time     "time_with_default",     default: '2000-01-01 07:17:04'
    t.decimal  "decimal_with_default",  default: 1234567890
  end

After:

  create_table "defaults", force: :cascade do |t|
    t.string   "string_with_default",   default: "Hello!"
    t.date     "date_with_default",     default: "2014-06-05"
    t.datetime "datetime_with_default", default: "2014-06-05 07:17:04"
    t.time     "time_with_default",     default: "2000-01-01 07:17:04"
    t.decimal  "decimal_with_default",  default: "1234567890"
  end

Merge pull request #28230 from y-yagi/HOST_to_be_in_uppercase

railties/lib/rails/commands/server/server_command.rbの修正です。

ENV["HOST"]ENV["Host"]にタイポしていたのを修正しています。


Whitelist adapters that support aliases in HAVING clause

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

having句で指定したaliasをselectに含む場合のテストを、Mysql2AdapterSQLite3Adapterでのみ実行するよう修正してます。

-    skip if current_adapter?(:PostgreSQLAdapter, :OracleAdapter)
+    skip unless current_adapter?(:Mysql2Adapter, :SQLite3Adapter)

上記挙動はSQL標準ではないため、ホワイトリストでサポートしているDBを明示する方が適切だろう、という事で修正されています。


Use DEFAULT_CIPHER constant in MessageEncryptor

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

MessageEncryptor#initializeメソッドでcipherのデフォルト値を設定するのにDEFAULT_CIPHER定数を使用するよう修正しています。


Merge pull request #28239 from y-yagi/use_appropriate_type_for_test_framework_option

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

generatorのtest_frameworkオプションのデフォルト値に不正な値(string型なのに、デフォルトにfalseを設定していた)を指定していたのを修正しています。

rails commit log流し読み(2017/02/28)

2017/02/28分のコミットです。

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

actionview/CHANGELOG.md


Oracle database also does not allow aliases in the having clause

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

having句で指定したaliasをselectに含む場合のテストを、OracleAdapterではskipするよう修正しています。

PostgresSQL同様、Oracleではhaving句でaliasを指定する事は出来ない為。


Remove encode_special_chars option from strip_tags

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

strip_tagsメソッドでsanitizerのsanitizeメソッドを呼び出す際に、encode_special_charsオプションを指定していたのを、オプション指定を削除しています。

rails-html-sanitizer v1.0.3からsanitizeメソッドのencode_special_charsオプションを無視するようになっており、オプションを指定する意味が無い為。


Use released webpacker in new applications

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

新規Railsアプリで使用するGemfileで、webpackerGitHubリポジトリを指定していたのを、rubygemsにリリース済みのgemを使用するよう修正しています。 webpacker 1.0がリリース済みな為。


Use tables instead of data_sources - views

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

SchemaDumper#tablesメソッドでtableを取得するのにdata_sourcesメソッドを使用していたのを、tablesメソッドを使用するよう修正しています。

-        sorted_tables = @connection.data_sources.sort - @connection.views
+        sorted_tables = @connection.tables.sort

data_sourcesメソッドはviewsの情報も含むが、tablesはtableの情報しか含まない為。


Take failed screenshot before reset driver

actionpack/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rbの修正です。

SystemTestCaseがテスト失敗時に自動で行うscreenshotの取得処理を、driverのリセット前に行うよう修正しています。driverのリセット後に行うと、テストを実行したdriverとscreenshotを取得するdriverが異なってしまう可能性があり、正確なscreenshotが取得出来ない為。


Dupping a CollectionProxy should dup the load_target

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

CollectionProxy#dupが、load_targetdupするよう修正しています。

元々Rails 3まではdupするようになっており、Rails 4からされなくなっていました。

で、Rails 3までの挙動に合わせる為、修正したとの事なのですが、これは後ほどrevertされています。


Fix http -> https [ci skip]

README.mdrailties/RDOC_MAIN.rdocの修正です。

Rails Tutorialへのリンクをhttpからhttpsに修正しています。


Improve documentation for Testing Your Mailers [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

The Basic Test Caseの項に、email.body.to_sはメールがHTML、Text両方あった場合に、片方のデータしか返さない旨説明を追加しています。合わせて、それぞれ個別に確認したい場合は、email.text_part.body.to_semail.html_part.body.to_sを使用するよう説明を追加しています。