なるようになるブログ

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

rails commit log流し読み(2019/03/15)

2019/03/15分のコミットです。

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


bumps Zeitwerk

activesupport/activesupport.gemspecの修正です。

Zeitwerkのバージョンを>= 1.3.4に修正しています。


Properly expand the environment's name in all commands

railtiesの修正です。

runnerserver及びcredentialsコマンドの-eオプションでenvironment's nameを指定した際に、自動で補完(prodと指定した場合、productionにしてくれる)するよう修正しています。

rails commit log流し読み(2019/03/14)

2019/03/14分のコミットです。

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


Merge tag 'v6.0.0.beta3'

Railsのバージョンをv6.0.0.beta3に更新しています。

今回はセキュリティリリースで、下記のセキュリティフィックスが含まれています(CVE-2019-5420のフィックスは5.2系、6.0系のみです)。

CVE-2019-5418は、ファイルコンテンツが漏えいする可能性がある脆弱性で、

def index
  render file: "#{Rails.root}/some/file"
end

のように、accept formatの指定なしでfileをrenderした場合に問題が起こる可能性があります。

CVE-2019-5419は、細工されたaccept headersが送信された場合に、Action Viewのtemplate生成処理が重くなり、処理が出来なくなる恐れがある、というものです。CVE-2019-5418と合わせて、サポートしていないformatは受け付けないようにして対応しています。

CVE-2019-5420は、対象のRailsアプリケーションの事がある程度わかっているとsecret tokenを推測出来てしまうという脆弱性です。このsecret tokenをRailsの内部構造の処理と組み合わせる事で、リモートでコードを実行出来てしまう可能性があります。なお、secret_key_baseが指定されている場合は問題ありません。secret_key_baseが指定されていない場合、tmpファイルにsecret_key_baseを作成しそれを使用するよう修正し対応しています。


Revert "Remove Marshal support from SchemaCache"

schema cacheのMarshalサポートの為のメソッドを削除した、Remove Marshal support from SchemaCacheをRevertしています。不要かと思ったらまだ使っているケースがあった為、との事です。


Fix gemfile.lock

Gemfile.lockの修正です。

先の6.0.0.beta3の対応の修正漏れの対応を行っています。


Add secret token for action mailbox tests

actionmailbox/test/dummy/config/initializers/secret_token.rbの修正です。

先の脆弱性の対応により必要になったsecret_key_baseの指定を追加しています。secret_key_baseの指定が無い場合tmpファイルを自動で作成するようになっているのですが、テストアプリのディレクトリ構成上、そのtmpファイルの作成処理がエラーになるので、config.secret_key_baseを直接しているようにして対応しています。


Fix secret_key_base for Railties

railties/test/application/url_generation_test.rbrailties/test/rails_info_controller_test.rbの修正です。

こちらもsecret_key_baseの指定を行うよう修正しています。


support slice assignment on SafeBuffer

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

SafeBufferでslice assignment(e.g. buffer[0, 3] = '<')が指定出来るよう対応しています。


Make application work without tmp directory

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

CVE-2019-5420で追加されたsecret_key_baseを記載したtmpファイルを作成する前に、tmpディレクトリを作成するよう修正しています。

tmpファイルはtmpディレクトリ配下(tmp/development_secret.txt)に作成するのですが、tmpディレクトリは存在しない可能性があり、存在しない場合にエラーになるのを防ぐ為。


GCS service: skip unnecessary bucket lookups

activestorage/lib/active_storage/service/gcs_service.rbの修正です。

GCS Serviceのbucket生成処理で、skip_lookupオプションを指定して不要なbucketのlookup処理を行わないよう修正しています。

rails commit log流し読み(2019/03/13)

2019/03/13分のコミットです。

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


Update small typo in documentation.

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

ActionController::Helpers moduleのdoc内のexampleコードで参照するクラス名をタイポしていたのを修正しています。


Initialize @default_timezone and @timestamp_decoder in add_pg_decoders

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

@default_timezone@timestamp_decoderの初期化をadd_pg_decodersメソッド内で行うよう修正しています。

初期化をadd_pg_decodersメソッド内で行わないと、disconnect!の後にreconnect!した場合に古い値のままになってしまい、結果エラーになってしまう為。


