なるようになるブログ

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

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

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

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


Merge pull request #34812 from bogdanvlviv/action_mailbox-guides-docs

Action Mailbox Basics guideを追加(内容はREADME.mdの中身を移動した形)、Action Mailer Basics guideからメールのreceiveに関する説明を削除、等を行っています。


Merge pull request #34825 from bogdanvlviv/change-migration-version-of-actionmailbox

actionmailbox/db/migrate/20180917164000_create_action_mailbox_tables.rbの修正です。

Action Mailboxが生成するmigrationファイルのバージョンを6.0に更新しています。


Switch to released rb-inotify 0.10.0

Gemfileの修正です。

forkしたrb-inotifyを使用していたのを、rubygemsにリリースされているrb-inotifyを使用するよう修正しています。

Ensure the IO always gets closed, exactly once (redux)の対応が含まれたgemがリリースされた為。

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

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

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


Label Action Mailbox PRs

.github/autolabeler.ymlの修正です。

autolabelerのlabelの一覧にactionmailboxを追加しています。


Remove frozen_string_literal pragma from Action Mailbox templates

actionmailbox/lib/rails/generators/mailbox/templates/application_mailbox.rb.ttactionmailbox/lib/rails/generators/mailbox/templates/mailbox.rb.ttの修正です。

Action Mailboxのtemplatesファイルからfrozen_string_literalの指定を削除しています。他のtemplatesファイルと合わせる為。


Ensure that the app generator skips action mailbox when --skip-active-record is given

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

rails new--skip-active-recordを指定した場合にAction Mailboxのloadがされない事を確認するテストを追加しています。


Require railties for all Action Mailbox dependencies

actionmailbox/lib/action_mailbox/engine.rbの修正です。

rails/engineだけrequireしていたのを、必要な依存(action_controlleractive_jobactive_recordactive_storage)のファイルを全てrequireするよう修正しています。


Do not show suggestion message when not exist suggestion

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

rails server、及び、generatorコマンドで、不正なコマンドを指定した場合に表示するメッセージで、サジェスチョンするコマンドが無い場合はサジェスチョンメッセージを表示しないよう修正しています。


Don't load Action Mailbox when Active Storage is skipped

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

rails new--skip-active-storageを指定した場合にAction Mailboxがロードされないよう修正しています。

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

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

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

activestorage/CHANGELOG.md

actionmailer/CHANGELOG.md


Don’t include an undefined X-CSRF-Token header

activestorage/app/assets/javascripts/activestorage.jsの修正です。

Active Storageのdirect upload処理で、HTMLにcsrf-tokenメタタグが無い場合、X-CSRF-Tokenヘッダーを付与しないよう修正しています。


Enable Lint/ShadowingOuterLocalVariable cop to avoid newly adding the warning

Lint/ShadowingOuterLocalVariable copを追加しています。


Remove redundant assignning to current_env

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

重複して行われていたcurrent_env変数への値の設定を削除しています。


Deprecate passing migrations_paths to connection.assume_migrated_upto_version

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

assume_migrated_upto_versionメソッドのmigrations_paths引数がdeprecateになりました。

Refactor migration to move migrations paths to connection以降、使用されていない為。


Use high level API on migration_context instead of using low level API directly

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

assume_migrated_upto_versionメソッドでmigrationのversionを取得するのに、migration filesを明示的に指定 + parse_migration_filenameメソッドを使用して値を取得していたのを、migrationsメソッドを経由して値を取得するよう修正しています。


Deprecate ActionMailer::Base.receive in favor of Action Mailbox

Action Mailerの修正です。

ActionMailer::Base.receiveメソッドがdeprecateになりました。Action Mailboxが導入されたので、今後はそちらを使ってねとの事です。


Load Action Mailbox when other components are skipped

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

rails/allをrequireしない時にもaction_mailbox/engineがrequireされるよう修正しています。


Don't load Action Mailbox when Active Record is skipped

railties/lib/rails/generators/app_base.rbrailties/lib/rails/generators/rails/app/templates/config/application.rb.ttの修正です。

skip_active_recordオプションが指定された際にaction_mailbox/engineをrequireしないよう修正しています。Action MailboxはActive Recordに依存している為。


Add missing quotes on Mailbox test template

actionmailbox/lib/rails/generators/test_unit/templates/mailbox_test.rb.ttの修正です。

Action Mailboxのgeneratorが生成するテストファイルで、クォートが不足している箇所があったのを修正しています。


Fix broken Mailbox generator test

actionmailbox/test/generators/mailbox_generator_test.rbの修正です。

先のテストファイルの修正で、テストの修正が漏れていたのを対応しています。


Remove mention about receive.action_mailer from the AS instrumentation guide

