なるようになるブログ

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

rails commit log流し読み(2023/03/08)

2023/03/08分のコミットです。

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


Add missing openssl require to activerecord/encryption/config.rb file

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

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


Merge pull request #47590 from zzak/rdoc-task-output-dir

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

created.ridを参照する先にディレクトリがハードコーディングされていたのを、変数で設定済みのディレクトリを参照するよう修正しています。


Lockdown rails app in production for security (#47594)

railties/lib/rails/generators/rails/app/templates/Dockerfile.ttの修正です。

gemsやアプリケーション自体のコード等、構築したら更新しないファイルはroot権限で保持し、logtmpディレクトリなど、書き込みが必要なディレクトリのみをDockerを実行するuserで書き込みが出来るよう修正しています。セキュリティの為。

rails commit log流し読み(2023/03/07)

2023/03/07分のコミットです。

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

railties/CHANGELOG.md


Fix small typo in Object#With rdoc [ci-skip]

activesupport/lib/active_support/core_ext/object/with.rbのdocの修正です。

Object#withメソッドのdoc内のタイポを修正しています。


Edits to the autoloading guide

rails guideのAutoloading and Reloading Constantsの修正です。

各箇所の言い回しやタイポの修正を行っています。


Fixes typo

rails guideのAutoloading and Reloading Constantsの修正です。

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


Merge pull request #47585 from deepakmahakale/patch-1

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

conductor用のcontrollerがAPI docに表示されないよう修正しています。


Merge pull request #47442 from Shopify/add-irb-to-gemfile-template

railties/railties.gemspecの修正です。

railtiesdependencyirbを追加しています。Rubyにbundleされているirbではなく、rubygemsにリリースされている最新のirbが使用されるようにする為。


Merge pull request #46126 from alexandreruban/fix-as-json-action-text-attachables

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

保存していないblobを含むActionText::Attachableインスタンスに対してas_jsonを実行するとエラーになってしまうバグがあったのを修正しています。


Use cached instance of o.index

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

indexを参照する際にcacheされているインスタンスを使用するよう修正しています。


Give documentational consistency to authenticate_with_http_token [ci-skip]

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

authenticate_with_http_tokenメソッドのdoc内のメソッドの戻り値について説明している箇所に、tokenが見つかった場合引数のlogin_procedure blockの結果が戻り値として返される旨説明を修正しています。

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

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

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

railties/CHANGELOG.md


Improve support for custom namespaces

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

autoloadingでディレクトリに対してい独自の名前空間の設定を行えるよう修正しています。例えば、app/services配下にあるclass/moduleをすべてServices namespace配下に定義したい場合、app/services/servicesというディレクトリを作成しその配下にファイルを格納する必要がありましたが、app/services/配下に直接Services namespace配下のファイルを定義できるようになっています。この場合、下記のようなinitializerを作成すれば良いようになっています。

# config/initializers/autoloading.rb

module Services; end
Rails.autoloaders.main.push_dir("#{Rails.root}/app/services", namespace: Services)

Merge pull request #47328 from zzak/horo-canonical-url

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

API docにcanonicalタグを設定するよう修正しています。


Implement Object#with

Active Supportの修正です。

指定されたblockの中でのみattributeの値を変更出来るようにする為のObject#withメソッドを追加しています。

client.timeout # => 5
client.with(timeout: 1) do
  client.timeout # => 1
end
client.timeout # => 5

よくテストで一時的にattributeの値を変更し、後処理でそれを元に戻す、という事をするのですが、#withメソッドを使うことでそれを簡単に記載出来るようになっています。

def test_something_when_enabled
  some_call_that_may_raise
  enabled_was, SomeLibrary.enabled = SomeLibrary.enabled, true
  # test things
ensure
  SomeLibrary.enabled = enabled_was
end

上記のようなテストの場合、Object#withを使用すると下記のように出来ます。

def test_something_when_enabled
  SomeLibrary.with(enabled: true) do
    # test things
  end
end

Merge pull request #47552 from lsylvester/where-include-index

Active Recordの修正です。

index作成時に、PostgreSQLINCLUDEパラメータとWHEREパラメータを一緒に指定すると不正なSQLが生成されてしまいエラーになってしまうバグがあったのを修正しています。


Edits in example code and railties CHANGELOG

rails guideのAutoloading and Reloading Constants、及び、railties/CHANGELOG.mdの修正です。

autoloadingで名前空間を設定する場合のexampleで、引数の指定方法が誤っていたのを修正しています。

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

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

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


dockerfile cosmetics:

railties/lib/rails/generators/rails/app/templates/Dockerfile.ttの修正です。

各処理のコメントのグラマーの修正や不要な空行の削除などを行っています。


use no-install-recommends consistently

railties/lib/rails/generators/rails/app/templates/Dockerfile.ttの修正です。

packageのインストール実行時に--no-install-recommendsオプションを指定するよう修正しています。


Trigger the Dockerfile test on pull_request event as well

.github/workflows/build-and-test-dev-image.yml.github/workflows/lint.ymlの修正です。

DockerfileのテストをPRが作成されたにも実行するよう修正、及び、lintをコードがpushされた際も実行するよう修正しています。


Update Asset Pipeline Guideline reference to Sass gem (#47491)

rails guideのThe Asset Pipelineの修正です。

Sassを使用する場合の説明で、sassc-railsを使用していたのをdartsass-railsを使用するよう修正しています。

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

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

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

actionpack/CHANGELOG.md

activemodel/CHANGELOG.md


add --home and --shell to rails user in Dockerfile (#47533)

railties/lib/rails/generators/rails/app/templates/Dockerfile.ttの修正です。

Dockerfile内でユーザを追加する際にhome、及び、shellの設定を行うよう修正しています。


Fixes #47572

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

ActiveSupport::TimeWithZoneTimedelegateする為のmethod_missingの引数指定に...を使用するよう修正しています。キーワード引数の考慮が漏れており、Timeのメソッドを使用する際にキーワード引数を使用出来るようにすr為。


Revert "Remove deprecated children and parent_of? on ActiveSupport::Notifications::Event"

deprecatedになっていたActiveSupport::Notifications::Event#childrenActiveSupport::Notifications::Event#parent_of?を削除した、Remove deprecated children and parent_of? on ActiveSupport::Notif…をRevertしています。Rails 7.1でdeprecatedになるメソッドで、まだ削除対象ではない為。


Merge pull request #47532 from jkotchoff/rails-info-routes-search-optimisation

Action Pack、railtiesの修正です。

rails/info/routesでの検索にroute name、HTTP Verb、及び、controller#actionを指定出来るよう修正しています。


Merge pull request #47546 from rails/revert-47500-patch-3

DockerfileCOPY --linkをするようにした、Use COPY --link in DockerfileをRevertしています。Red HatのbuildahではCOPY --linkをサポートしていない為。

参考: [RFE] Add support for --link in COPY/ADD


Merge pull request #47551 from zzak/rails-new-dev-docker-ci

CIでrails newで生成するDockerfileが正しく動作する事をテストするよう修正しています。


Merge pull request #47409 from hahmed/ha/move-test-server-to-fix-faiing-test

actioncable/test/stubs/test_server.rbの修正です。

Ruby 3.0より非推奨になったostructを使用している箇所があったのを、使用しないよう修正しています。


Merge pull request #47569 from p8/activemodel/add-model-name-to-missing-attribute-error

Active Record、Active Modelの修正です。

ActiveModel::MissingAttributeErrorのエラーメッセージに、class名を含むよう修正しています。

User.first.pets.select(:id).first.user_id
# => ActiveModel::MissingAttributeError: missing attribute 'user_id' for Pet

Merge PR #45463

Active Modelの修正です。

エラーメッセージ内のAPOSTROPHE (U+0027)をRIGHT SINGLE QUOTATION MARK(U+2019)を使用するよう修正しています。例えば、can't be blankcan’t be blankとなっています。Unicode Standardでは、Punctuation Apostropheを表現するのに、デジタルおよび印刷デザインでは通常RIGHT SINGLE QUOTATION MARKを使用する事を推奨している為、との事です。

参考: Unicode Standard Section 6.2


Merge pull request #47483 from palkan/fix/channel-test-case-test-server

Action Cableの修正です。

ActionCable::Channel::TestCaseを使用した際にNameErrorがraiseしてしまうバグがあったのを修正しています。


:nail_care: AM CHANGELOG fixed-width re: #45463, #47569

activemodel/CHANGELOG.mdの修正です。

各エントリーのフォーマットの修正を行っています。

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

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

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md

actionview/CHANGELOG.md

activestorage/CHANGELOG.md


Remove deprecated behavior on Request#content_type

Action Pack、railtiesの修正です。

deprecatedになっていた古いRequset#content_typeの挙動、及び、config.action_dispatch.return_only_request_media_type_on_content_typeを削除しています。


Remove deprecated ability to assign a single value to config.action_dispatch.trusted_proxies

actionpack/lib/action_dispatch/middleware/remote_ip.rbの修正です。

deprecatedになっていたconfig.action_dispatch.trusted_proxiesにsingle valueを設定できるようにする対応を削除しています。


Remove deprecated poltergeist and webkit (capybara-webkit) driver registration for system testing

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

deprecatedになっていたsystem testingのpoltergeistwebkitのサポートを削除しています。


Remove deprecated ActiveRecord::Base config accessors

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

deprecatedになっていたActiveRecord::Baseのconfig accessorsを削除しています。


Remove deprecated config.active_record.partial_writes

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

deprecatedになっていたconfig.active_record.parを削除しています。


Remove deprecated override of Enumerable#sum

Active Record、Active Supportの修正です。

deprecatedになっていたEnumerable#sumのoverride処理を削除しています。


Remove deprecated Tasks::DatabaseTasks.schema_file_type

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

deprecatedになっていたTasks::DatabaseTasks.schema_file_typeを削除しています。


Remove deprecated ActiveSupport::PerThreadRegistry

Active Supportの修正です。

deprecatedになっていたActiveSupport::PerThreadRegistryを削除しています。


Remove deprecated option to passing a format to #to_s

Active Support、railtiesの修正です。

deprecatedになっていた各クラスの#to_sにformatを渡した場合の挙動を削除しています。合わせて、この挙動を変更する為のconfig.active_support.disable_to_s_conversionをdeprecateにしています。


Remove deprecated override of ActiveSupport::TimeWithZone.name

Active Support、railtiesの修正です。

deprecatedになっていたActiveSupport::TimeWithZone.nameのoverride処理を削除しています。合わせて、この挙動を変更する為のconfig.active_support.remove_deprecated_time_with_zone_nameをdeprecateにしています。


Remove deprecated active_support/core_ext/uri file

deprecatedになっていたactive_support/core_ext/uri fileを削除しています。


Remove deprecated active_support/core_ext/range/include_time_with_zone file

deprecatedになっていたactive_support/core_ext/range/include_time_with_zone fileを削除しています。


Remove implicit conversion of objects into String by ActiveSupport::SafeBuffer

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

deprecatedになっていたobjectをActiveSupport::SafeBufferを使用してStringに変換する処理を削除しています。


Remove deprecated children and parent_of? on ActiveSupport::Notifications::Event

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

deprecatedになっていたActiveSupport::Notifications::Event#childrenActiveSupport::Notifications::Event#parent_of?を削除しています。


Remove deprecated support to generate incorrect RFC 4122 UUIDs

Active Support、railtiesの修正です。

deprecatedになっていた不正なRFC 4122 UUIDs を作成する為の挙動を削除しています。合わせて、この挙動を変更する為のconfig.active_support.use_rfc4122_namespaced_uuidsをdeprecateにしています。


Remove deprecated constant ActionView::Path

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

deprecatedになっていたActionView::Pathを削除しています。


Remove deprecated support to instance variables as locals to partials

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

deprecatedになっていたpartialsにインスタンス変数をlocalsとして渡す挙動を削除しています。


Remove deprecated invalid default content types in Active Storage configurations

Active Storageの修正です。

deprecatedになっていたActive Storageのcontent typeに不正な値を指定できるようにする為の挙動を削除しています。


Remove deprecated ActiveStorage::Current#host and ActiveStorage::Current#host= methods

activestorage/app/models/active_storage/current.rbの修正です。

deprecatedになっていたActiveStorage::Current#host及びActiveStorage::Current#host=を削除しています。


Remove deprecated behavior when assigning to a collection of attachments

Active Storage、Active Supportの修正です。

deprecatedになっていたattachmentのcollectionにattachmentを追加する為の挙動を削除しています。


Remove deprecated purge and purge_later methods from the attachments association

activestorage/lib/active_storage/attached/model.rbの修正です。

deprecatedになっていたattachment associationのpurgepurge_laterメソッドを削除しています。


Merge pull request #47556 from codez/failsafe_delayed_job_name

activejob/lib/active_job/queue_adapters/delayed_job_adapter.rbの修正です。

jobのjob_classに不正な値(削除されてしまったりしてすでに存在しないクラス)が指定された場合に、ログの出力自体がエラーになってしまっていたのを修正しています。


Update Rails welcome image in guides

guides/assets/images/getting_started/rails_welcome.pngの修正です。

guideで表示されるwelcomeページのimageを最新の内容に更新しています。


Fix markdown format and typo

activestorage/test/models/variant_test.rbactivesupport/CHANGELOG.mdの修正です。

テスト名のタイポ、及び、CHANGELOG内のタイポを修正しています。


Clarify AS::Representations::RedirectController processes files [skip ci]

rails guideのActive Storage Overviewの修正です。

Lazy vs Immediate Loadingの項にある、ActiveStorage::Representations::RedirectControllerが行うファイルアップロード時の挙動について詳細な説明を追加しています。


Merge pull request #47563 from p8/activerecord/improve-attributes-methods-test

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

read_attributeに存在しないattributeを指定した場合の挙動のassertを追加しています。


Merge pull request #45642 from kbrock/quoted_columns

activerecord/lib/arel/nodes/homogeneous_in.rbactiverecord/lib/arel/visitors/to_sql.rbの修正です。

HomogeneousInで手動でSQLを生成していたのを、他の処理と同様にToSql#Attributedelegateするよう修正しています。


Merge pull request #47565 from Shopify/fix-nullifying-association-with-composite-query-constraints

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

composite query constraintsを使用しているhas_many associationに対するnullifが行えるよう修正しています。


Merge pull request #47566 from Shopify/do-not-use-query-constraints-if-association-doesnt-explicitly-specifies-it

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

compute_primary_keyメソッドでassociationで明示的にquery_constraintsの指定がある場合のみquery_constraintsを使用するよう修正しています。

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

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

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


Merge pull request #47534 from Shopify/fix-polymorphic-has-many-through-assignments

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

polymorphicを使用しているhas many through associationに対してrecordとsource_typeを一緒にassignした場合に、正しくassociationの設定が行われないバグがあったのを修正しています。


Merge pull request #47541 from Shopify/has-many-through-assign-with-query-constraints

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

composite foreign keyを使用しているhas_many through associationのassignを行えるよう修正しています。


Fix has_many through association assginments with custom scope and custom joining association name

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

has_many through association + scopeを変更 + joinするassociation nameを変更している場合に、associationへのassing処理が正しく行えないバグがあったのを修正しています。


Merge pull request #47259 from skipkayhil/hm-regenerate-dummies

Active StorageやAction Textで使用しているテスト用のdummy applicationを最新のRailsで作り直しています。