Remove unused Row class in SelectManager

activerecord/lib/arel/select_manager.rbの修正です。

使用していないRowクラスを削除しています。


Update URL in RELEASING_RAILS.md [ci skip]

RELEASING_RAILS.mdの修正です。

https://git-scm.com/book へのリンクが存在しないページへのリンクになっていたのを修正しています。


Remove Marshal support from SchemaCache

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

schema cacheのMarshalサポートの為のメソッドを削除しています。

Use YAML to serialize schema cacheから、schema cacheのserialize処理にはYAMLが使用されるようになり、Marshalを使用する事は無くなった為。


Modernize size calculation in Schema Cache

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

sizeを計算するのにmap + injectを使用していたのを、sumメソッドを使用するよう修正しています。


Schema Cache: cache table indexes

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

schema cacheでtable indexもcacheするよう修正しています。


Document int Primary Key with create_or_find_by (#35573)

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

create_or_find_byメソッドのdocに、insertに失敗した場合もprimary keyの値はインクリメントされるので、primary keyにintegerを使用している場合にintegerの上限に達しやすくなってしまう旨注記を追加しています。


Add test for runner command with environment option

railties/test/application/runner_test.rbの修正です。

rails runnerコマンドにenvironmentオプションを指定した場合のテストを追加しています。


Fix rubocop violations

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

rubocopの設定に違反している箇所があったのを修正しています。


[skip ci] Rails 5.1+ supports bigint primary key

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

primary keyにbigintを使用するようになったRailsのバージョンが5.0+記載されていたのですが、実際は5.1+だったのでその旨修正しています。


Indentation >>

railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb.ttの修正です。

scaffold generatorで生成する_form.erb.ttで、タグのインデントが不足している箇所があったのを修正しています。


Fix typo s/ActiveSupport::Timezone/ActiveSupport::TimeZone/ [ci skip]

activesupport/CHANGELOG.mdの修正です。

ActiveSupport::TimeZone.allActiveSupport::Timezone.allにタイポしていたのを修正しています。

rails commit log流し読み(2019/03/12)

rails commit log流し読み(2019/03/12)

2019/03/12分のコミットです。

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

activemodel/CHANGELOG.md

activesupport/CHANGELOG.md


Merge pull request #35485 from excid3/default-attachable-trix-partial

actiontext/lib/action_text/attachable.rbの修正です。

ActionText::Attachable moduleにto_trix_content_attachment_partial_pathメソッド(Trixでattachementを表示する際に使用するメソッド)を定義し、ActionText::Attachableをincludeしているmodelで同じpathを参照するよう修正しています。


Add locale option to parameterize

activesupport/lib/active_support/core_ext/string/inflections.rbactivesupport/lib/active_support/inflector/transliterate.rbの修正です。

String#parameterize、及び、ActiveSupport::Inflector#parameterizeActiveSupport::Inflector#transliterateメソッドの引数にlocaleオプションを追加しています。これらのメソッドは最終的にI18n.transliterateを呼ぶようになっているのですが、I18n.transliterateでは元々localeを指定出来るようになっており、オプションをそのまま渡すようになっています。


Merge pull request #34965 from bogdanvlviv/improve-rails-encrypted--help

railties/lib/rails/commands/encrypted/USAGErailties/lib/rails/commands/encrypted/encrypted_command.rbの修正です。

encryptedコマンド用のUSAGEファイルを追加し、encryptedコマンドのヘルプでコマンドについての詳細を表示するよう修正しています。


[ci skip] Improve encrypted commands USAGE

railties/lib/rails/commands/encrypted/USAGEの修正です。

encryptedコマンドのUSAGEにEncryption Keysについての詳細な説明を追加、及び、各箇所の言い回し等を修正しています。


Merge pull request #34955 from bogdanvlviv/follow-up-33962

Restructure credentials after environment overrides.のfollow upとして、rails guideのConfiguring Rails Applicationsconfig.credentials.content_path、及び、config.credentials.key_pathについての説明を追加、及び、各箇所のタイポを修正しています。


Fix bug with parametrize when locale is passed

Active Supportの修正です。

先のlocaleオプションを追加した対応で、オプションの指定方法が誤っていた箇所があったのを修正、及び、全く無かったテストを追加しています。


Do not generate dummy string when the tag used is not the <%=

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

Load YAML for rake tasks without parsing ERBでDB用のtaskをロードする際にdatabase.ymlをERBのパース無しで読み込むようにしたのですが、それだと逆にERBを使用して動的にdatabase.ymlを生成している際に困る、という問題が発生しました。

その対応として、タグが<%=を使用している場合のみダミー文字列を使用する(ERBのパースを行わない)よう修正を行うようにしています。


overriden -> overridden [ci skip]

railties/lib/rails/commands/encrypted/USAGEの修正です。

overriddenoverridenにタイポしていたのを修正しています。


bump Zeitwerk to 1.3.3

activesupport/activesupport.gemspecの修正です。

zeitwerkのバージョンを>= 1.3.3に修正しています。


Merge pull request #35424 from Korri/validation-rules-locale-fallback

activemodel/lib/active_model/errors.rbの修正です。

error messageをi18nで変換する際に、他のロケールを見るより先にgeneric messageにフォールバックしていたのを、他のロケールの値を確認するよう修正しています。

例えば、Product modelのtitle attributeでblankエラーがen-US localeで発生した場合のi18nのルックアップ処理が、以下のように変更されています。

before

en-US.activerecord.errors.models.product.attributes.title.blank
en-US.activerecord.errors.models.product.blank
en-US.activerecord.errors.messages.blank
en-US.errors.attributes.title.blank
en-US.errors.messages.blank

en.activerecord.errors.models.product.attributes.title.blank
en.activerecord.errors.models.product.blank
en.activerecord.errors.messages.blank
en.errors.attributes.title.blank
en.errors.messages.blank

after

en-US.activerecord.errors.models.product.attributes.title.blank
en-US.activerecord.errors.models.product.blank
en-US.activerecord.errors.messages.blank

en.activerecord.errors.models.product.attributes.title.blank
en.activerecord.errors.models.product.blank
en.activerecord.errors.messages.blank

en-US.errors.attributes.title.blank
en-US.errors.messages.blank

en.errors.attributes.title.blank
en.errors.messages.blank

Add changelog entry for transliterate/parameterize accepting locale [ci skip]

activesupport/CHANGELOG.mdの修正です。

transliterateとparameterizelocale`オプションを指定出来るようにした対応について、CHANGELOGにエントリーを追加しています。


Add note about has_many associations callbacks [ci skip]

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

Association Callbacksの項に、association callbackはassociationが追加 / 削除された時だけ実行される旨説明を追加しています。


After https://github.com/rails/rails/pull/35281 and https://github.com/rails/rails/pull/35036 AV warns about not having the compiled container.

guides/rails_guides/generator.rbの修正です。

guideのgeneratorでtemplate cacheに関するwarningが出ていたので、with_empty_template_cacheメソッドを使用してインスタンスを生成するよう修正しています。


Show friendly message to install action mailbox if the related table does not exist

actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erbactionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erbの修正です。

エラーページを表示する際に、エラーがAction Mailboxのテーブルが無い事によるエラーだった場合、エラーページにrails action_mailbox:installを実行すれば解決する旨説明を記載するよう修正しています。


Add additional ERB DummyCompiler tests

railties/test/application/rake/dbs_test.rbの修正です。

ERB DummyCompiler(database.ymlをERBのパース無しで読み込む際に使用する為のクラス)についてのテストを追加しています。


Edit a changelog entry [ci skip]

activemodel/CHANGELOG.mdの修正です。

CHANGELOG entryのグラマーの修正を行っています。


Change wording of some instances of 'opt out' [ci skip]

docの修正です。

各箇所のグラマーの修正を行っています。

rails commit log流し読み(2019/03/11)

2019/03/11分のコミットです。

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

activerecord/CHANGELOG.md


Merge pull request #35121 from utilum/warning_tried_to_create_proc_without_block

blockを明示的に指定せずにProcを生成している箇所(メソッドの引数のブロックが使用されていた箇所)があったのを修正しています。

Ruby 2.6までは、blockを指定せずにProcを生成する事が出来、その場合、メソッドへ渡されたブロックがそのまま使用されていました。ただ、この挙動がRuby 2.7からwarningが出るようになった為、メソッドの引数にblockが来ることを期待している箇所は、メソッドの引数にblock用の変数を追加するよう修正しています。

参考: ruby-trunk-changes r66760 - r66776


Merge pull request #35449 from pjrebsch/quoting-empty-range

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

空の配列に関するquote処理が正しく行われていないバグがあったのを修正しています。

# before
User.where('id = ?', 0...0).to_sql
#=> "SELECT \"users\".* FROM \"users\" WHERE (id = )"

# after
User.where('id = ?', 0...0).to_sql
#=> "SELECT \"users\".* FROM \"users\" WHERE (id = NULL)"

Fix query attribute method on user-defined attribute to be aware of typecasted value

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

ユーザが定義したattributeに対してquery attribute methodを実行した際に、type castした値が使用されないバグがあったのを修正しています。


Fix random CI failure due to non-deterministic sorting order

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

find_byのテストで使用するmodelを変更しています。元のmodelだとデータが複数あり、取得されるデータが非決定的でランダムでテストが失敗してしまう事がある為。


Add example of the output of rails routes --expanded in the routing guide [ci skip]

rails guideのRails Routing from the Outside Inの修正です。

Listing Existing Routesの項に、rails routes--expandedを指定した場合のexampleを追加しています。


Remove MigrationTest#test_create_table_with_custom_sequence_name

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

Oracle enhanced adapterの場合のみ実行していたテストを削除しています。Oracle enhanced adapter側で該当のテストを実行するようにする為との事です。


Merge pull request #35525 from audiolion/feature/dynamic-actioncable-websocket-url

actioncable/app/javascript/action_cable/index.jsの修正です。

Action CableのWebSocket URLにfunctionを指定出来るようにしています。authorization tokenを指定する場合等、動的にURLを生成したいケースがある為。


Use the -u switch for the rails server banner

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

rails serverコマンドのヘルプに、deprecatedになったオプションの指定方法が表示されていたのを修正しています。


Mention environment variable instead of just environment

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

CHANGELOG、deprecatedメッセージ内のenvironmentenvironment variableに修正しています。


Fix style issues and build source after #35525

actioncable/app/assets/javascripts/action_cable.jsactioncable/app/javascript/action_cable/index.jsの修正です。

先のWebSocket URLにfunctionを指定出来るようにした対応で、ソースのbuild処理が不足していたのを対応、及び、lintに違反しているコードがあったのを修正しています。


Squish the deprecation messages across the codebase

各箇所のdeprecatedメッセージを表示する際に、不要な空白が表示されないよう修正しています。


[ci skip] Removed extra hyphens

rails guideのRails Routing from the Outside Inの修正です。

rails routes--expandedを指定した場合のexampleから、不要なハイフンを削除しています。

rails commit log流し読み(2019/03/10)

2019/03/10分のコミットです。

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


Fixed autosave association test typo

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

テストでassociationasssociationにタイポしていたのを修正しています。


Fix reconnect! to work after disconnect!

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

disconnect!を使用した後にreconnect!を使用した場合に、正しくconnect処理が行われるよう修正しています。


SQLite3: Set busy_timeout in configure_connection

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

configure_connectionメソッドでbusy_timeoutの設定を行うよう修正しています。これも先ほどのコミット同様disconnect!を使用した後のreconnect!が動作するようにする為の対応との事です。


Revert an incorrect change in jquery-2.2.0.js

actionview/test/ujs/public/vendor/jquery-2.2.0.jsの修正です。

Railsのコードではないjquery-2.2.0.jsのコードを、[ci skip] Minor documentation fixes for consistency[ci skip] Fix typosで修正してしまっていたのを、元に戻しています。


Don't test disconnect! if in memory db

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

in memory dbではdisconnect!のテストを行わないよう修正しています。in memory dbではdisconnect!してしまうと全てのtableとfixutreのデータが失われてしまう為。


PostgreSQL: Add add_pg_encoders and add_pg_decoders in connect

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

connectメソッドでadd_pg_encodersadd_pg_decodersメソッドを呼び出すよう修正しています。これもdisconnect!を使用した後のreconnect!が動作するようにする為の対応との事です。


Added missing guide links in README documentation and minor wording fix [ci skip]

コンポーネントのREADMEに、関連するGuideへのリンクを追加しています。


Support other optional parameters and quoted-strings on Content-Type parser

actionpack/lib/action_dispatch/http/response.rbの修正です。

Content Type headerのパース処理で、headerにcharset以外のoptional parametersがあった場合、及び、charsetの値がquoteされている場合に正しくtype / charsetが取得出来るよう修正しています。

rails commit log流し読み(2019/03/09)

2019/03/09分のコミットです。

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


Allow autoloader inflectors to be swaped out

activesupport/lib/active_support/dependencies/zeitwerk_integration.rbrailties/lib/rails.rbrailties/lib/rails/autoloaders.rbの修正です。

Zeitwerk autoloader inflectorの指定処理をアプリ初期化時に行うよう修正しています。config/application.rb内で任意のinflectorを指定出来るようにする為。


moves a require to the file that needs it

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

ファイルのrequire処理を実際にそのファイルを使用している箇所で行うよう修正しています。


Improve wording in cache documentation [ci skip]

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

各メソッドのdocの言い回しを修正しています。


- Remove the word painfully from documentation

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

Calling the Mailer項の言い回しを修正しています。


Read the CSP nonce on page load

actionview/app/assets/javascripts/rails-ujs/start.coffeeactionview/app/assets/javascripts/rails-ujs/utils/csp.coffeeの修正です。

CSP nonceの読み込み処理をページロード時に行うよう修正しています。

Turbolinksはページ変更時にCSP nonceが指定されているmetaタグの置き換えを行うのですが、ujsによって挿入されたインラインスクリプトはページロード時に指定されていたnonceの値が必要な為、置き換え前の値を使用出来るようにするために、ページロード時に値を読み込むよう修正しています。


Minor text changes to the db:seed:replant tests

railties/test/application/rake/dbs_test.rbの修正です。

db:seed:replant taskのテストの、テスト名のグラマーを修正しています。


Merge pull request #35538 from sharang-d/use-latest-webpacker

新規に作成したアプリケーションで、webpackerのバージョン指定が>= 4.0.0.rc.3になっていたのを~> 4.0.0に修正、及び、テストで使用しているwebpackerのバージョンも4系に更新しています。


Fix "DEPRECATION WARNING: ActionView::Template#initialize requires a locals parameter"

railties/test/backtrace_cleaner_test.rbの修正です。

テストでActionView::Template#initializeの引数に指定に関するdeprecation warningが出ていたのを対応しています。


Don't lock the webpacker gem by its patch version

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

先のwebpackerのバージョン指定でパッチバージョンでロックしていたのを、マイナーバージョンの変更まで許容するよう修正しています。基本的にパッチバージョンでのロックは宜しくない(マイナーバージョンのリリースの度に修正が必要になってしまう)為。


Minor documentation fixes related to bulk insert [skip ci]

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

bulk insert処理に関する説明、グラマー等の修正を行っています。


Guides: Fix parent class of model test example (#35065)

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

Custom Assertions And Testing Jobs Inside Other Componentsの項にあるexampleをActiveJob::TestHelperを明示的にincludeする方法に修正しています。直前の説明の内容と合わせる為。


[ci skip] Minor documentation fixes for consistency

各箇所のuse-casesuse casesに修正しています。


Updated links from http to https in guides, docs, etc

rubyonrails.orgへのリンクがhttpになっていた箇所をまとめてhttpsに修正しています。


Merge pull request #35531 from boblail/issue-35519

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

upsert_allのdocに記載されていたexampleがinsertとreplaceを一緒に行う内容だったのを、insert(又はupdate)のみ行うよう修正しています。

SQLite3及びMySQLでは動作する内容だったのですが、PostgreSQL(及びSQL-2003に定義されているMERGEのルール)では動作しない処理の為。


Merge pull request #35527 from tight/improve_doc_of_automatic_inverse_of

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

Associationsに関するdocのinverse_ofの自動検出について説明している箇所に、custom scopeがある場合も自動検出が動作しない旨説明を追加しています。


Fix links in gemspec and docs from http to https.

引き続きrubyonrails.orgへのリンクがhttpになっていた箇所をhttpsに修正しています。