なるようになるブログ

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

rails commit log流し読み(2015/12/17)

2015/12/17分のコミットです。

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

actionpack/CHANGELOG.md

activesupport/CHANGELOG.md

railties/CHANGELOG.md

actioncable/CHANGELOG.md


Mention the correct way to halt callback chains

rails guideのA Guide for Upgrading Ruby on Railsの修正です。

Upgrading from Rails 4.2 to Rails 5.0の項、 callback chainsを停止をさせる方法がfalseを返す事からthrow(:abort)に変更になった対応についてのタイトルが紛らわしいタイトルになっていたのを修正しています。

-### Halting callback chains by returning `false`
+### Halting callback chains via `throw(:abort)`

Ensure we install the database backend gems on Windows

Gemfileの修正です。

Windows環境でDB用のgemがインストールされるよう修正しています。

-platforms :ruby do
+platforms :ruby, :mswin, :mswin64 do

platform :rubyLinux or Macのみ対象となるんですねえ。


Add additional platforms for Windows

Gemfileの修正です。

MinGW環境でもDB用のgemがインストールされるよう修正しています。

-platforms :ruby, :mswin, :mswin64 do
+platforms :ruby, :mswin, :mswin64, :mingw, :x64_mingw do

Add redirect_back for safer referrer redirects

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

Refererヘッダーが取得出来ればその値、取得出来ない場合は引数(fallback_location)に指定された値にリダイレクトするActionController::Redirecting::redirect_backメソッドを追加しています。

redirect_back(fallback_location: root_path)

redirect_toメソッド:backオプションを指定した場合も、Refererヘッダーから取得した値にリダイレクト出来るようになっていたのですが、redirect_to :backの場合、Refererヘッダーが取得出来ない場合はRedirectBackErrorをraiseするようになっていました。

Refererヘッダーが取得出来ないケースは割と考えられる為、エラーをraiseするより、任意の場所にリダイレクト出来た方が便利だろう、という事で追加されたようです。


Deprecate redirect_to :back

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

先の#redirect_backの対応に伴い、redirect_to:backオプションを指定するのがdeprecateになりました。今後は、#redirect_backの方を使ってね、との事です。


Require a version of bcrypt that works on Windows when needed

Gemfileの修正です。

Windowsの場合、3.0系のbcryptを使用するよう修正しています。 Windowsではbcrypt 3.1系は今エラーになってしまう為との事です。参考:Ruby 2.2.2 on Windows - LoadError: cannot load such file -- bcrypt_ext · Issue #128 · codahale/bcrypt-ruby


Use Module.prepend instead of alias_method for Range#to_s

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

Range#to_sメソッドを実装するのに#alias_methodを使用していたのを、Module.prependを使用するよう修正しています。


Don't leak Object constants in core_ext/module/qualified_const

Module#qualified_const_xxxメソッド(#qualified_const_defined?#qualified_const_get#qualified_const_set)がdeprecateになりました。

