なるようになるブログ

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

rails commit log流し読み(2017/05/30)

2017/05/30分のコミットです。

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

activesupport/CHANGELOG.md


Add option for class_attribute default (#29270)

Active Supportの修正です。

class_attributeメソッドにデフォルト値を設定出来るよう修正しています。

# before
:settings
self.settings = {}

# after
class_attribute :settings, default: {}

Merge pull request #29248 from yawboakye/rename-should-rename-table-pkey

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

PostgreSQL adapterでrename_tableメソッドを実行した際に、table名に合わせてprimary key名も変更するよう修正しています。


Pass params FILE and LINE + 1 if class_eval with <<

ctionpack/lib/action_dispatch/journey/route.rbの修正です。

Journey::Routeクラスでverb用のメソッドをclass_evalで生成する際に、引数に__FILE____LINE__を渡すよう修正しています。


Merge pull request #29151 from onemanstartup/jquery_slim_fix

actionview/app/assets/javascripts/rails-ujs/start.coffeeの修正です。

jQueyが定義されているかどうかチェックする際に、jQuery.ajaxが定義されているかどうかもチェックするよう修正しています。

jQuery slim versionではjQuery.ajaxは使用出来ない為、とのことです。へー。

参考:jQuery 3.2.1 Is Now Available, With Some Hotfixes | Official jQuery Blog


Remove extra block for assert_changes [ci skip]

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

Rails Specific Assertionsの項、assert_changesメソッドの引数ついて説明している箇所にblockパラメータが2つあったのを削除しています。


Add missing “not” in the doc for assert_no_changes [ci skip]

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

assert_no_changesメソッドのdocで説明に誤りがあったのを修正しています。


Bump RuboCop to 0.49.1

Gemfile.lockの修正です。

RuboCopのバージョンを0.49.1に更新しています。


Grammar fixes

actionview/app/assets/javascripts/README.mdのdocの修正です。

各項のグラマーの修正を行っています。


Add backticks

activesupport/CHANGELOG.mdの修正です。

ActiveSupport::CurrentAttributesをバッククオートで囲むよう修正しています。


Fix indentation + remove blank line

activesupport/CHANGELOG.mdの修正です。

不要な空行の削除、インデントの調整を行っています。


Do not use UTF8 in test SecretsCommandTest#test_edit_secrets

railties/lib/rails/secrets.rbrailties/test/commands/secrets_test.rbの修正です。

テスト内のassertionでASCIIに無い文字を使用している箇所があったのを削除しています。LC_ALL=Cの環境でエラーになってしまうのを避ける為、との事です。


Grammar fixes

rails guideのActive Record Query Interfaceの修正です。

OR Conditionsの項のグラマーの修正を行っています。


Fix UUID column with null: true and default: nil

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

UUID columnにnull: truedefault: nilを一緒に指定した場合に、エラー(undefined methodinclude?‘ for nil:NilClass)になってしまうバグがあったのを修正しています。


Merge pull request #29273 from kamipo/deserialize_raw_value_from_database_for_json

Active Recordの修正です。

AbstractJson#changed_in_place?でDBから取得した値のdeserialize処理を行うよう修正しています。

JSON型はスペースや、keyの順番等データは同じでも表現が変わってしまう場合があり、そういう問題が発生しないようにする為に、変更があったかどうかのチェックの際に deserialize処理を行うようにしたようです。


Merge pull request #29098 from kamipo/fix_association_with_extension_issues

Active Recordの修正です。

extension処理の修正として、default_scopeに対してextendingした場合にextendingしたmoduleが呼ばれないバグがあったのを修正、既存のメソッドのカスタマイズにするのにmethod_missingを使用出来なかったのを修正、extendの影響範囲を一つのassoctionに閉じるよう修正、等を行っているようです。多分。


Add an extra test showing why collections are cached

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

proxy objectをstubする事が出来ることを確認するテストを追加しています。


Don’t expose methods and attrs for internal usage

Active Recordの修正です。

内部でだけ使用しているattributesの可視性をprivateからprotectedに変更しています。

privateにしないのは、privateにしてしまうとRuby 2.2系でwarning(private attribute?)が出てしまう為。


Add next occur and previous occurred day of week API (#26600)

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

次、又は、前の曜日を取得するためのDate#prev_occurringDate#next_occurringメソッドを追加しています。

Date.today
# => Wed, 31 May 2017
Date.today.next_occurring(:monday)
# => Mon, 05 Jun 2017 00:00:00 UTC +00:00
Date.today.next_occurring(:sunday)
# => Sun, 04 Jun 2017 00:00:00 UTC +00:00

Date.today.prev_occurring(:monday)
# => Mon, 29 May 2017 00:00:00 UTC +00:00
Date.today.prev_occurring(:sunday)
# => Sun, 28 May 2017 00:00:00 UTC +00:00

Remove requirement on mathn

Gemfileactionview/test/template/date_helper_test.rbの修正です。

Gemfileからmathnを削除しています。

元々はdistance_of_time_in_wordsメソッドでInteger#/が再定義された場合も正しく動作することを確認する為にmathnをrequireしていました。

ただ、Ruby 2.2.からdeprecateになりRuby 2.5で本体から削除され、実際のアプリケーションでmathnをrequireして使用する事はあまり無いだろう、という事でmathnを削除し、テストでは独自に#/を定義し動作確認を行うようにしています。


Replace therubyracer with mini_racer

デフォルトで使用する v8 のエンジンをtherubyracerからmini_racerに変更しています。

therubyracerはセキュリティ脆弱性が残っている古いバージョンに依存している為。 2013-11-12にリリースされたChrome 31と同じ状態との事です。 https://github.com/cowboyd/therubyracer/blob/master/therubyracer.gemspec#L20

なるほど古い。