なるようになるブログ

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

rails commit log流し読み(2015/11/24)

2015/11/24分のコミットです。

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

activerecord/CHANGELOG.md


Test if each_object(singleton_class) works, since JRuby added it.

activesupport/lib/active_support/core_ext/class/subclasses.rbの修正です。

Class#descendantsメソッドを定義する際に、ObjectSpace.each_objectメソッドの引数にオブジェクトを指定していたのを、singleton classを指定するよう修正しています。

-    ObjectSpace.each_object(Class.new) {}
+    # Test if this Ruby supports each_object against singleton_class
+    ObjectSpace.each_object(Numeric.singleton_class) {}

元々JRubyではObjectSpace.each_objectの引数にsingleton classは指定出来なかったのですが、JRuby 9.0.5.0から指定出来るようになった、かつ、singleton classで見れない場合、descendantsメソッドではObjectSpace.each_objectClassを指定してチェックするようにしているのですが、Class経由だと数が多く、性能が悪いため修正したとの事です。


Remove blanket array delegation from Relation

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

ActiveRecord::Delegationから、RelationからArrayにdelegation出来ないメソッドの一覧を定義していたBLACKLISTED_ARRAY_METHODS定数を削除しています。

black listで全てのメソッドを対応出来てはいなかった、かつ、現在RelationEnumerableをincludeしており、Arrayにdelegateしなくてはならないメソッドは少なくなった為、black listの方は削除し、Arrayにdelegateするメソッドの定義の方を更新し、対応しています。


Merge pull request #22372 from greysteil/clearer-ip-spoofing-comment

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

check_ip_spoofing -> ip_spoofing_checkに変数名を変更、及びIpSpoofAttackErrorが発生する場合の振る舞いについての詳細な説明を追加しています。


Move migration/postgresql_geometric_types_test.rb in adapters/postgresql/geometric_test.rb

activerecord/test/cases/adapters/postgresql/geometric_test.rbactiverecord/test/cases/migration/postgresql_geometric_types_test.rbの修正です。

PostgreSQLのgeometric型に関するテストを、activerecord/test/cases/adapters/postgresql/geometric_test.rbからactiverecord/test/cases/migration/postgresql_geometric_types_test.rbに移動しています。


Add schema dumping support for PostgreSQL geometric data types

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

PostgreSQLのGeometric Types(linelsegboxpathpolygoncircle)がschema dump時に正しく出力されるよう修正しています。


Merge pull request #18446 from cloud8421/actionmailer-unregister-interceptor

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

動的にinterceptor、preview_interceptorの解除をする為のBase.unregister_interceptor, Base.unregister_interceptors, Base.unregister_preview_interceptor 及び Base.unregister_preview_interceptorsメソッドを追加しています。


Merge pull request #17928 from sergey-alekseev/remove-unused-form-data-method

actionpack/lib/action_dispatch/http/request.rbの修正です。

ActionDispatch::Request#form_data?メソッドで、media typeのチェックで、content_mime_typeを直接参照していたのを、ラッパーメソッドである#media_typeメソッドを使用するよう修正しています。


Merge pull request #17013 from gsamokovarov/fix-null-resolver

actionview/lib/action_view/testing/resolvers.rbの修正です。

ActionView::NullResolver#queryメソッドActionView::Templateインスタンスを作成する際、参照する値を謝っていたのを修正しています。

   class NullResolver < PathResolver
     def query(path, exts, formats)
       handler, format, variant = extract_handler_and_format_and_variant(path, formats)
-      [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format, :variant => variant)]
+      [ActionView::Template.new("Template generated by Null Resolver", path.virtual, handler, :virtual_path => path.virtual, :format => format, :variant => variant)]
     end
   end

Merge pull request #21000 from twalpole/find_or_parameter_issues

Active Record / Active Modelの修正です。

ActionController::ParametersHashWithIndifferentAccessの子クラスで無くなった影響で、forbidden_attributes_protectionのテスト用クラスをHashWithIndifferentAccessから継承させないよう修正、 及びWhereChain#notメソッドで引数のsanitizeチェックを行うよう修正しています。


Revert "Merge pull request #18446 from cloud8421/actionmailer-unregister-interceptor"

動的にinterceptor、preview_interceptorの解除をする為のBase.unregister_interceptor, Base.unregister_interceptors, Base.unregister_preview_interceptor 及び Base.unregister_preview_interceptorsメソッドを追加した Merge pull request #18446 from cloud8421/actionmailer-unregister-interceptor をrevertしています。

