なるようになるブログ

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

rails commit log流し読み(2017/02/21)

2017/02/21分のコミットです。

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

actionpack/CHANGELOG.md


Merge pull request #25877 from kamipo/delegate_to_scope_rather_than_merge

Active Recordの修正です。

collection proxyを生成する際に必ずassocation.scopeの結果をmergeしていたのを、必要に応じてscope(assocation.scope)にメソッド呼び出しをdelegateするようにして、不要な場合はassocationのscope呼び出し、及びmerge処理を行わないよう修正しています。

Rails 3.2 -> 4.0にアップグレードにhas_many associationが遅くなっていたのは、このmergeとassociation.scopeの呼び出しが原因だった為、この対応により大分性能改善されそうです。ありがたや。


Merge pull request #27863 from robin850/api-improvements

api docのsidebarRubyのcoreを拡張したクラスがそのまま羅列されていたのを、coreを拡張したクラスはCore extensionsというラベル配下にまとめるよう修正しています。

beforeaftersidebarを見比べて頂けるとわかりやすいかと思います。


Revert “Merge pull request #27925 from robin850/hwia-removal”

top levelのHashWithIndifferentAccessをdeprecateにした、Merge pull request #27925 from robin850/hwia-removalをrevertしています。

yamlを生成した際に必ずActiveSupport::HashWithIndifferentAccessになるようtop levelのHashWithIndifferentAccessencode_withメソッドを定義していたのですが、これだとHashWithIndifferentAccessを継承したクラスのyaml生成結果にも影響が出てしまう(子クラスのクラス名ではなく、こちらもActiveSupport::HashWithIndifferentAccessとして生成されてしまう)為、revertしたようです。


Merge pull request #27941 from y-yagi/prevent_multiple_values_being_set_to_run_via

Active Support、railtiesの修正です。

rake経由でテストを実行した場合に、Minitest.run_viaに複数の値が設定されるようになってしまっていたのを、設定されないよう修正しています。


Merge pull request #26703 from eileencodes/rails_system_tests

System Test(browserを使用してのテスト)の為のActionDispatch::SystemTestCaseクラスを追加しています。ActionDispatch::SystemTestCaseCapybara::DSLをincludeしており、Capybaraのメソッドが使えるようになっています。

System Test作成用のgeneratorが提供されており、bin/rails generate system_test xxxでSystem Testが作成出来るようになっています。実際にgeneratorを実行(bin/rails generate system_test users_create_test)すると、下記クラスが生成されます。

# test/application_system_test_case.rb
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
# test/system/users_create_tests_test.rb
require "application_system_test_case"

class UsersCreateTestsTest < ApplicationSystemTestCase
  test "visiting the index" do
    visit users_create_tests_url

    assert_selector "h1", text: "UsersCreateTest"
  end
end

ActionDispatch::SystemTestCaseを継承したApplicationSystemTestCaseクラスが生成されるようになっており、そこで共通の処理が定義出来るようになっています。また、デフォルトではseleniumドライバーを使うようになっていますが、driven_by:poltergeistを指定する事で、poltergeistも使用出来るようになっています。

他にもスクリーンショットをとる為のヘルパーメソッドが提供されてたりします。こちらについてはAPI doc参照。


Add changelog for system tests

actionpack/CHANGELOG.mdの修正です。

先のActionDispatch::SystemTestCaseの対応についてCHANGELOGにentryを追加しています。


Add missing space

actionpack/CHANGELOG.mdの修正です。

先のコミットで追加されたActionDispatch::SystemTestCaseの対応についてのentryで、スペースが不足していたのを追加しています。


Merge pull request #28083 from eileencodes/ensure-test-threads-shared-db-conn

Active Recordの修正です。

テスト実行時に、スレッド間で同じDB connectionを使うよう修正しています。fixturesのsetup / teardown実行時にスレッドのlockをするようにしており、それ以外の環境では影響が出ないようにしています。


Merge pull request #28081 from meinac/fix_redirect_method

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

redirect_toメソッドでresponse bodyに設定するredirect先URLの情報を、response.locationから取得するよう修正しています。

-      self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
+      self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(response.location)}\">redirected</a>.</body></html>"

locationメソッドを参照してしまうと、contollerに独自のlocationメソッドが定義されていた場合に、そちらが使用されてしまい、予期せぬ挙動になるため。


Fix some grammar in docs [ci skip]

actionpack/lib/action_dispatch/system_test_case.rbのdoc及びrails guideのA Guide to Testing Rails Applicationsの修正です。

グラマーの修正、及び不要なスペースの削除を行っています。


Merge pull request #28055 from robertomiranda/patch-3

railties/lib/rails/generators/app_base.rbの修正です。

rails newで生成するGemfileで使用するpumaのバージョンを3.7以上に修正しています。


Fix run_via[]= backwards compatibility.

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

Minitest.run_viaに古い形式で値を設定(Minitest.run_via[:rails] = true)しようとした場合に、エラーになってしまっていた(引数の受け取り方に誤りがあった)のを修正しています。


Merge pull request #28088 from y-yagi/do_not_generate_templates_to_api_doc

railties/lib/rails/api/task.rbの修正です。

API docにtemplateファイルが表示されていまっていたのを、templateファイルはAPI docに表示されないよう修正しています。


Fix define_attribute_method with Symbol in AR

railties/lib/rails/api/task.rbの修正です。

define_attribute_methodメソッドにSymbolを渡した場合、NoMethodErrorでエラーになってしまうバグがあったのを修正しています。