なるようになるブログ

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

rails commit log流し読み(2015/01/03)

2015/01/03分のコミットです。

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

activerecord/CHANGELOG.md

actionview/CHANGELOG.md

activesupport/CHANGELOG.md

railties/CHANGELOG.md


Remove support to activerecord-deprecated_finders

ActiveRecordの修正です。

activerecord-deprecated_findersサポート対応の為の処理を削除しています。


Merge pull request #18228 from kamipo/correctly_dump_primary_key

ActiveRecordの修正です。

デフォルト以外のprimary key を使用している場合に、dumpファイルに型とオプションについての情報が正しく出力されてなかったバグがあったのを修正しています。


Remove thread variables backport

activesupport/lib/active_support/core_ext/thread.rbを削除しています。

Thread変数を扱う為に拡張していたのですが、Ruby 2.0からRuby本体でthread_variablesをサポートしているので、もう不要との事で削除しています。


Merge pull request #17974 from killthekitten/fix-render-block

actionview/lib/action_view/helpers/rendering_helper.rbの修正です。

render "partial" にブロックを渡せるよう修正しています。

サンプル。

# `users/index.html.erb`
<%= render "shared/search_filters", search: @q do |f| %>
  <p>
    Name contains: <%= f.text_field :name_contains %>
  </p>
<%= end %>

# `roles/index.html.erb`
<%= render "shared/search_filters", search: @q do |f| %>
  <p>
    Title contains: <%= f.text_field :title_contains %>
  </p>
<%= end %>

# `shared/_search_filters.html.erb`
<%= form_for(@q) do |f| %>
  <h1>Search form:</h1>
  <fieldset>
    <%= yield f %>
  </fieldset>
  <p>
    <%= f.submit "Search" %>
  </p>
<% end %>

Merge pull request #17978 from kommen/fixed-pr-14903

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

ActiveSupport::Notifications.instrumentを使用して"process_action.action_controller"の計測を行う際、エラーが発生した際にもappend_info_to_payloadを実行するよう修正しています。

-        result = super
-        payload[:status] = response.status
-        append_info_to_payload(payload)
-        result
+        begin
+          result = super
+          payload[:status] = response.status
+          result
+        ensure
+          append_info_to_payload(payload)

Merge pull request #15309 from iantropov/issue_12698_build_through

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

"has_many through"を使用している時に、buildメソッドインスタンスを生成した際、foreign_keyが正しく設定されないバグがあったのを修正しています。


Merge pull request #17820 from fw42/restore_query_cache_on_rollback

ActiveRecordの修正です。

translationのrollback時に、query cacheをクリアーするよう修正しています。


Add default value for create_table_definition

ActiveRecordの修正です。

create_table_definitionメソッドの第二引数以降にデフォルト引数を設定しています。殆どのケースで最初の引数しか設定してない為、対応したとの事です。


Refactor visit_ChangeColumnDefinition

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

visit_ChangeColumnDefinitionメソッドリファクタリングを行っています。


Merge pull request #8547 from printercu/patch-1

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

invalid encodingが発生した際、エラーメッセージのエンコーディングを変更するよう修正しています。

+        begin
+          message = "#{e.class.name}: #{e.message}: #{sql}"
+        rescue Encoding::CompatibilityError
+          message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}"
+        end

エンコーディングのエラーが発生しているのに、そのエンコーディングのままメッセージを組み立てようとして更にエラーになってしまうケースがあった為、sqlエンコーディングを設定したようです。


Follow up to #17973 [ci skip]

actionview/lib/action_view/helpers/form_helper.rbの修正です。

先日行われたfile_fieldメソッド実行時にhidden_fieldを追加する対応についての説明を修正しています。


Revert part of 996e646bd8cff3bcf2b13863439f48d3e744cdae [ci skip]

The Guide to Testing Rails Applications is published!のコミットの一部をrevertし、Testing Guideをwork_in_progress: trueに戻しています。

その後、Testing Guideリリース用のPRが作成されたので、確認の為にrevertですかねえ。


A quick pass through NestedAttributes' doc [ci skip]

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

グラマーの修正、フォーマットの整理等を行っています。


Don't test invalid log encoding against PostgreSQL adapter

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

先に行われたinvalid encodingの対応につていのテストをPostgreSQLの場合実施しないよう修正しています。"It already treats the message"とコミットログに記載されているので、対応済み?


Add PolymorphicReflection and constraints method

ここからAssociationScope#add_constraintsメソッドリファクタリングの為のコミットが続きます。

scope_chainのflattenバージョンを生成する為のconstraintsメソッドと、PolymorphicReflectionクラスを新規に作成しています。


Add RuntimeReflection for recursive access to chain

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

実行時にreflection情報にアクセスするためのRuntimeReflectionクラスを新規に作成しています。


