なるようになるブログ

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

rails commit log流し読み(2017/08/12)

2017/08/12分のコミットです。

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

railties/CHANGELOG.md


Merge pull request #30186 from yhirano55/fix_generator_example_code

rails guideのCreating and Customizing Rails Generators & Templatesの修正です。

Generator methodsの項、lib及びrakefileメソッドのexampleコードが正しく動作しないコードになっていたのを修正しています。


Refactor app_generator_test (#30192)

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

test_default_frameworks_are_required_when_others_are_removedにActive Storageのチェックを追加、及び、test_generator_for_yarn.gitignoreのチェックを追加しています。


Microsoft Azure –> Microsoft Azure Storage [ci skip]

activestorage/README.mdの修正です。

Microsoft AzureMicrosoft Azure Storageに修正しています。


Evaluate @active_storage_attached_#{name} only once

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

has_one_attachedhas_many_attachedメソッドで@active_storage_attached_#{name}を取得する為のメソッドをdefine_methodを使用して定義したいのを、class_evalを使用して定義するよう修正しています。

元の実装だとメソッドを呼び出す度にdefine_methodが評価されてしまっており無駄だった為、一度だけ評価されるようにする為にclass_evalを使用しるよう修正しています。


Enable browser caching for blobs and variants (#30196)

activestorage/app/controllers/active_storage/blobs_controller.rbactivestorage/app/controllers/active_storage/variants_controller.rbの修正です。

Active Storageのblobsとvariantsでbrowser cachingを有効にするよう修正しています。固定で5分(max-age=300, private)設定されるようになっています。


Add null: false to Active Storage tables

activestorage/db/migrate/20170806125915_create_active_storage_tables.rbの修正です。

Active Storageのtableで必須の項目にnull: falseを指定しています。


Remove unused close_connection in Action Cable tests (#30195)

actioncable/test/connection/multiple_identifiers_test.rbactioncable/test/connection/string_identifier_test.rbの修正です。

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


Specify table.name only when scope.table and table are different (#29058)

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

scope.tabletableの値が違い時だけ、table.nameに値を指定するようにしています。

テーブル名と同じ名前のカラムがテーブルにある場合にエラーになるバグがあったのを避ける為。多分。


Make activestorage treat Rack::Test::UploadedFile just like ActionDispatch::Http::UploadedFile

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

Active StorageのblobにRack::Test::UploadedFileクラスのオブジェクトを指定出来るよう修正しています。テストの際に使用するよう。


Merge pull request #29720 from gaurish/ar_find_error_message_improvement

Active Recordの修正です。

idを複数指定した場合にレコードが見つからなかった場合のエラーメッセージに、見つからなかったid(e.g. Couldn't find all Developers with 'id': (1, -9999) (found 1 results, but was looking for 2). Couldn't find Developer with id -9999.)を表示するよう修正しています。


Remove unnedded Active Storage installation steps

activestorage/README.mdの修正です。

READMEからInstallationの項を削除しています。

Installation項に書かれている内容は自動で行う為、との事。しかしいまはまだこのステップ必要なんですよねえ。後から不要になる想定かなあ。


Merge pull request #30113 from dixpac/remove_unecessary_require_in_test_helper

activestorage/test/test_helper.rbの修正です。

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


Merge pull request #30147 from yhirano55/fix_trailing_blank_lines

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

ファイルの終端から不要なからファイルを削除しています。


Merge pull request #30092 from bogdanvlviv/prevent-generation-extra-empty-lines

railties/lib/rails/generators/rails/plugin/plugin_generator.rbrailties/lib/rails/generators/rails/plugin/templates/Rakefileの修正です。

plugin generatorが生成するRakefileに不要な空行が生成されないよう修正しています。


Merge pull request #30159 from allcentury/dump-temp-file-permissions

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

dumpファイルの移動にFileUtils.mvを使用していたのを、FileUtils.cpを使用するよう修正しています。元のファイルのパーミションを維持出来るようにする為。


Merge pull request #30060 from bdewater/aj-callback-docs

rails guideのActive Job Basicsの修正です。

Callbacksの項に、メソッドを登録する場合のexampleを追加しています。


Merge pull request #30110 from yhirano55/add_git_source

railties/lib/rails/generators/rails/plugin/templates/Gemfileの修正です。

plugin generatorが生成するGemfilegit_source(:github) { |repo| "https://github.com/#{repo}.git" }の定義を追加するよう修正しています。


Merge pull request #30105 from bogdanvlviv/remove-sorted-test_order

railties/test/isolation/abstract_unit.rbの修正です。

ActiveSupport::TestCaseself.test_order = :sortedの指定があったのを削除しています。

isolation testは別プロセスで動く為、test_orderの指定が無くても大丈夫な為。多分大丈夫。


Merge pull request #30116 from yhirano55/skip_unused_components_when_running_rails_command_in_plugin

railties/lib/rails/generators/rails/plugin/templates/bin/rails.ttの修正です。

rails engineを生成する際に、skipオプションを指定したコンポーネントのファイルはロードしないよう修正しています。


Merge pull request #30103 from yahonda/has_one_associations_failures

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

不足していた、:authors associationのload処理を追加しています。


Merge pull request #30114 from yhirano55/remove_empty_line_from_dummy_manifest

railties/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.jsの修正です。

dummy application用のmanifestファイルの先頭に不要な空行があったのを削除しています。


Merge pull request #29559 from kirs/eager-load-controller-actions

actionmailer/lib/action_mailer/railtie.rbactionpack/lib/action_controller/railtie.rbの修正です。

eager_loadにtrueが設定されている場合、各controllerのactionメソッドをサーバ起動時に読む込むよう修正しています。

元々は最初のリクエスト実行時に読みこむようになっていたのですが、それだと最初のリクエストのreponse timeが遅くなってしまう為、それを避ける為、サーバ起動時に読みこむようにしています。


Merge pull request #30126 from chopraanmol1/support_for_has_many_and_has_one_for_where_relation

Active Recordの修正です。

whereメソッドにhas one又はhas many associationが定義されているrelationが指定された場合、primary keyではなくforeign keyを返すよう修正しています。

class Account < ActiveRecord::Base
  has_many :invoices
end

class Invoice < ActiveRecord::Base
  belongs_to :account
end

Account.where(invoices: Invoice.where(paid: true))
# before
SELECT "accounts".* FROM "accounts" WHERE "accounts"."account_id" IN (SELECT "invoices"."id" FROM "invoices" WHERE "invoices"."paid" = 't')

# after
SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" IN (SELECT "invoices"."account_id" FROM "invoices" WHERE "invoices"."paid" = 't')

Merge pull request #30165 from tjschuck/code_formatting_fix

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

submitメソッドのdocのフォーマット、グラマーの修正を行っています。


Merge pull request #30166 from yhirano55/fix_generator_method_environment

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

generator actionに複数行指定した場合にインデントがおかしくなってしまうバグがあったのを修正しています。


Fix outdated comment for Core::ClassMethods#=== [ci skip] (#30146)

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

Core::ClassMethods#===のコメントを修正しています。

-      # Overwrite the default class equality method to provide support for association proxies.
+      # Overwrite the default class equality method to provide support for decorated models.
       def ===(object)

元のコメントはFixed that association proxies would fail === tests like PremiumSubsc…で追加されたのですが、左記のコミットで追加されたテスト(及びAssociationProxyクラス)はSplit AssociationProxy into an Association class (and subclasses) whi…で削除されました。

で、現在は、===メソッドはSplit AssociationProxy into an Association class (and subclasses) whi…で追加されたtest_decorated_polymorphic_whereテストで使われているから、上記のようにコメントを修正したとの事です。