なるようになるブログ

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

rails commit log流し読み(2021/01/12)

2021/01/12分のコミットです。

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


Fix typo in Action Text Overview guide

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

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


Add round up assertions for decimal tests

activemodel/test/cases/type/decimal_test.rbの修正です。

decimalのテストで、round upした値についてもチェックするよう修正しています。


Use _read_attribute instead of []

activerecord/lib/active_record/associations/belongs_to_association.rbactiverecord/lib/active_record/associations/belongs_to_polymorphic_association.rbの修正です。

reflectionからforeign_keyを取得する際に[]メソッドの代わりに_read_attributeを使用するよう修正しています。

_read_attributeの方が速いのと、selectを使ってattributeが制限されている場合にエラーにならない為。


Restore the ability that update/destroy optimistic locking object without default

activemodel/lib/active_model/attribute.rbactiverecord/lib/active_record/locking/optimistic.rbの修正です。

Revert "Fix update with dirty locking column to not match latest object accidentally"のRevert commitにより、default valueの指定が無いoptimistic lockingを使用しているobjectのupate / destroyが出来なくなっていたのを、再度出来るよう対応しています。


Inlining locked?

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

arelがlocked?かどうかのチェックをインラインで行うよう修正しています。


Fix find_by with custom primary key for belongs_to association

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

belongs_to association + primary keyをcustomしている場合に、find_byにassociationを指定した場合にcustom primary keyによる検索が行われないバグがあったのを修正しています。

rails commit log流し読み(2021/01/11)

2021/01/11分のコミットです。

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


Merge pull request #41026 from santib/use-4xx-for-validations-errors-responses

scaffold generatorが生成するコードで、エラーになった際のHTTP statusに200を使用していたのを、422を使用するよう修正、及び、各docを修正しています。

Turboが4xx(または5xx)じゃないとエラーの表示を正しく行えない為。

rails commit log流し読み(2021/01/10)

2021/01/10分のコミットです。

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


Extract distinct_relation_for_primary_key on connection

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

relationのdistinct処理をコネクションのメソッドに切り出しています。adapter毎に処理をカスタマイズ出来るようにする為、とのことです。

rails commit log流し読み(2021/01/09)

2021/01/09分のコミットです。

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

actionview/CHANGELOG.md


Fix failing tests introduced by #41030

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

Fix preventing writes for ApplicationRecordの対応の影響でisolationテストがfailするようになってしまってしたのを修正しています。


Merge pull request #41052 from bogdanvlviv/preload_links_header-clarification

railties/test/application/configuration_test.rb、及び、rails guideのConfiguring Rails Applicationsの修正です。

Results of config.load_defaultsの項に、config.action_view.preload_links_headerについての説明を追加、load_defaults 6.0した際のpreload_links_headerのデフォルト値について確認するテストを追加しています。


Merge PR #41055

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

configに、action_view.button_to_generates_button_tagを指定しても、そのconfigが反映されないバグがあったのを修正、及び、docにconfig.action_view.button_to_generates_button_tagについての説明を追加しています。


Merge pull request #41043 from dbussink/default-sha256-digest

Active Support、railtiesの修正です。

ActiveSupport::Digestでデフォルトのdigest classにSHA1を使用していたのを、SHA256を使用するよう修正しています。


Merge pull request #41014 from dbussink/specific-sha256-usage

Active Supportの修正です。

Digest::SHA2 classを使用している箇所、Digest::SHA2を使用しないよう修正しています。

Digest::SHA2は暗黙的にSHA256を使用するようになっているのですが、OpenSSLには同名のクラスは存在しなく(OpenSSL::Digest::SHA2はない)、OpenSSL配下のクラスをconfig等に使用させる際に混乱の元となる為、Digest::SHA2を使用しないよう修正してます。


Translate FormBuilder#button calls with formmethod:

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

ActionView::Helpers::FormBuilder#buttonformmethod attributeを_method="$VERB"に変換するよう修正しています。1つのフォームで、ボタン毎に異なるHTTP verbを使用出来るようにする為。

<%= form_with model: post, method: :put do %>
  <%= form.button "Update" %>
  <%= form.button "Delete", formmethod: :delete %>
<% end %>

# =>
# <form action="posts/1">
#   <input type="hidden" name="_method" value="put">
#   <button type="submit">Update</button>
#   <button type="submit" formmethod="post" name="_method" value="delete">Delete</button>
# </form>

Fix where on polymorphic association with empty array

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

whereでpolymorphic associationに空のArrayを指定した場合にエラーになってしまうバグがあったのを修正しています。


Inlining force_clear_transaction_record_state

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

専用のメソッドで行っていたtransaction record stateのclear処理を、各箇所でインラインで行うよう修正しています。


Merge pull request #41063 from kamipo/fix_where_with_polymorphic_association_2


Enable Lint/DuplicateRequire cop

.rubocop.ymlactiverecord/test/cases/associations/inverse_associations_test.rbの修正です。

Lint/DuplicateRequire copを追加、及び、activerecord/test/cases/associations/inverse_associations_test.rbから重複していたrequireを削除しています。

rails commit log流し読み(2021/01/08)

2021/01/08分のコミットです。

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


Fix has_many_inversing with touch: true on a belongs_to association with inverse

