なるようになるブログ

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

rails commit log流し読み(2018/03/14)

2018/03/14分のコミットです。

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

actionmailer/CHANGELOG.md


Merge pull request #32222 from bogdanvlviv/update-ruby_on_rails_5_2_release_notes

rails guideのRuby on Rails 5.2 Release Notesの修正です。

Major Featuresの各項目に詳細な説明を追加、及び、各コンポーネントの項に変更内容を記載しています。


Merge pull request #32153 from bogdanvlviv/rails-routes-32130

actionpack/lib/action_dispatch/routing.rbactionpack/lib/action_dispatch/routing/inspector.rbの修正です。

rails routesgrepオプションを指定、かつ、routesが見つからなかった場合のエラーメッセージがNo routes were found for this controller.になっていたのを、No routes were found for this grep pattern.に修正しています。


Merge pull request #32231 from gmcgibbon/perform_email_jobs_in_assert_emails

actionmailer/lib/action_mailer/test_helper.rbの修正です。

assert_emailsメソッド内でenqueueされたmail jobを実行するようにしています。

元々は呼び出す側でperform_enqueud_jobsメソッドを実行しないとenqueueされたメールについてはassert_emailsで確認出来なかったのですが、この対応によりそれが不要になります。

# before
assert_emails(1) do
  perform_enqueud_jobs(only: ActionMailer::DeliveryJob) do
    SomeMailer.send_mail.deliver_later
  end
end


# after
assert_emails(1) { SomeMailer.send_mail.deliver_later }

Remove changelog header for unreleased version

CHANGELOGからまだリリースされていないバージョンのヘッダー(Rails 6.0.0.alpha (Unreleased))を削除しています。


Extract details to methods to clarify command.

railties/lib/rails/commands/routes/routes_command.rbの修正です。

inspector及びformatterの取得処理をメソッドに切り出しています。


Rely on Rails::Command's help output.

actionpack/lib/action_dispatch/routing/inspector.rbrailties/lib/rails/commands/routes/routes_command.rbの修正です。

rails routesのhelpを表示するのに独自にメソッドを定義していたのを、thorが提供しているhelp表示の為の仕組みを使用するよう修正しています。


Fix routing inspector tests broken in https://github.com/rails/rails/commit/6629d51a2756fadf961bb09df20579cacfef2c8e

actionpack/test/dispatch/routing/inspector_test.rbの修正です。

先のhelp表示対応の影響でテストが壊れてしまっていたのを修正しています。

合わせて、テスト内でしかhelperメソッドの可視性をprivateに変更、メソッドの引数をキーワード引数に変更等を行っています。


Remove entry that was backported to Rails 5.1.3. [ci skip]

rails guideのRuby on Rails 5.2 Release Notesの修正です。

railtiesの項から5.1系にバックポート済みのエントリーを削除しています。


Pass the skip_pipeline option in image_submit_tag

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

image_submit_tagメソッドにskip_pipelineオプションを指定しても無視されてしまうバグがあったのを修正しています。


Update "Upgrading from Rails 5.1 to Rails 5.2" [ci skip]

rails guideのUpgrading Ruby on Rails、及び、Configuring Rails Applicationsの修正です。

Upgrading from Rails 5.1 to Rails 5.2の項に、expiry及びencrypted cookieで、有効期限がcookieの値に埋め込まれた対応についての説明を追加しています。

rails commit log流し読み(2018/03/13)

2018/03/13分のコミットです。

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


Remove path config option from Azure service

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

Azure Storage Serviceのconfigからpathオプションを削除しています。

Azure Storage Serviceではpathオプションにblob storageのエンドポイントを指定します。が、Active Storageとしては、エンドポイントはblobのclientから取得するようになっています。

そのため、pathを明示的に指定する必要が無い、かつ、pathにエンドポイントを直接するには今は引数が足りない、という問題もあった為、pathは削除したとの事です。


Update ASt test services config

.travis.ymlactivestorage/test/service/configurations.yml.encの修正です。

先のpathオプションを削除した対応で、CIで使うようのconfigファイルの更新が漏れていたのを修正しています。


Remove path option from AzureStorage config

railties/lib/rails/generators/rails/app/templates/config/storage.yml.ttの修正です。

デフォルトで生成されるstorage.ymlからpathオプションを削除いています。


Redis cache store: fix constructing with a Redis instance

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

RedisCacheStore.build_redisメソッドでRedis instanceを生成する際に、callメソッドを呼び出すかどうかのチェックにrespond_to?(:call)を使用していたのを、is_a?(Proc)でチェックするよう修正しています。

-          if redis.respond_to?(:call)
+          if redis.is_a?(Proc)
             redis.call

引数にProcが渡された場合に実行するようのチェックだったのですが、Redisオブジェクトにもcallメソッドが定義されており、Redisオブジェクトが渡された場合にも誤ってcallメソッドが実行されてしまっていた為、左記を避ける為、Procがどうかをチェックするようにしています。


Fix Azure signed URL generation with newer client lib

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

Active Storageでsigned URLを生成する際に、独自の生成ロジックでURLを生成したいてたの、client libraryが提供しているURL生成用のメソッドを使用するよう修正しています。


Restore full Travis config

.travis.ymlの修正です。

先のコミットの際に何故か壮大にTravisの設定ファイルを壊してしまっていたのを、元に戻しています。

rails commit log流し読み(2018/03/12)

2018/03/12分のコミットです。

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


Merge pull request #32160 from bogdanvlviv/improve-rails-routes-expanded

actionpack/lib/action_dispatch/routing/inspector.rbの修正です。

routes --expandedでヘッダー部を表示する際に、値を固定で出していた(widthが73を想定した値)のを、IO.console_sizeで端末のサイズを取得し、サイズに合わせた値を表示するよう修正しています。


