なるようになるブログ

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

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

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

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

actionview/CHANGELOG.md

activesupport/CHANGELOG.md


Enrich the introduction for debug gem (#43621)

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

Debugging with the debug gemの項に、debugging sessionの起動方法や、session内で使えるコマンドについての説明等を追加しています。


docs: true/false typo

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

Merging of scopesの項にあるexampleコードが、実際の結果と異なる値になっていたのを修正しています。


Fix flaky test in HasManyThroughDisableJoinsAssociationsTest

activerecord/test/models/author.rbの修正です。

テストで使用するassociationにorderの指定を追加しています。。orderを指定しないと結果の順番が不定になる為。


Enable Lint/DuplicateMethods rubocop rule

Lint/DuplicateMethods copを追加、及び、各ファイルにcopを適応しています。


Merge pull request #43650 from gmcgibbon/fixes_for_38957

actiontext/app/javascript/actiontext/attachment_upload.jsの修正です。

Action Textで行っているdirect upload処理について、Pass service_name param to DirectUploadsControllerの変更内容に合わせて引数の修正を行っています。


Require MFA to release rails

gemspecの修正です。

MFAの設定がされてないとrubygemsにgemをリリース出来ないよう、gemのmetadataにrubygems_mfa_requiredの指定を追加しています。


Install github cli in dev container

.devcontainer/Dockerfile.devcontainer/library-scripts/github-debian.shの修正です。

dev containerにGitHub CLIをインストールするよう修正しています。


Fix the Dockerfile

.devcontainer/Dockerfileの修正です。

先のコミットで追加したgithub-debian.shのパスが誤っていたのを修正しています。


Fix gemspec

gemspecの修正です。

rubygems_mfa_requiredの値の指定方法が誤っていたのを修正しています。


Merge PR #42755

actionview/lib/action_view/base.rbactionview/lib/action_view/helpers/active_model_helper.rbの修正です。

Base.field_error_procActionView::Baseインスタンスのcontext内で実行するよう修正しています。これにより、下記のように、field_error_procに指定するblockにActionView::Baseに定義されているメソッドが使えるようになっています。

config.action_view.field_error_proc = proc { |html| content_tag(:div, html, class: "field_with_errors") }

Merge PR #43409

Action Viewの修正です。

FormBuilder#field_nameと引数に指定された値からname attributeの値を生成するfield_nameメソッドを追加しています。

form_for @post do |f|
  f.text_field :title, name: f.field_name(:title, :subtitle)
  # => <input type="text" name="post[title][subtitle]">
end
form_for @post do |f|
  f.field_tag :tag, name: f.field_name(:tag, multiple: true)
  # => <input type="text" name="post[tag][]">
end

Support name Symbol to FormBuilder#button

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

FormBuilder#buttonの第一引数にname attributeに使用する為の値をSymbolを指定出来るよう修正しています。

form.button(:draft, value: true)
# => <button name="post[draft]" value="true" type="submit">Create post</button>
form.button(:draft, value: true) do
  content_tag(:strong, "Save as draft")
end
# =>  <button name="post[draft]" value="true" type="submit">
#       <strong>Save as draft</strong>
#     </button>

Support Object#with_options without a block

activesupport/lib/active_support/core_ext/object/with_options.rbactivesupport/lib/active_support/option_merger.rbの修正です。

Object#with_optionsの引数にblockを指定しなかった場合に、ActiveSupport::OptionMergerインスタンスを戻り値とするよう修正しています。decorateしたobjectをベースにview helperを実行出来るようにする為。

module MyStyledHelpers
  def styled
    with_options style: "color: red;"
  end
end

styled.link_to "I'm red", "/"
#=> <a href="/" style="color: red;">I'm red</a>

styled.button_tag "I'm red too!"
#=> <button style="color: red;">I'm red too!</button>

Fix typos in the script

.devcontainer/library-scripts/github-debian.shの修正です。

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


Invert conditional

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

with_optionsメソッド内のblock引数がnilかどうかのチェックを反転しています。不要なメソッド呼び出しを避けれるようにする為。


Fix typo in the documentation

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

doc内のグラマーの修正を行っています。


Remove warnings on AS/test/cache/stores

activesupport/test/cache/stores/mem_cache_store_test.rbactivesupport/test/cache/stores/redis_cache_store_test.rbの修正です。

テスト実行時にRubyのwarning(instance variable xxx not initialized)が出ていたのを修正しています。


Merge PR #43413

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

button_toメソッドで生成するformで、引数のmodelの状態に合わせて使用するHTTP verbを変更する(保存済みのレコードの場合patchを使用する)よう修正しています。

button_to(Workshop.find(1)){ "Update" }
#=> <form method="post" action="/workshops/1" class="button_to">
#=>   <input type="hidden" name="_method" value="patch" autocomplete="off" />
#=>   <button type="submit">Update</button>
#=> </form>

button_to([ Workshop.find(1), Session.find(1) ]) { "Update" }
#=> <form method="post" action="/workshops/1/sessions/1" class="button_to">
#=>   <input type="hidden" name="_method" value="patch" autocomplete="off" />
#=>   <button type="submit">Update</button>
#=> </form>

Merge PR #43416

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

fieldsメソッドのmodel引数にnestしたmodel(e.g. [@nested, @model])を指定出来るよう修正しています。form_withmodel引数と挙動を合わせる為。


Remove code duplication by extracting the _object_for_form_builder private method

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

値がArrayだった場合に値のlastを取得する、という処理が複数箇所にあったのでメソッドに切り出しています。


Fix typo in the documentation

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

コンポーネント名について説明している箇所のActiveModelActive Modelに修正しています。


Link to listing existing routes

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

Path and URL Helpersの項に、route helperを検索する方法について説明しているListing Existing Routesへのリンクを追加しています。