なるようになるブログ

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

rails commit log流し読み(2019/01/18)

2019/01/18分のコミットです。

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

railties/CHANGELOG.md

actionpack/CHANGELOG.md

actionview/CHANGELOG.md

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


Merge pull request #34213 from matildasmeds/guides_session_guidelines_2

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

古いバージョンに関する説明を削除、諸々言い回しを修正、Action Controller guide・Custom Credentialsの項へのリンクの追加等々を行っています。


Make trix a peer dependency of actiontext since it’s not used directly

actiontext/app/javascript/actiontext/index.jsactiontext/package.jsonの修正です。

trixのdependencyをpeer dependencyに移動しています。Action Textは直接はtrixを使用していない為。


Tidy up action_text:install task

actiontext/lib/templates/installer.rbの修正です。

action_text:install task実行時に必要なjsのpackageのインストールも行うよう修正しています。


Merge pull request #34953 from gmcgibbon/seed_with_inline_jobs

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

seedを読み込む際にActive Jobのadapterを強制的にinlineにするよう修正しています。

seedでActive Storageのattachmentを登録する、かつ、adapterがasnycの場合処理が完了しない(デットロックになってしまいハングしてしまう)為、強制的にinline adapterを使用するよう修正しています。


Ensure Action Mailbox processes an email only once when received multiple times

Action Mailboxの修正です。

同じメールを複数回受信した場合に、一度だけ処理を行うよう修正しています。同一かどうかの判定用に、checksum(Digest::SHA1.hexdigestで生成)の値も保持するよう修正しています(message idが無かった場合にchecksumで同一判定出来るようにする為)。


Ensure external redirects are explicitly allowed

Action Packの修正です。

redirect_toメソッドで、明示的に許可されている(allow_other_hostオプションにtrueが指定されている)場合のみ、外部サイトへのredirectを許可するよう修正しています。allow_other_hostがfalse(デフォルト)の状態で外部サイトにredirectしようとすると、ArgumentErrorになるようなっています。


Ensure that AR::Relation#exists? allows only permitted params

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

exists?メソッドの引数にActionController::Parametersインスタンスを指定出来る事を確認するテストを、permitted paramのみ使用される事を確認するよう修正しています。


Specify a name for [ message_id, message_checksum ] index to ensure the name does not exceed the limit.

actionmailbox/db/migrate/20180917164000_create_action_mailbox_tables.rbの修正です。

action_mailbox_inbound_emailsのmessage_id + message_checksumのindexに明示的にnameを指定するよう修正しています。nameの指定が無いとindex長でエラーになる為。


Use create_and_extract_message_id! to create an inbound email.

actionmailbox/app/controllers/rails/conductor/action_mailbox/inbound_emails_controller.rbの修正です。

inbound emailを作成する際に、ActionMailbox::InboundEmail.create_and_extract_message_id!メソッドを使用するよう修正しています。checksumとmessage idがセットされるようにする為。


Update the promisse that ActionController::TestCase will be extracted

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

ActionController::TestCaseについて説明している箇所で、Rails 5.1でgemに切り出す旨記載されいたのを、"the future"と記載するよう修正しています。gemに切り出すつもりはあるのですが、それをいつ行うかはまだ未定の為。


Remove deprecated methods in ActionDispatch::TestResponse

actionpack/lib/action_dispatch/testing/test_response.rbの修正です。

deprecatedになっていたActionDispatch::TestResponseのメソッド(success?missing?error?等)を削除しています。


Remove deprecated fragment_cache_key helper in favor of combined_fragment_cache_key

actionpack/lib/abstract_controller/caching/fragments.rbの修正です。

deprecatedになっていたfragment_cache_keyメソッドを削除しています。


Remove deprecated image_alt helper

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

deprecatedになっていたimage_altメソッドを削除しています。


Remove deprecated expand_hash_conditions_for_aggregates

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

deprecatedになっていたexpand_hash_conditions_for_aggregatesメソッドを削除しています。


Remove deprecated ActiveRecord::Migrator.migrations_path=

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

deprecatedになっていたActiveRecord::Migrator.migrations_path=メソッドを削除しています。


