2016/02/11分のコミットです。
CHANGELOGにのったコミットは以下の通りです。
Merge pull request #23512 from y-yagi/set_association_name_to_fixture
railties/lib/rails/generators/test_unit/model/templates/fixtures.ymlの修正です。
migrationのattributeにreferenceを使用している場合に、生成されるfixtureにassociation名を設定するよう修正しています。
Rails 5からactive_record.belongs_to_required_by_defaultがtrueになり、belongs_to associationを使用する場合associationを設定する必要があるようになり、fixtureにassociation名が設定されていないとデフォルトで生成されたテストがエラーになってしまう為、設定を追加しています。
Merge pull request #22772 from gsamokovarov/nack-template-error
actionview/lib/action_view/template/error.rbの修正です。
ActionView::Template::Errorをreraiseした場合に、元のExceptionがわからなくなってしまう問題があった為、cause attributeに、元のExceptionの情報を保持するよう修正しています。
Merge pull request #21671 from kaspth/integration-request-encoding-helpers
actionpack/lib/action_dispatch/testing/integration.rbの修正です。
integration testのrequest処理用メソッド(post、get)にmime typeを指定する為のasオプションを追加しています。
# before post articles_path(format: :json), params: { article: { title: 'Ahoy!' } }.to_json, headers: { 'Content-Type' => 'application/json' } # after post articles_path, params: { article: { title: 'Ahoy!' } }, as: :json
これは便利そう。
Set postgresql poolsize via RAILS_MAX_THREADS
railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.ymlの修正です。
poolsizeの値をRAILS_MAX_THREADSから取得するよう修正しています。
- pool: 5 + pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Add Default Puma Config by schneems · Pull Request #23057 · rails/railsで追加されたpumaのconfigでthread数をRAILS_MAX_THREADSで取得するようになっており、その数と合わせる為、修正したとの事です。
Merge pull request #23583 from brchristian/penultimate
Active Record / Active Supportの修正です。
Arrayにsecond_to_last、third_to_lastメソッドを追加、及びActiveRecordのFinderMethodにsecond_to_last、third_to_last、second_to_last!、third_to_last!メソッドを追加しています。
名前の通りで、"最後から2つめの値"、及び"最後から3つめの値"を取得出来るメソッドです。
(1..10).to_a.second_to_last # => 9 (1..10).to_a.third_to_last # => 8 User.second_to_last # => User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", -2]] User.third_to_last # => User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", -3]]
second_to_last!、third_to_last!は値が取得出来なかった場合ActiveRecord::RecordNotFoundがraiseされます。
Merge pull request #23274 from KeithP/actioncable_logging
actioncable/lib/action_cable/connection/base.rbの修正です。
Action Cableのconnectionに成功 / 失敗した場合に、それぞれ詳細なログを出力するよう修正しています。
Add parsed_body to spare writing out parsing routines.
Action Packの修正です。
integration test用のResponseクラスに、parse済みのbodyを取得する為のparsed_bodyメソッドを追加しています。
parserはregister_encoderメソッド経由で任意のparserが登録可能になっています。
ActionDispatch::IntegrationTest.register_encoder :wibble,
param_encoder: -> params { params.to_wibble },
response_parser: -> body { body }
また、デフォルトでMimeがJSONの場合のparse処理(JSON.parse)は設定されています。
CHANGELOGより。
# before require 'test_helper' class ApiTest < ActionDispatch::IntegrationTest test 'creates articles' do assert_difference -> { Article.count } do post articles_path(format: :json), params: { article: { title: 'Ahoy!' } }.to_json, headers: { 'Content-Type' => 'application/json' } end assert_equal({ id: Article.last.id, title: 'Ahoy!' }, JSON.parse(response.body)) end end
# after require 'test_helper' class ApiTest < ActionDispatch::IntegrationTest test 'creates articles' do assert_difference -> { Article.count } do post articles_path, { article: { title: 'Ahoy!' } }, as: :json end assert_equal({ id: Article.last.id, title: 'Ahoy!' }, response.parsed_body) end end
Add request encoding and response parsing to changelog.
actionpack/CHANGELOG.mdの修正です。
先に追加されたrequest encoding設定及びresponseのparse処理について、CHANGELOGに追記しています。
build scope chain functionally and remove caching
activerecord/lib/active_record/reflection.rbの修正です。
scope chainの生成処理を一つのメソッドで行っていたのを、各種メソッドに切り出しています。合わせて、chainの情報をキャッシュしていたのを、止めています。キャッシュしていても性能に影響が無い為、との事です。
check supports_view_paths? at registration time
actionview/lib/action_view/dependency_tracker.rbの修正です。
ActionView::DependencyTracker.find_dependenciesメソッドで行っていたtrackerに対するsupports_view_paths?のチェックを登録時(ActionView::DependencyTracker.register_tracker)に行うよう修正しています。
register_trackerが呼ばれるのは一度だけに対して、find_dependenciesは複数回呼ばれるので、不要なsupports_view_paths?のチェック処理を減らす為。
Merge pull request #23395 from PareshGupta/remove-unused-constant
Active Recordの修正です。
使用していないReaderMethodCache、WriterMethodCache定数を削除しています。
sort templates after looking them up in the from the paths cache https://github.com/rails/rails/commit/dfa0ab50f9d7357a670edb5178646176809f9e27
actionview/lib/action_view/dependency_tracker.rbの修正です。
view path cacheを取得する際、名前順にソートした値を返すよう修正しています。
元々はソートを行っていなかった為、返される値はファイルシステムに依存していたので、環境によって戻ってくる値の順番が違くなってしまうという問題があった為、値をソートして返すようにしたとの事です。
Update active_record_querying.md
rails guideのActive Record Query Interfaceの修正です。
scopeの中で条件式を使用した場合のexampleを追加、及びscopeは必ずActiveRecord::Relationを返す必要がある旨説明を追加しています。
Merge pull request #23596 from afn/issue-23058
activesupport/lib/active_support/deprecation/behaviors.rbの修正です。
config.active_support.deprecationに:raiseを指定した場合に、TypeError(set_backtrace': backtrace must be Array of String (TypeError)が出てしまうバグがあったのを修正しています。
DeprecationクラスでExceptionのbacktraceを設定する際callstackをそのまま設定していたのですが、callstackがStringではないケースがあった為エラーになっていたようです。callstackをStringに変換して対応しています。
Merge pull request #23605 from y-yagi/remove_warnings_in_finder_methods
activerecord/lib/active_record/relation/finder_methods.rbの修正です。
FinderMethod moduleのメソッドでRubyのwarning(ambiguous first argument; put parentheses or a space even after-' operator)が出ていたのを、メソッド呼び出しに()`を追加し対応しています。