Fix CHANGELOGs [ci skip]

actionview/CHANGELOG.mdactivejob/CHANGELOG.mdactivesupport/CHANGELOG.mdの修正です。

各エントリーの終端にドットを追加、不要なスペースの削除等を行っています。


Fix note marks [ci skip]

rails guideの修正です。

各guideで注記を記載していた箇所のNoteNOTEに修正しています。すべて大文字じゃないと正しく注記として表示されない為。


Add section to routing guide about config/routes.rb [ci skip]

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

config/routes.rbファイル自体についての説明を記載したConfiguring the Rails Routerセクションを追加しています。


[ci skip] Add missing do.

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

先ほど追加されたConfiguring the Rails Routerセクション内のexampleコードで、doが不足していたのを修正しています。

rails commit log流し読み(2018/03/11)

2018/03/11分のコミットです。

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


Remove unnecessary Hash.method_defined?(:dig) checking

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

Parameters#digメソッドを定義する際にHashdigが定義されているかどうかをチェックしていたのを削除しています。masterは2.4.1以上のみをサポートしており、Hash#digは必ず定義されている為。

rails commit log流し読み(2018/03/10)

2018/03/10分のコミットです。

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


Merge pull request #32215 from M-Sayed/master

actionpack/lib/action_dispatch/routing/polymorphic_routes.rbのdocの修正です。

polymorphic_pathメソッドのdocでpolymorphic_url及びrouting_type: :pathpolymorphic_pathメソッドが使われている旨説明が記載されていたのですが、今はもう使われていない為、該当の説明を削除しています。


update psych gem to 3.2 stable release

GemfileGemfile.lockの修正です。

psych gemを3系に更新しています。


Do not show unnecessary message during server startup

railties/lib/rails/commands/server/server_command.rbの修正です。

rails server起動中に、停止時に表示するメッセージが表示されてしまっていったのを、表示されないよう修正しています。

rails commit log流し読み(2018/03/09)

2018/03/09分のコミットです。

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


Only apply monkey-patch if detected to be required

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

必ずunescapeメソッドを再定義していたのを、必要な時だけメソッドの再定義を行うようにしています。

unscapeunicode / escaped文字を混在した値を指定した場合にエラーになってしまっていたのを修正した対応が、Ruby本体にもインポートされた為。

参考:fix error if the input is mixed Unicode and percent-escapes


Fixes a typo and updates active_job_basics.md

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

Callbacksにあるexampleコードでclass名の取得方法に誤りがあったのを修正しています。


Add delegate :pick, to: :all

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

pluck同様に、pickメソッドも:alldelegateするよう修正しています。


Update some i18n references in guides (#32182)

rails guideのRails Internationalization (I18n) APIの修正です。

もう存在しないGlobalize::Backend::Staticの削除、Translating Model Contentの項を追加しI18n用のgemの説明を追加、各項の言い回しの修正等を行っています。

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

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

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

activesupport/CHANGELOG.md


Merge pull request #32183 from kivikakk/uri-ext-fix

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

URI.unscapeunicode / escaped文字を混在した値を指定した場合に、エラーになってしまっていたのを修正しています。

# before
URI.unescape("\xe3\x83\x90")          # => "バ"
URI.unescape("%E3%83%90")             # => "バ"
URI.unescape("\xe3\x83\x90%E3%83%90") # => Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT


# after
URI.unescape("\xe3\x83\x90")          # => "バ"
URI.unescape("%E3%83%90")             # => "バ"
URI.unescape("\xe3\x83\x90%E3%83%90") # => "ババ"

Merge pull request #32175 from bogdanvlviv/express-route_for-as-public-api

actionpack/lib/action_dispatch/routing/url_for.rbのdocの修正です。

ActionDispatch::Routing::UrlFor#route_forメソッドをpublic APIにしています。

元々特に意図があってprivateにしていた訳ではない、かつ、directメソッドと合わせて使うと便利そう、という事でpublic APIになりました。

例。

resources :buckets

direct :recordable do |recording|
  route_for(:bucket, recording.bucket)
end

direct :threadable do |threadable|
  route_for(:recordable, threadable.parent)
end

threadable_path(threadable) # => "/buckets/1"
threadable_url(threadable)  # => "http://example.com/buckets/1"

Add example of maintaining context with route_for

ActionDispatch::Routing::UrlFor#route_forメソッドのdocにhelperメソッドを使用した場合の説明を追加しています。


Quote string return values in doc examples [ci skip]

actionpack/lib/action_dispatch/routing/url_for.rbのdocの修正です。

先のdocの修正で追加した実行結果の例をダブルクォートで囲むよう修正しています。


Allow using inline style and script in the internal controllers

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

Rails内部で保持しているview(welcomeページや、mailer preview等)ではinline scriptを使えるよう、controllerでscript_src :unsafe_inline及びstyle_src :unsafe_inlineを指定するよう修正しています。

上記viewではinline style及びinline scriptを使用している為、アプリの設定に関わらずviewが正しく表示されるようにする為に上記指定を行うようにしています。


Add the ability to disable the global CSP in a controller

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

controller単位でCSPを無効に出来るよう修正しています。

class LegacyPagesController < ApplicationController
  content_security_policy false, only: :index
end

無効にしたい場合、上記のように最初の引数にfalseを指定すればOKです。


Always yield a CSP policy instance

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

CSPのインスタンスが生成されていない場合、強制的にインスタンスを生成するよう修正しています。

リクエストが実行される際にインスタンスが生成されているかどうかは、アプリのグローバル設定でCSPが有効かされているかどうかに依存しているのですが、それだとcontroller単位でCSPを変更したい場合に困る為、インスタンスが存在しない場合はリクエストを処理する際に生成するようにしています。