テストでmochaを使うようになっていたのですが、このPRを投げられた後に、テストでmochaを使わないようになっており、その影響でテストがコケてしまった為、一旦revertしたとの事です。


Fix test failures caused by #21000

activemodel/test/cases/attribute_assignment_test.rbの修正です。

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


set_field_encoding is only needed for MysqlAdapter

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

引数の値をそのまま返すだけだったActiveRecord::ConnectionAdapters::Mysql2Adapter#set_field_encodingメソッドを削除、及びActiveRecord::ConnectionAdapters::AbstractMysqlAdapte#columnメソッドで直接set_field_encodingメソッドを呼び出さないよう修正しています。


Fix more test failures caused by #21000

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

各テスト用modelのrequireが不足していたので追加しています。


Merge pull request #22272 from y-yagi/remove_test_files_in_plugin_gemspec

railties/lib/rails/generators/rails/plugin/templates/%name%.gemspecの修正です。

rails plugin用のgemspecのテンプレートでtest_filesオプションを使用していたのを、削除しています。

test_filesオプションがdeprecateになっている(Documentation about 'test_files' is confusing · Issue #90 · rubygems/guides)と思われる為、削除されています。


Remove valgrind note about linux only support

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

Valgrindについて説明している箇所に、Linuxだけのアプリである旨記載されてあったのですが、Valgrind 3.11.0からMac OSXもサポートするようになった(Valgrind)為、該当部分の記載を削除しています。


Merge pull request #22287 from dharamgollapudi/patch-2

railties/lib/rails/tasks/dev.rakeの修正です。

dev:cache taskについてのdescを、task -Tでタスク名が表示されるよう、taskの定義の上に移動しています。


Merge pull request #22120 from hnatt/refactor-actionmailer

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

ActionMailer::Baseクラスのリファクタリングを行っています。

register_observerメソッドregister_interceptorメソッドでで共通していた処理をメソッドに切り出し、デフォルトの値の設定処理をメソッドに切り出し、変数名を適切な名前に変更、等を行っています。


nodoc in the private method

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

observer_class_forメソッド:nodoc:を設定しています。


Avoid mutating the headers hash

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

mailメソッド内で、headers hashから値をdeleteしていたのを、headers hashの状態は変えないよう修正しています。


Put all private method together

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

private メソッドがクラス内に点在していたのを、位置を一箇所にまとめるよう、メソッドの位置を移動しています。


Move all nodoc methods to the private section

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

rails内部用のメソッドについて、全てprivateセクションに移動しています。


Merge pull request #22172 from tijmenb/fix-source-in-show-exception

Action Packの修正です。

source codeのtemplateに、textのtemplateを追加しています。

AJAXでエラーが起きた際に、htmlではなくtextでrenderされるようにする為に追加されています。

PRより。

# before
$curl 'http://localhost:3000/' -H 'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

    <div class="source " id="frame-source-0">
      <div class="info">
        Extracted source (around line <strong>#3</strong>):
      </div>
      <div class="data">
        <table cellpadding="0" cellspacing="0" class="lines">
          <tr>
# after
$curl 'http://localhost:3000/' -H 'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

Extracted source (around line #3):

#1 class PostsController < ApplicationController
#2   def index
*3     raise
#4   end
#5 end

Merge pull request #22214 from kamipo/not_passing_native_database_types_to_table_definition

Active Recordの修正です。

TableDefinition#newの引数から、native_database_typesを削除しています。

native_database_typeslimitオプションのデフォルトとの値を取得するためだけに使われていたのですが、 type_to_sqlメソッドで同じ処理をしており、TableDefinitionで行う必要は無い為、削除したとの事です。


Merge pull request #22370 from yui-knk/remove_blank_line

railties/lib/rails/generators/rails/plugin/templates/rails/routes.rbの修正です。

pluginのroutes.rbのtemplateから、不要な空行を削除しています。


Merge pull request #22348 from kv109/22233_without_deprecation

activesupport/lib/active_support/values/time_zone.rbの修正です。

スイスのtimezoneのマッピングが間違えていたのを修正しています。

-      "Bern"                         => "Europe/Berlin",
+      "Bern"                         => "Europe/Zurich",
+      "Zurich"                       => "Europe/Zurich",

IANAによると、Zurich => Europe/Zurich があれば良いのですが、既存アプリの互換性の為にBernもそのまま残してあるとの事です。