Refactor construct_tables method

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

construct_tablesメソッド内の処理を別メソッドに切り出して、リファクタリングを行っています。


Clean up assignments in #add_constraints

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

add_constraintsメソッド内で使用している変数を整理しています。


Move #alias_name to ReflectionProxy class

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

AbstractReflection#alias_nameメソッドReflectionProxyクラスに移動しています。


Refactor #get_chain to remove need for #construct_tables

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

construct_tablesメソッドを削除し、その中で行われていた処理をget_chainメソッド内に移動しています。


Refactor #get_chain iteration to a linked list

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

get_chainをLinked listでイテレーション出来るようリファクタリングしています。


Clean up / refactor new reflection classes

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

先に作成したPolymorphicReflectionRuntimeReflectionクラスをreflection.rb内に移動し、それぞれのクラスの継承関係を整理しています。


Assign the #alias_name to each reflection

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

各Reflectionクラスでalias_nameを保持するよう修正しています。


Pass connection rather than alias_tracker

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

add_constraintsメソッドにconnection情報を渡すよう修正しています。


Move alias_candiate into AbstractReflection

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

ReflectionProxy#alias_candiateメソッドAbstractReflectionクラスに移動しています。


Initialze #alias_tracker with base table name

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

AliasTrackerクラスのインスタンス生成用メソッドの引数にテーブル名を追加しています。


Add #all_includes method to reflections

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

RuntimeReflection#all_includesメソッドを追加しています。


Move #type_caster to alias tracker initialize

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

AliasTrackerクラスのインスタンス生成用メソッドの引数にtype_casterを追加しています。


Cleanup methods, missing spacing and missing nodocs

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

全体の変数名の整理、:nodoc:の追加、スペースの追加等を行っています。

AssociationScope#add_constraintsメソッドリファクタリングの為のコミットはここまで。


Merge pull request #8740 from amatsuda/missing_source_file

actionpack/lib/abstract_controller/helpers.rbの修正です。

default_helper_module!メソッドでrescueするクラスをMissingSourceFile -> LoadErrorに修正しています。 MissingSourceFileについての説明は次のコミットで。


Deprecate MissingSourceFile in favor of LoadError.

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

MissingSourceFileクラスがdeprecateになりました。

元々、MissingSourceFileLoadErrorクラスのエイリアスでしかなく、既にRailsの中で使用している箇所も無いことから、deprecateにしたとの事です。


Merge pull request #9065 from atombender/master

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

複数のLoggerを使用している場合に、タグ情報が異なるLoggerにもシェアされてしまうバグがあったのを修正しています。

以下例。

my_logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))
my_logger.push_tags "my_tag"
Rails.logger.info "test"  # outputs "[my_tag] test"
Rails.logger.tagged("other_tag") do
  my_logger.info "test"  # outputs "[my_tag] [other_tag]"
end

ちょっと使い方が特殊な感もありますが…。


Support datetime values in AR::Type::DateTime#type_cast_for_database

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

ActiveRecord::Base.default_timezone:localを設定している場合にdatetime型のカラムのデータの読み込み時にエラーがおこるバグがあったのを修正しています。


Unsafe default translations should not be marked html_safe

actionview/lib/action_view/helpers/translation_helper.rbの修正です。

translateメソッドdefault引数に値を指定し、defaultの値が返される場合に、リターンされる値にはhtml_safeが設定されていたのですが、 default設定する値はただの文字列であり、html_safeフラグが設定されているのはおかしいのでは、という事で、html_safeフラグは設定されないよう修正しています。

translation = translate(:'translations.missing', :default => [:'translations.missing_html', :'translations.foo'])
translation
translation.html_safe? # => false

Merge pull request #10380 from JonRowe/test_all_domain_2_letter_tld

actionpack/test/dispatch/cookies_test.rbの修正です。

@request.hostにTOP Level Domainに2文字、domainに3文字のホスト名を設定した場合のテストを追加しています。


Generated fixtures won't use parent_id when generated with parent:references

railties/lib/rails/generators/test_unit/model/templates/fixtures.ymlの修正です。

generatorにreferencesを指定した場合に、生成されるfixturesのファイル内のアソシエーションの定義から、"_id"を削除するよう修正しています。


Update Redcarpet to version 3.2.2

Gemfileguides/rails_guides.rbの修正です。

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


Consider html+erb as a valid language for snippets

guides/rails_guides/markdown/renderer.rbの修正です。

rails guideのスニペットのlangにhtml+erbを指定した場合に正しくハイライトされるよう修正しています。


Avoid displaying new lines inside note paragraphs

guides/assets/stylesheets/main.cssの修正です。

"note"パラグラフのスタイルを修正し、変な箇所で改行がされないよう対応しています。