なるようになるブログ

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

rails commit log流し読み(2015/09/08)

2015/09/08分のコミットです。

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

activerecord/CHANGELOG.md

activemodel/CHANGELOG.md

actionpack/CHANGELOG.md


Merge pull request #20534 from qnm/activesupport-require-issue

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

active_support/core_ext/date/calculationsのrequireが不足していたのを追加しています。


Typo fix [ci skip]

activerecord/test/models/face.rbのdocの修正です。

lengthlenghにタイポしていたのを修正しています。


Correct query for PostgreSQL 8.2

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

query_conditions_for_initial_loadメソッドでtype name取得する際、generic castを使用していたのですが、この機能が追加されたのがPostgreSQL 8.3なので、8.2より以前でも動作するよう、 regprocedureを使用して書きなおしています。

-                OR t.typinput::varchar = 'array_in'
+                OR t.typinput = 'array_in(cstring,oid,integer)'::regprocedure

Merge pull request #21069 from dmitry/feature/validate-multiple-contexts-at-once

Active Model / Active Recordの修正です。

valid? / invalid?メソッド複数のコンテキストを渡せるよう修正しています。

class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => false
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}

便利そう。 が、直ぐさまrevertされています。


Revert "Merge pull request #21069 from dmitry/feature/validate-multiple-contexts-at-once"

という訳で、先のvalid? / invalid?メソッド複数のコンテキストを渡せるよう修正したコミットをrevertしています。

revert理由は、"Active Recordのテストが壊れた為"となっていました。後ほど、テストを修正した状態で再度マージされています。


Merge pull request #21534 from Vratislav/clarify-custom-config-guide

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

Custom configurationの項、 custom configurationについて説明している箇所に、値はconfig.xプロパティ配下に設定される旨説明を追加しています。


Use Hash[] instead of Hash#dup in resolve_column_aliases

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

resolve_column_aliasesメソッドで、Hashの複製に。Hash#dupを使用していたのを、代わりにHash#[]を使用するよう修正しています。

Hash#dupはパフォーマンスに問題がある為、との事です。詳細は、 Bug #7166: Speed up Hash#dup by patching Hash#initialize_copy - Ruby trunk - Ruby Issue Tracking System 参照。


Validate multiple contexts on valid? and invalid? at once.

Active Model / Active Recordの修正です。

valid? / invalid?メソッドの対応を、再度コミットしています。


.gitignore: Ignore .ruby-version in any subdir

.gitignoreの修正です。

/.ruby-versionのみignoreの対象にしていたのを、ディレクトリを指定せず、ファイル名のみでチェック(.rub-version)するよう修正しています。


Support mysql2 0.4.0, first release with prepared statements support

Gemfileactiverecord/lib/active_record/connection_adapters/mysql2_adapter.rbの修正です。

仕様するmysql2 gemのバージョンを0.4.0以上に修正しています。

プリペアドステートメントを使用する為のようですねえ。


Make config.force_ssl less dangerous to try and easier to disable

actionpack/lib/action_dispatch/middleware/ssl.rbの修正です。

config.force_sslオプションの扱いについての改善対応を行っています。

SSL redirect: * :host:portオプションをredirectパラメータ内に移動 * :status:bodyをカスタマイズ出来るよう対応。301だとブラウザがキャッシュしてしまい、テストの際に使いづらいので、テストの際に302、307が使用出来るよう対応したようです。

HTTP Strict Transport Security (HSTS): * max-ageのデフォルトを1年から180に変更。 * hsts: falseを指定した場合、hstsを無効化出来るよう、hsts: { expires: 0 }を送信するよう修正。 * preload: trueオプションを指定した場合、ブラウザのpreload listにサイトを追加するよう送信します(Preloaded HSTSを使用)。

HSTSのpreloadの仕組みとか初めてしりました。詳細は、Ssl - HSTS (HTTP Strict Transport Security) の導入 - Qiitaをご参照。


Reduce allocation in resolve_column_aliases.

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

TableMetadata#resolve_column_aliasesメソッドで、不要なアロケーションが行われないようにする為に、 Hash#keys + Array#grepしていたのを、Hash#eachだけでループ回すりょうリファクタリングしています。性能改善対応。


Memoized reflections accessor

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

reflections accessorの値をメモ化するよう修正しています。

reflectionsの値は、add_reflectionメソッドを呼び出したりしない限り、クラスロード時から値が変わる事は無いため、一度作成した値を使いまわすよう修正したとの事です。


:bomb:

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

先の修正で、変数名をタイポしてしまっていた箇所があったのを修正しています。


Merge pull request #21519 from y-yagi/test_runner_raise_error

railties/lib/rails/test_unit/minitest_plugin.rbrailties/lib/rails/test_unit/test_requirer.rbの修正です。

rails testコマンドに存在しないファイルやディレクトリを指定した場合に、エラーになるよう修正しています。


Replace AR with ActiveRecord to make it more readable [ci skip]

各docの修正です。

Active Recordを、略語のARと記載していた箇所を、正式名称(Active Record)で記載するよう修正しています。


Add view tests for MySQL

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

MySQL adapterで、viewのテストがなかったので、テストを追加しています。


Define SchemaStatements#tables as interface

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

SchemaStatements#tablesメソッドを定義しています。

実際のメソッドの実装は各adapter配下でそれぞれ行っているので、インターフェースのみです(NotImplementedErrorをraiseするだけ)。


Merge pull request #21511 from rwz/ar-exceptions-no-args

Active Recordの修正です。

Active Record配下のエラークラスは、元々は引数が全て必須パラメータだったのですが、実際は使用しない引数もある為、 引数にデフォルト値を設定し、必須ではなくなるよう修正しています。

例。

   class HasManyThroughAssociationNotFoundError < ActiveRecordError #:nodoc:
-    def initialize(owner_class_name, reflection)
-      super("Could not find the association #{reflection.options[:through].inspect} in model #{owner_class_name}")
+    def initialize(owner_class_name = nil, reflection = nil)
+      if owner_class_name && reflection
+        super("Could not find the association #{reflection.options[:through].inspect} in model #{owner_class_name}")
+      else
+        super("Could not find the association.")
+      end
     end
   end