activerecord/lib/active_record/associations/belongs_to_association.rbactiverecord/lib/active_record/associations/belongs_to_polymorphic_association.rbの修正です。

has_many_inversingがtrue + belongs_toにtouchの指定がある場合に、touch処理で親assocationが削除済みの子associationをロードしようとしてエラーになってしまう事があったのを修正しています。


Add key_generator_hash_digest_class to the new frameworks default file

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_2.rb.tt、及び、Rails guideのUpgrading Ruby on Railsの修正です。

new_framework_defaults_6_2.rbkey_generator_hash_digest_class = OpenSSL::Digest::SHA256の指定を追加、及び、guideにkey generatorを変更する場合のkeyのrotaionの方法についての説明を追加しています。


Revert "Fix update with dirty locking column to not match latest object accidentally"

locking columnを明示的に更新する際に誤ってstable objectを更新してしまう可能性があったのを修正した、Fix update with dirty locking column to not match latest object accidentallyをRevertしています。

この修正により、dirtyなlock_versionにより更新を成功/失敗させる事が出来なくなったのですが、その処理に依存した使い方docに説明にされており、既存のアプリの挙動を壊さないようにするためRevertしています。


Update ActionCable docs [ci skip]

actioncable/lib/action_cable/channel/streams.rbのdoc、及び、rails guideのAction Cable Overviewの修正です。

ActionCable.server.broadcastのexampleコードで、明示的な{}の指定を追加しています。指定が無いとRuby 3.0でArgumentErrorになってしまう為。


Merge pull request #41030 from eileencodes/fix-preventing-writes-again

Active Recordの修正です。

ApplicationRecordpreventing_writes?を実行した際に、正しい結果が取得出来ないバグがあったのを修正しています。


Merge pull request #41046 from eileencodes/dont-check-if-qc-is-enabled

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

query cacheを取得する際に、query_cache_enabledにfalseが指定されているconnetionは取得しないようにしていたのを、取得するよう修正しています。既にcacheが有効になっている場合、明示的に除外する必要は無いはず、の為。


Unite Active Storage configs in load_defaults '6.1' into one if-section

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

load_defaultsメソッド内のActive Storageに関する処理を1つにまとめています。

rails commit log流し読み(2021/01/07)

2021/01/07分のコミットです。

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


Remove update_table_definition entry from migration log

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

古いRailsのバージョンで作られたmigrationファイル、かつ、その中でadd_referenceを使用している場合に、そのmigrationファイル実行時のログが不要な情報を含むログになってしまっていたのを修正しています。


Allow configuration of the digest class used in the key generator

activesupport/lib/active_support/key_generator.rbactivesupport/lib/active_support/railtie.rbの修正です。

ActiveSupport::KeyGeneratorで使用するdigest classをconfigで指定出来るよう対応、及び、デフォルトのdigestにSHA1を使用していたのを、SHA256を使用するよう修正しています。現在だとSHA1はセキュリティ的に問題がある為。

rails commit log流し読み(2021/01/06)

2021/01/06分のコミットです。

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

activemodel/CHANGELOG.md


Keep Preloader#preload API the same as before

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

Preloader#preloadメッセージのpreload_scope引数をoptionalに変更しています。Rails 6.0までと引数を合わせる為。


Fix grammar

rails guideのAutoloading and Reloading Constants (Classic Mode)の修正です。

autoload_paths and eager_load_pathsの項のグラマーを修正しています。


[ci skip]Inherit from correct base class in docs

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

attribute APIのdoc内のexampleコードで、使用するクラスの指定に誤りがあったのを修正しています。


Add validate numericality in range

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

numericality validatorでRangeを指定出来るよう修正しています。

validates_numericality_of :approved, in: 1..3

Revert "actionpack: Improve performance by allowing routes with custom regexes in the FSM."

routingのFSMで、custom regexepを指定してのroutingを行えるよう修正した、actionpack: Improve performance by allowing routes with custom regexes in the FSM.をRevertしています。

constaintsにSymbolを使用した場合に動作しなくなる、というリグレッションが発生してしまった為。

リグレッションを解決し、後ほど再度コミットされています。


actionpack: Improve performance by allowing routes with custom regexes in the FSM.

Action Packの修正です。

routingのFSMで、custom regexepを指定してのroutingを行えるよう修正した対応を再度コミットしています。


Add underscore in front of internal method

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

internal method(find_record)のメソッド名の先頭に_`を追加しています。ユーザが同名のメソッドを定義していた場合に、コンフリクトを避ける為。


Handle STI models for has_many dependent: :destroy_async

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

STI modelsでhas_manyに:destroy_asyncを指定していた場合に、親レコード削除時に子のレコードが全て削除がされないバグがあったのを修正しています。


Remove leading whitespace from the XML under test

activesupport/test/xml_mini/xml_mini_engine_test.rbの修正です。

XMLのテストで、テスト対象のXMLから先頭の空白を削除するよう修正しています。

XMLのdoctypeの前に空白があるせいで、本来テストしたい内容とは違う問題でエラーになってしまう為。


Update minitest to comply with Ruby trunk

Gemfile.lockの修正です。

minitestのバージョンを最新のバージョンに更新しています。


Fix through association with through scope which has joins

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

through association + through scopeでjoinが使わている場合に、scopeの組み立てが正しく行われないバグがあったのを修正しています。