なるようになるブログ

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

rails commit log流し読み(2018/05/02)

2018/05/02分のコミットです。

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

activestorage/CHANGELOG.md


Partly revert #32289 to provide Rails' custom fallback in case

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

suggestメソッドでDidYouMean::SpellCheckerが使用出来るかチェックし、使用出来ない場合はレーベンシュタイン距離で計算したサジェストを出すよう修正しています。

did_you_meanが存在しないケースがある(did_you_meanはbundled gemで、普通にアンインストール出来る)為。


require "active_support/test_case" is not supported since 53e877f7

activerecord/test/cases/arel/helper.rbactiverecord/test/cases/test_case.rbの修正です。

テスト用にactive_support/test_caseをrequireしていたのを、active_supportをrequireするよう修正しています。

test_orderactive_supportに定義されてしまっており、active_supportをrequireしないとtest_orderが参照出来ずエラーになってしまう為。


Fix typo in ActiveRecord test method name

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

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


Make sure that when serialing an just deserialized job arguments are there

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

ActiveJob::Core#serializeメソッドでargumentsをserializeする際に、argumentsがserialize済みかどうかをチェックし、既にserialize済みの場合、そちらの値を使い回すよう修正しています。

一度serializeしたjobを再度serializeした場合に、元のargumentsが取得出来るようにする為。


More exercise test_remove_named_index

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

違う定義のnamed indexを削除しようとするとエラーになることを確認するテストを追加しています。


Merge pull request #32784 from jpawlyn/allow-belongs-to-create-for-new-record

activerecord/lib/active_record/associations/has_one_association.rbactiverecord/lib/active_record/associations/singular_association.rbの修正です。

belong_to associationのobjectをnew record(保存していないrecord)から作成しようとするとエラーになっていたのを、作成出来るよう修正しています。


Remove unnecessary require

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

不要なrubygemsのrequireを削除しています。


Remove unused assert_like from Arel::Test

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

使用していないassert_likeメソッドを削除しています。


Support streaming downloads from Google Cloud Storage

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

Google Cloud Storageでstreaming downloadを使用出来るよう修正しています。

google-cloud-storage gem側でstreaming downloadのサポートが入った為、なのですが、そちらの対応自体georgeclaghornによるものでした。

参考:Facilitate partial file downloads


Use https with weblog URI

weblog.rubyonrails.orgへのリンクをhttpsに修正しています。

GitHub Pagesでカスタムドメインhttpsが使用出来るようになった為。

rails commit log流し読み(2018/05/01)

2018/05/01分のコミットです。

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


Fix test: threads being nil in ensure

