なるようになるブログ

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

rails commit log流し読み(2016/04/09)

2016/04/09分のコミットです。

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

actionmailer/CHANGELOG.md

activerecord/CHANGELOG.md

activesupport/CHANGELOG.md


Clarify description of include_all_helpers config setting's default behavior [ci skip]

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

config.action_controller.include_all_helpersについて説明している箇所に、デフォルトの挙動についての説明を追加しています。


Clarify fixtures examples [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

Fixtures are Active Record objectsの項にあるexampleコードが、実際は動作しないコードになっていたのを、正常に動作するコードに修正しています。


Remove reference to non existing link in the welcome page.

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

Merge pull request #23237 from gsamokovarov/new-welcome-page · rails/rails@f3c1897 でwelcome pageの構成が変更になった事により存在しなくなったリンク(About your application's environment)についての説明を削除しています。


Merge pull request #24457 from jeremy/mailer/dont-deliver-later-after-message-is-loaded

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

message変更後に#deliver_laterメソッドを呼び出した場合に、エラーをraiseするよう修正しています。

irb(main):002:0> message = NotifierMailer.welcome
=> #<ActionMailer::Base::NullMail:0x00556421d59be0>
irb(main):004:0> message.message_id = 1
=> 1
irb(main):005:0> message.deliver_later
RuntimeError: You've accessed the message before asking to deliver it later, so you may have made local changes that would be silently lost if we enqueued a job to deliver it. Why? Only the mailer method *arguments* are passed with the delivery job! Do not access the message in any way if you mean to deliver it later. Workarounds: 1. don't touch the message before calling #deliver_later, 2. only touch the message *within your mailer method*, or 3. use a custom Active Job instead of #deliver_later.

元々、mailerの引数のみがdelivery jobに渡されるようになっており、上記のような処理を行っていた場合、値は無視されていました(jobに指定した値は渡されてなかった)。が、無視されてしまっていると、バグに気づきづらいという問題があった為、明確にエラーをraiseするように修正したとの事です。


Support microsecond datetime precision on MariaDB 5.3+.

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

MariaDBでmicrosecond datetime precisionを使用出来るよう修正しています。

      def supports_datetime_with_precision?
-        version >= '5.6.4'
+        if mariadb?
+          version >= '5.3.0'
+        else
+          version >= '5.6.4'
+        end
       end

MariaDBでは5.3以降でmicrosecond precisionをサポートしていたのですが、上記チェック処理(MySQLでは5.6.3からサポート)になってしまっていました。

また、最新のMariaDBのversionは10.xなのですが、version stringは、コンパチの為に5.5.5-10.1.8-MariaDB-logというような値を返すようになっているらしく、最新のMariaDBでも使用出来ない、という問題があった為、MariaDBMySQLとは別にバージョンチェック処理を行うようにして修正を行っています。

余談ですが、Basecamp 3ではMariaDB を使用しているらしいです(MariaDB documentation by iangilfillan · Pull Request #24454 · rails/rails)


Merge pull request #24165 from y-yagi/generate_application_job_when_not_exist

activejob/lib/rails/generators/job/job_generator.rbの修正です。

jobをgenerateする際に、application_job.rbが存在しない場合、application_job.rbを生成するよう修正しています。

Rails 5からgenratorが生成するjob classはApplicationJobは継承するようになっており、rails newした際にapplication_job.rb(ApplicationJob)を生成するようになっているのですが、Rails 4からアップデートした際にはファイルが存在しない為、ファイルが無い場合は生成するようにしています。


Fix behavior of JSON encoding for Exception

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

Exceptionクラスをjsonに変換した際に、エラーの内容が正しく表示されるよう、Exception#as_jsonメソッドを追加しています。

# before
puts Exception.new("hoge").to_json
# => {}

# after
puts Exception.new("hoge").to_json
# => "hoge"