なるようになるブログ

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

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

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

CHANGELOGへの追加はありませんでした。


Add tests to ensure we don't interfere with json gem's output

ActiveSupportのテストの修正です。

active_support/jsonをロードした場合に、JSON gemが正常に動作する事を確認する為のテストを追加しています。

ActiveSupport 4.2 で、active_support/jsonをロードした場合 json gemの挙動を壊してしまうバグがあり、その確認の為に追加したようです。

issueはこちら

以下の様な処理を行った場合に、問題が起きていました。

irb(main):001:0> require 'json'
=> true
irb(main):002:0> obj = Struct.new(:key).new
=> #<struct key=nil>
irb(main):003:0> JSON.dump([obj])
=> "[\"#<struct key=nil>\"]"
irb(main):004:0> require 'active_support/json'
=> true
irb(main):005:0> JSON.dump([obj])  #=> SystemStackError: stack level too deep

active_support/jsonでは、to_jsonメソッドを呼び出すと、active_support/json内で追加したto_json_with_active_support_encoderメソッドが呼ばれるよう対応しています(Rails 4.2まではalias_method_chainを使用して実施)。

で、Fix #to_json for BasicObject Enumerables by codeodor · Pull Request #10278 · rails/rails の対応で、Enumerable moduleにもto_json_with_active_support_encoderメソッドを追加したのですが、JSON gemでは Enumerable moduleに to_jsonが定義されていない為、Object#to_jsonに対してaliasが設定されてしまい、メソッドの呼び出しがループしてしまっていたようです。 Objectクラスより先にEnumerableクラスにactive_support_encoderメソッドの設定をする事で対応しています。

なお、masterブランチではalias_method_chainが使われなくなっている(Module#prepend)ので、問題はおきていません。


Expand the JSON test coverage for Struct and Hash (?!)

activesupport/test/json/encoding_test_cases.rbの修正です。

JSON のテストに、Hashクラス、及びStructクラスを使用した場合のテストを追加しています。


Expand coverage of JSON gem tests

activesupport/test/core_ext/object/json_gem_encoding_test.rbの修正です。

JSON gemを使用したテストで、共通部分をメソッドに切り出しています。


added description instead of remove usage [ci skip]

actionpack/lib/action_controller/metal/renderers.rbactionpack/lib/action_dispatch/http/mime_type.rbのdocの修正です。

メソッドのdocに、メソッドについての説明を追加しています。


fix typo in caching guide [ci skip]

rails guideのCaching with Rails: An Overviewの修正です。

Russian Doll Cachingの項、view cacheのexampleにタイポがあったのを修正しています。