actionmailer/test/log_subscriber_test.rb、guides/source/active_support_instrumentation.md`の修正です。

Deprecate ActionMailer::Base.receive in favor of Action Mailboxのfollow upとして、テストでActionMailer::Base.receiveを使用した場合にdeprecateメッセージが出る事を確認するよう修正、Active Support Instrumentation guideからreceive.action_mailer hookの削除を行っています。

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

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

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

actionmailbox/CHANGELOG.md


Merge pull request #34786 from georgeclaghorn/actionmailbox

メールの受信処理を行う為のAction MailboxコンポーネントRails本体にインポートしています。

デフォルトでAmazon SES, Mailgun, Mandrill, SendGrid及びPostfixをサポートしています。

サポートしている各サービス毎にcontrollerが用意されており、メールを受信するとそれらcontrollerでActive Storageを使用して元のメールをcloud storageに保存するようになっています。

Action Mailbox用のテーブル(action_mailbox_inbound_emails)があり、そちらではメールのstatusが管理されるようになっています。メールの情報はDBには保存しないようになっており、メールの情報を参照する際は、Active Storageを経由してcloud storageにあるファイルを参照するようになっています。

cloud storageに保存したメールは自動で削除されるようになっており、デフォルトでは30日後に削除されるようになっています。この値はconfigで変更可能。

また、メールを受信後、自動で返信・転送も出来るようになっています。これらは独自のmailboxクラスで処理を定義出来るようになっています。以下転送の例。

# app/mailboxes/forwards_mailbox.rb
class ForwardsMailbox < ApplicationMailbox
  # Callbacks specify prerequisites to processing
  before_processing :require_forward

  def process
    if forwarder.buckets.one?
      record_forward
    else
      stage_forward_and_request_more_details
    end
  end

  private
    def require_forward
      unless message.forward?
        # Use Action Mailers to bounce incoming emails back to sender – this halts processing
        bounce_with Forwards::BounceMailer.missing_forward(
          inbound_email, forwarder: forwarder
        )
      end
    end

    def forwarder
      @forwarder ||= Person.where(email_address: mail.from)
    end

    def record_forward
      forwarder.buckets.first.record \
        Forward.new forwarder: forwarder, subject: message.subject, content: mail.content
    end

    def stage_forward_and_request_more_details
      Forwards::RoutingMailer.choose_project(mail).deliver_now
    end
end

諸々詳細は、README参照。


Test against Ruby 2.6.0

.travis.ymlの修正です。

CIでRuby 2.6.0に対してテストを実行するよう修正しています。


Start an Action Mailbox changelog

actionmailbox/CHANGELOG.mdの修正です。

Action MailboxのCHANGELOG.mdを追加しています。


Generate Action Mailbox's API docs

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

API docでAction Mailboxのdocを生成するよう修正しています。


Nest Action Mailbox classes in the API docs

Action Mailboxの修正です。

classをnestして定義する(e.g. class ActionMailbox::BaseControllermodule ActionMailbox; class BaseControllerに変更)よう修正しています。

コンポーネントでmoduleを切り出しておかないと、API docが期待通りに生成されない為のはず。


Nest ActionMailbox::Base in the API docs (missed in 6c168aa)

actionmailbox/lib/action_mailbox/base.rbの修正です。

先のclassのnest対応で、対応が漏れている箇所があったのを修正しています。


Improve actionmailbox's .gitignore and remove redundant files

Action Mailboxの修正です。

.gitignoreから不要な記載を削除、リポジトリに入れるべきではないログファイルの削除等を行っています。


Fix Ruby warnings in actionmailbox

actionmailbox/app/models/action_mailbox/inbound_email/message_id.rbの修正です。

ActionMailbox::InboundEmail::MessageId#create_and_extract_message_idメソッドRubyのwarningが出ていたのを修正しています。


Reuse AR::Association#find_target method

Active Recordの修正です。

CollectionAssociationSingularAssociationそれぞれで定義していたfind_targetメソッドを親クラスのAssociationに定義し、処理を共通化するよう修正しています。Merge pull request #34538 from bogdan/reuse-find-targetのリトライ。


Only run isolated tests on the latest stable ruby: that's now 2.6

ci/travis.rbの修正です。

isolated testがRuby 2.5、2.6両方で実行されていたのを、最新の安定版のRuby(2.6)でだけ実行されるよう修正しています。isolated testは時間が掛かる為。

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

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

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


Generate doc of methods provided by form builders [ci skip]

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

fomr builderで提供されているview helper method(text_fieldpassword_field等)についてdocを追加しています。

form helperで提供されている同名のメソッドと引数が違っており、form helper側のdocを見てform builderのメソッドを使ってエラーになる、という報告が来た為。

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

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

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


Specify hosts in bug report template.

guides/bug_report_templates/action_controller_master.rbの修正です。

bug report templateでアクセスを許可するhostsにexample.orgを追加しています。

Guard against DNS rebinding attacks by whitelisting hostsで導入されたHost Authorizationは、developmentの場合、デフォルトで0.0.0.0/0::/0、及びlocalhostのアクセスのみ許可するようになっています。

しかし、bug reporte templateで使用しているrack-testは、デフォルトでhostにexample.orgを使用するようになっています。結果、development envでbug report templateを使用しようとすると、Host Authorizationによりリクエストが拒否され、正しく動作確認を行うことができない、という問題があった為、hostを明示的に指定するようにしています。

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

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

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


Add missing require for IPAddr

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

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


Make Rails Facebook-free

actionpack/test/controller/routing_test.rbの修正です。

routingのテスト内でaction名にfacebookを使用していたのをtwitterに修正しています。

BasecampがFacebookを使わないビジネスをしよう、という宣言をしており、それに関連してfacebookというのを使うのをやめよう、という意図らしいです。

参考:Become A Facebook-Free Business – Signal v. Noise