Remove ability to specify a timestamp name for #cache_key

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

deprecatedになっていたcache_keyメソッドのtimestamp引数を削除しています。


Change SQLite3Adapter to always represent boolean values as integers

Active Recordの修正です。

SQLite 3 adapterでbooleanの値を保持するのにintegerを使用するよう修正しています。合わせて、挙動を指定する為のconfig.activerecord.sqlite3.represent_boolean_as_integerはdeprecateになりました。


Remove delegation of missing methods in a relation to private methods of the class

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

deprecatedになっていたrelationからclassのprivate methodへのdelegationを削除しています。


Remove delegation of missing methods in a relation to arel

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

deprecatedになっていたrelationからarelへのdelegationを削除しています。


Do not allow passing the column name to count when a block is passed

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

deprecatedになっていたcountメソッドにblock + column name引数両方を指定した場合の処理を削除しています。


Do not allow passing the column name to sum when a block is passed

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

deprecatedになっていたsumメソッドにblock + column name引数両方を指定した場合の処理を削除しています。


Remove deprecated ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?

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

deprecatedになっていたActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?メソッドを削除しています。


Remove deprecated #insert_fixtures from the database adapters

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

deprecatedになっていたinsert_fixturesメソッドを削除しています。


Remove deprecated #supports_statement_cache? from the database adapters

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

deprecatedになっていたsupports_statement_cache?メソッドを削除しています。


Remove deprecated #set_state from the transaction object

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

deprecateになっていたTransactionState#set_stateメソッドを削除しています。


Remove deprecated #acronym_regex method from Inflections

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

deprecatedになっていたInflections#acronym_regexメソッドを削除しています。


Remove deprecated Module#reachable? method

activesupport/lib/active_support/core_ext/module.rbactivesupport/lib/active_support/core_ext/module/reachable.rbの修正です。

deprecateになっていたModule#reachable?メソッドを削除しています。


Remove deprecated config.secret_token

railtiesの修正です。

deprecateになっていたconfig.secret_tokenを削除しています。


Remove secret_token rack env and cookie upgrade code

Action Packの修正です。

cookiesecret_tokenに関する処理を削除しています。config.secret_tokenが削除された事により動作しなくなった為。


Remove deprecated capify!

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

deprecateになっていたcapify!メソッドを削除しています。


Remove deprecated environment argument from the rails commands

railtiesの修正です。

deprecatedになっていたrails console、rails dbconsoleコマンドのenvironment引数を削除しています。


Remove deprecated support to old config.ru that use the application class as argument of run

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

deprecatedになっていいたconfig.ru内のrunメソッドににRails::Applicationのサブクラスを指定した場合の処理を削除しています。


Remove deprecated server argument from the rails server command

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

rails serverコマンドにRack server nameをオプションなしで指定した場合の処理を削除しています。

deprecatedだった為、となっていますが、この機能がdeprecatedになったのはRails 6から削除対象では無いため、後ほどrevertされています。


Remove deprecated after_bundle helper inside plugins templates

railtiesの修正です。

deprecatedになっていたplugins templatesの中でのafter_bundleメソッドの実行を削除しています。


Use released webpacker

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

rails自体でリリース済みのwebpackerを使用するよう修正、及び、新規に作成するRailsアプリではwebpacker 4.0.0.rc.3以上を使用するようバージョン指定を追加しています。


Action Text: bundle package.json in built gem.

actiontext/actiontext.gemspecの修正です。

Action Textのgem packageにpackage.jsonも含むよう修正しています。

action_text:install taskでpackage.jsonを使用する(依存しているパッケージのインストールに使用している)為。


Merge pull request #34963 from dylanahsmith/better-composed-of-single-field-query

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

mappingがある場合のaggregate処理のqueryがシンプルなqueryになるよう修正しています。

例。

class Customer < ActiveRecord::Base
  composed_of :balance, class_name: "Money", mapping: %w(balance amount)