今後は、Ruby標準のメソッド(#const_defined?#const_get#const_set)を使うように、との事です。


Avoid conditionals in the Gemfile

Gemfileの修正です。

Gemfilewindows環境のチェックをするのにBundler::WINDOWSを使用していたのを、platforms :mingw, :x64_mingw, :mswin, :mswin64を使用するよう修正しています。

-if Bundler::WINDOWS
+platforms :mingw, :x64_mingw, :mswin, :mswin64 do
   gem 'bcrypt-ruby', '~> 3.0.0', require: false
-else
+end

Gemfileで分岐処理書いてしまうと、bundle install実行する環境ごとにGemfile.lockが更新されてしまい宜しく無いので修正した、という事の筈…。


Use sprockets 3 in the Rails 5 release

Gemfile及びrailtiesの修正です。

sprockets4系を使用するようにしていたのをやめてsprockets3系を使用するよう修正しています。

Rails 5ではsprockets 4系にならないんですねえ。


Fix test failure on Windows

activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rbの修正です。

Windowsで、sqlite3がDB用のディレクトリを作成することを確認するテストがコケてしまっていたのを修正しています。

database fileをまだ使用しているのに削除しようとした為エラーになっていたようです。 DBのコネクションを確実にcloseするようにして対応しています。


Fix documentation about ApplicationRecord

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

ApplicationRecordの親クラスをActionController::Baseとしてしまっていたのを、ActiveRecord::Baseに修正しています。


Fix test failures on Windows

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

TimeZoneを指定したテストがWindowsでコケてしまっていたのを修正しています。

TimeZoneにAmerica/New_Yorkを指定していたのですが、この値がWindows環境で無い為エラーになってしまっていたようです。WindowsではEST5EDTを使用するよう修正しています。


Add mysql back to the Gemfile

Gemfileの修正です。

先のコミットで誤ってmysql gemをコメントアウトしてしまったのを戻しています。


Add Logger option to disable message broadcasts

activesupport/lib/active_support/logger.rbactivesupport/lib/active_support/logger_silence.rbの修正です。

ActiveSupport::Loggerに、messageのbroadcastsを行うかどうかを指定する為のbroadcast_messagesオプションを追加しています。

development環境でlogの出力先にSTDOUTを指定していた場合に、同じログが2回出力されてしまう問題があり、それを抑止出来るようにる為にオプションを追加しています。


Don't over-specify types in our tests

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

migrationで生成されるlock_idがFixnumかどうかチェックしているテストを削除しています。

Windows + PostgreSQLの環境だとOSにより生成される値が違う(BigNumになる場合がある)事があり、そもそもその値をチェックする必要は無いのでは、という事で削除されたようです。


Remove dead code

activerecord/lib/rails/generators/active_record/model/model_generator.rbの修正です。

使用されていないActiveRecord::Generators::ModelGenerator#accessible_attributesメソッドを削除しています。


Do not define attributes_with_index as a Thor task

activerecord/lib/rails/generators/active_record/model/model_generator.rbの修正です。

ActiveRecord::Generators::ModelGenerator#attributes_with_indexメソッドpublicからprotectedに移動しています。

public methodだとThorのタスクとして認識されてしまう為、タスクとして認識されないようにする為移動したとの事です。


Make sure File.exist? run in the root of the application

activerecord/lib/rails/generators/active_record/model/model_generator.rbの修正です。

modelを生成する際、app/models/application_record.rbが存在するかどうかのチェックを、必ずRails.rootで行うよう修正しています。

-          if File.exist?('app/models/application_record.rb')
+          application_record = nil
+
+          in_root { application_record = File.exist?('app/models/application_record.rb') }

app/models/application_record.rbが存在する場合のみ、modelの親クラスがApplicationRecordとなるようになり、ファイルが存在しない場合は今まで通りActiveRecord::Baseが親クラスになります。


join_to_delete is same as join_to_update

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

ActiveRecord::ConnectionAdapters::DatabaseStatements#join_to_deleteメソッドの実装が#join_to_updateメソッドと同じだった為、#join_to_deleteメソッドを削除し、#join_to_updateのaliasとして定義するよう修正しています。

が、aliasにする際、#join_to_updateの引数を#join_to_deleteと合わせるようにしたのですが、それにより#join_to_updateメソッドの引数が変わってしまい、既存のライブラリ(oracle-enhanced/oracle_enhanced_adapter.rb at 3c42131db82b64ac41645db3affc6e4650289df6 · rsim/oracle-enhanced)に影響がある為、後ほどrevertされています。


Revert "Merge pull request #22615 from kamipo/join_to_delete_is_same_as_join_to_update"

join_to_delete is same as join_to_updateをrevertしています。理由は上記参照。


fix typo in method name [ci skip]

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

RecordInvalidエラーが発生するメソッド名を、ActiveRecord::Base#save -> ActiveRecord::Base#save!に修正しています。


[ci skip] Fix grammar and sentence framing

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

ActionMailer::Base#attachmentsメソッドのdocの修正です。

グラマーの修正、及び文の構成の修正を行っています。


Merge pull request #22616 from gfvcastro/test-ruby-2-2-4

.travis.ymlの修正です。

CIで実行するRubyのバージョンを2.2.3 -> 2.2.4に修正しています。


Pass over the ApplicationRecord changelog entry

activerecord/CHANGELOG.mdの修正です。

先日マージされた、ApplicationRecordについてのentryの説明を、全体的に修正しています。


ApplicationRecord documentation pass

各docの修正です。

doc内の各modelの親クラスを、まとめてActiveRecord::BaseからApplicationRecordに修正しています。


ApplicationRecord release notes entry

rails guideのA Guide for Upgrading Ruby on Railsの修正です。

Upgrading from Rails 4.2 to Rails 5.0の項に、ApplicationRecordについての説明を追加しています。


Merge pull request #22586 from rails/merge-action-cable

別ブランチで管理されていてAction Cableがrails本体にマージされました。

Action CableはWebSocketsをrailsアプリで使う為のフレームワークです。

RedisのPubSubを使用する為、Action Cableを使用するにはRedisが必須です。また、通常のapp serverとは別にWebSocketsの通信の為のサーバ(cable server)が必要になり、 こちらはPumaが必要になります。

cable serverはrack appなので、通常のrack app同様にconfig.ruを記載する必要があります。

# cable/config.ru
require ::File.expand_path('../../config/environment', __FILE__)
Rails.application.eager_load!

require 'action_cable/process/logging'

run ActionCable.server
#!/bin/bash
bundle exec puma -p 28080 cable/config.ru

Action Cableを使用するには、server / client両方Channel用の処理が必要なのですが、まだgeneratorが無いので、試したい場合は、Action CableのREADME を見るか、railsが提供しているAction Cable Examplesのコードを見るのがわかりやすいきがします。


Include example of allowed_request_origins

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

config.action_cable.allowed_request_originsを指定した場合のexampleを追加しています。


Deal with leading CR when its not a mountable engine

railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rbの修正です。

mountable engineの場合に、controller testに不要な空白が生成されてしまっていたのを修正しています。

これ、結果的に不要なスペースが生成されるようになってしまったような。


README.rdoc -> README.md for newly generated plugins

rails pluginで生成されるREADMEのフォーマットをrdocからmarkdownに修正しています。


Puma 2.15.3 actually works fine

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

Pumaのインストール先にgithubのmasterを指定していたのを削除しています。リリース済みのPuma 2.15.3で正常に動作する為、との事です。


Kill extra newline at the start of generated manifest.js

railties/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.ttの修正です。

生成されるmanifest.jsの先頭から不要な空行を削除しています。


Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread

Active Supportの修正です。

thread毎にclass / moduleの変数の設定/取得をする為の、#thread_mattr_writer#thread_cattr_writer#thread_mattr_accessor#thread_cattr_accessorメソッドを追加しています。

module Current
  thread_mattr_reader :user
end

Current.user # => nil
Thread.current[:attr_Current_user] = "DHH"
Current.user # => "DHH"

Use consistent references

activesupport/CHANGELOG.mdの修正です。

Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-threadCHANGELOGのentry内に記載したexampleで使用するクラス・変数名を統一するよう修正しています。


Fix section about ApplicationRecord in upgrading guide [ci skip]

rails guideのA Guide for Upgrading Ruby on Railsの修正です。

Active Record models now inherit from ApplicationRecord by defaultの項、クラス名を誤っていた箇所があったのを修正しています。


Merge pull request #22621 from akshay-vishnoi/add-missing-tests

actionview/test/template/asset_tag_helper_test.rbの修正です。

asset_pathメソッドに空文字、及びスペースを指定した場合のテストが不足していたのを追加しています。


Update README.md

rails guideのAction Cable –- Integrated WebSockets for Railsの修正です。

ActiveRecord -> Active Recordに修正しています。


Use separate test class name

activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rbの修正です。

thread accessorsのテストで、ファイル名とテストクラス名が異なっていたのを、合わせています。