`activesupport/test/cache/behaviors/connection_pool_behavior.rb@の修正です。

connection_poolのテストでテストの先頭でthreads変数を初期化するよう修正しています。

元々はテストの処理中に初期化していたのですが、それだと、ActiveSupport::Cache.lookup_storeでエラーになった場合の後処理で問題になる(後処理でthreadsを使用している)為、初期化の箇所を修正しています。


Fix an oxford comma

rails guideのGetting Started with Railsの修正です。

カンマのフォーマットを、oxford comma形式に修正しています。


Document rails new storage folder

rails guideのGetting Started with Railsの修正です。

Creating the Blog Applicationの項に、storageディレクトリについての説明を追加しています。


Reset CONTENT_LENGTH between test requests

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

ActionController::TestRequestクラスでrequest毎にCONTENT_LENGTHをリセットするよう修正しています。

Reset RAW_POST_DATA between test requestsRAW_POST_DATAはリセットするようになっていたのですが、CONTENT_LENGTHはそのままになっていました。

ただ、CONTENT_LENGTHがそのままだと、そのCONTENT_LENGTHを信じて行われる処理で不整合がおきてしまう(実際のbodyのデータのサイズとあわない)為、CONTENT_LENGTHもリセットするよう修正しています。


Add quotes to code in rdoc comment in ActionController [ci skip]

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

ActionController::Baseのdoc内のexampleコードで、Stringを返すコードにダブルクォートを追加しています。


Merge pull request #32771 from yahonda/another_32720

Arelのテストの修正です。

Arel::Testの親クラスをActiveSupport::TestCaseに変更、及び、Arel::SpecActiveSupport::Testing::Assertionsをinclude及び必要なassertionメソッドを定義するようにし、Arelのテストでもrefute_xxではなくassert_not_xxxを使用するよう修正しています。

rails commit log流し読み(2018/04/30)

2018/04/30分のコミットです。

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


Fix url_helper examples in testing guide [ci skip]

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

All of these keyword arguments are optional.の項のexampleコードで、url helperに渡す引数に誤りがあったのを修正しています。


Remove reference to Tokaido

rails guideのGetting Started with Railsの修正です。

Installing Railsの項で、RailsをインストールするのにTokaidoを使用するのを勧めていたのを削除しています。

Tokaidoの開発がもう止まってしまっている為。

rails commit log流し読み(2018/04/29)

2018/04/29分のコミットです。

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


[ci skip] update ActiveStorage documentation

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

File/IO Objectsをattachする場合の説明や、ファイルをダウンロードする方法の説明、及び、他のJSのライブラリと一緒に使用する場合の説明等を追加しています。


Merge pull request #32747 from printercu/improve_t_helper

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

TranslationHelper#translateメソッドでdefaultオプションが指定されていない場合に、不要なオブジェクトを生成しないよう修正しています。


Fix Associations::ClassMethods doc [ci skip]

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

Associations:ClassMethodsのdocに、定義されない#association.nil?メソッドについての例があったのを削除、及び、各メソッド毎にttタグで囲むよう修正しています。


Restore original merging order to enforce if_exists: true

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

2.6 warnings: passing splat keyword arguments as a single Hashの対応で、create_tableforceオプションが指定された場合にif_exists: trueが強制的に指定されなくなってしまった(オプションにif_existsが指定されていたら、そちらが使用されてしまう)のを、元の挙動(必ずif_exists: trueを指定する)に戻しています。


We usually do not use GH#1234 style in the CHANGELOGs [ci skip]

rails guideのContributing to Ruby on Railsの修正です。

Updating the CHANGELOGの項、issueを修正した際のエントリーの書き方の例を修正しています。

-    You can continue after the code example and you can attach issue number. GH#1234
+    You can continue after the code example and you can attach issue number. Fixes #1234.

今は通常GH#xxxという書き方はしていない為。


Swap assertion order for better reporting

railties/test/generators/app_generator_test.rbの修正です。

test_system_tests_directory_generatedtest/systemディレクトリの存在チェックの前にtest/system/.keepの存在チェックをしていたのを、test/systemディレクトリの方を先にチェックするよう修正しています。


Make Railties CI log for Ruby 2.6 accessible again

Gemfileの修正です。

thorのmasterブランチを使用してテストを実行するよう修正しています。ERB.newの引数指定によるdeprecateが表示されるのを避ける為。


Stream blobs from disk in 5 MB chunks

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

DiskService#downloadメソッドでstreaming downloadする際に、一度にファイルを読み込むサイズを64KBだったのを、5MBに修正しています。他のserivceと合わせる為。


Improve the performance of ActiveSupport::Inflector.ordinal

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

ActiveSupport::Inflector.ordinalメソッドで、引数のnumberが1..13の場合に、値を決め打ちで返すよう修正しています。パフォーマンス改善。


Avoid duplicating downloads from Google Cloud Storage in memory

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

GCSService#downloadメソッドで、bodyを取得するのにreadメソッドを使用していたのを、stringメソッド使用するよう修正しています。

不要なオブジェクトの生成を避ける為。

rails commit log流し読み(2018/04/28)

2018/04/28分のコミットです。

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


Adding precision about which letter case to use for controller names (#32740)

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

Connecting URLs to Codeの項、toオプションで指定するコントローラ名はスネークケースで記載する必要がある旨説明を追加しています。


Merge pull request #31956 from fatkodima/has_attached-presence-validation

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

Attached::Oneクラスにblank?メソッドを追加しています。実装はattachment.blank?の結果を返すようになっています。

attachmentsにvalidationを出来るようにする為との事です。

class User < ActiveRecord::Base
  has_one_attached :avatar
  has_many_attached :highlights

  validates :avatar, presence: true
  validates :highlights, presence: true
end

↑のようにpresenceチェックが出来るようになっています。


Merge pull request #32733 from Edouard-chin/ec-setupand-teardown

activesupport/lib/active_support/test_case.rbactivesupport/lib/active_support/testing/setup_and_teardown.rbの修正です。

ActiveSupport::Testing::SetupAndTeardown moduleをincludeActiveSupport::TestCaseに追加していたのを、prependを使うようにし、継承チェインの先頭にはいるよう修正しています。

先頭にいないと、after_teardownでexceptionが発生した場合のエラーのハンドリング(exceptionが発生しても後処理を継続する処理)が期待通りに動作しない為。


Merge pull request #32727 from utilum/assert_dont_expects

Action Cable、Active Recordのテストの修正です。

mock処理にmochaを使用していたのを、rails内部のヘルパーメソッド(assert_calledassert_called_with)を使用するよう修正しています


Merge pull request #30647 from droptheplot/render-partials-string-locals

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

partial rendererのlocalsオプションに渡すHashのkeyにStringを使用出来なかったのを、使用出来るよう修正しています。


[ci skip] Fix typo in testing.md

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

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

rails commit log流し読み(2018/04/27)

2018/04/27分のコミットです。

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

activerecord/CHANGELOG.md


Reduce extra object creations in TaggedLogging

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

TaggedLoggingでtagからStringを生成する際に、tagが一つしか無い場合は不要なオブジェクトを生成しないよう修正しています。


Reduce String allocations when building Action View tags

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

TagBuilder#tag_optionメソッドでString#grubを使っていたのをString#grub!を使うようにして、不要なオブジェクトが生成されないよう修正しています。


Don't try to destoy the given string via method argument

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

先のString#gsub!を使用するにした対応の影響で、tagをescapeしない際にFrozenErrorが発生してしまうようになっていたので、valuedupするようにして対応しています。


Don't dup Strings when jsonifying

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

EscapedString#to_jsonメソッドで、String#grubを使っていたのをString#grub!を使うようにして、不要なオブジェクトが生成されないよう修正しています。


Address Style/StringLiterals offence

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

Stringを生成するのにシングルクォートを使用していたのを、ダブルクォートを使用するよう修正しています。


Add test case that assigning belongs_to on destroyed object raises frozen error

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

destoy済みのobjectをbelongs_to associationに指定した場合のテストを追加しています。


Update 'rails_welcome.png' to reflect a more diverse population (#32735)

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

元々白人(と思われる人)しかいなかったのを、より多様な人種がいる画像に更新しています。

rails_welcome.png

参考:More inclusive imagery


Merge pull request #32617 from tgturner/size-should-use-available-association

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

Associations::CollectionAssociation#size、及び、Associations::CollectionAssociation#empty?メソッドでassociation idsがload済みだった場合、queryを実行せず、そのload済みのidsを使用するよう修正しています。


Ensure that ids_reader respects dirty target whether target is loaded or not

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

ids_readerメソッドで、targetがロード済みかどうかに関わらず、dirty targetを使用するよう修正しています。collection.sizeと挙動を合わせる為。

rails commit log流し読み(2018/04/26)

2018/04/26分のコミットです。

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


Simplify URL generation for partial downloads from GCS

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

GCSService#download_chunkメソッド内のURI生成処理をリファクタリング(fileの生成処理に既存のメソッドを使用、不要な引数の削除)しています。


Move #extract_metadata_from to ActiveStorage's TestHelper

Active Storageのテストの修正です。

各テストクラスで定義していたextract_metadata_fromメソッドをtest_helper.rbに移動しています。


Merge pull request #32725 from nikolai-b/rm_count_math_mixin

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

Arel::Nodes::Countから使用していないMath moduleを削除しています。