end
# before
Customer.where(balance: (1..50).map { |amount| Money.new(amount) }).to_sql
#=> SELECT "customers".* FROM "customers" WHERE ((((((((((((((((((((((((((((((((((((((((((((((((("customers"."balance" = 1 OR "customers"."balance" = 2) OR "customers"."balance" = 3) OR "customers"."balance" = 4) OR "customers"."balance" = 5) OR "customers"."balance" = 6) OR "customers"."balance" = 7) OR "customers"."balance" = 8) OR "customers"."balance" = 9) OR "customers"."balance" = 10) OR "customers"."balance" = 11) OR "customers"."balance" = 12) OR "customers"."balance" = 13) OR "customers"."balance" = 14) OR "customers"."balance" = 15) OR "customers"."balance" = 16) OR "customers"."balance" = 17) OR "customers"."balance" = 18) OR "customers"."balance" = 19) OR "customers"."balance" = 20) OR "customers"."balance" = 21) OR "customers"."balance" = 22) OR "customers"."balance" = 23) OR "customers"."balance" = 24) OR "customers"."balance" = 25) OR "customers"."balance" = 26) OR "customers"."balance" = 27) OR "customers"."balance" = 28) OR "customers"."balance" = 29) OR "customers"."balance" = 30) OR "customers"."balance" = 31) OR "customers"."balance" = 32) OR "customers"."balance" = 33) OR "customers"."balance" = 34) OR "customers"."balance" = 35) OR "customers"."balance" = 36) OR "customers"."balance" = 37) OR "customers"."balance" = 38) OR "customers"."balance" = 39) OR "customers"."balance" = 40) OR "customers"."balance" = 41) OR "customers"."balance" = 42) OR "customers"."balance" = 43) OR "customers"."balance" = 44) OR "customers"."balance" = 45) OR "customers"."balance" = 46) OR "customers"."balance" = 47) OR "customers"."balance" = 48) OR "customers"."balance" = 49) OR "customers"."balance" = 50)


# after
Customer.where(balance: (1..50).map { |amount| Money.new(amount) }).to_sql
#=> SELECT "customers".* FROM "customers" WHERE "customers"."balance" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)

Merge pull request #34956 from kamipo/actionmailbox_datetime_precision

actionmailbox/db/migrate/20180917164000_create_action_mailbox_tables.rbの修正です。

action_mailbox_inbound_emails tableでprecisionをサポートしている場合のにtimestampsにprecisionオプションを指定するよう修正しています。MySQL 5.5ではdatetimeにprecisionは指定出来ない為。


Revert "Remove deprecated server argument from the rails server command"

rails serverコマンドにRack server nameをオプションなしで指定した場合の処理を削除した、Remove deprecated server argument from the rails server commandをrevertしています。Rails 6で削除対象では無いため。


Use unboundable? rather than boundable?

Active Recordの修正です。

boundable?メソッドの代わりにunboundable?メソッドを定義、及び使用するよう修正しています。

infinite?メソッドと同じような使い方を出来るようにする為、のようです。おそらく。


Merge pull request #34969 from eileencodes/fix-error-message-for-multi-db-apps

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

指定されたadapterがDBのconfigに存在しなかった場合のエラーメッセージが、adapter名のみ表示していたのを、env名と合わせて表示するよう修正しています。

例。

'doesnexist' database is not configured. Available: development,
development, test, test, production, production
(ActiveRecord::AdapterNotSpecified)
The `doesntexist` database is not configured for the `production`
environment. (ActiveRecord::AdapterNotSpecified)

Available databases configurations are:

development: primary, primary_readonly
test: primary, primary_readonly
production: primary, primary_readonly

Merge pull request #34972 from krzysiek1507/fix/date-advance-performance

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

Date#advanceメソッドでoptionsの複製処理を無くすようリファクタリングを行っています。


Merge pull request #34959 from alkesh26/action-cable-typo-fixes

Action Cableの修正です。

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


Merge pull request #30000 from kamipo/all_of_queries_should_return_correct_result

Active Recordの修正です。

RangeErrorの扱いに誤りがあり、巨大な数字を含むqueryを実行した場合に正しい結果が取得出来ない、というバグがあったのを修正しています。