なるようになるブログ

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

rails commit log流し読み(2017/04/07)

2017/04/07分のコミットです。

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

activerecord/CHANGELOG.md


Improve logging when Origin header doesn’t match

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

CSRF tokenのチェックでエラーになった場合、かつ、異なるoriginからのリクエストだった場合に、ログにその詳細(e.g. HTTP Origin header (http://bad.host) didn't match request.base_url (http://test.host))を出力するよう修正しています。


Fix warning: already initialized constant HashWithIndifferentAccessTest::HashWithIndifferentAccess

activesupport/test/hash_with_indifferent_access_test.rbの修正です。

HashWithIndifferentAccessを再定義している事によるRubyのwarningがでていたので、不要な定義処理を削除し対応しています。


Remove duplicated “test” prefix

各テストから、重複していた"test"という文字を削除しています。

例。

-  test "test type casting with emulated booleans" do
+  test "type casting with emulated booleans" do

Merge pull request #28632 from kamipo/fix_warning_extra_states_are_no_longer_copied

activemodel/lib/active_model/errors.rbの修正です。

ActiveModel::ErrorsRubyのwarning(warning: extra states are no longer copied)が出ていたのを修正しています。

    def values
-      messages.reject do |key, value|
-        value.empty?
+      messages.select do |key, value|
+        !value.empty?
       end.values
     end

default_procが設定されているHashに対してrejectメソッドを呼び出すと上記warningが出てしまうので、selectを使用するよう修正したようです。知らなかった。

参考:https://github.com/ruby/ruby/blob/v2_4_1/hash.c#L1335-L1337


Merge pull request #28670 from aledalgrande/activerecord-docs-fix

rails guideのActive Record Callbacksの修正です。

Halting Executionの項でcallback chainを止める方法にfalseをreturnする旨説明が記載されていたのを、throw :abortを行う必要がある旨説明を修正しています。


Passing in no arguments to the dynamic fixture accessor method returns all fixtures, not an empty array.

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

fixturesのaccessor methodに引数を指定しなかった場合に、全てのfixtureの値を返すよう修正しています。

# todo.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
  title: MyString
  user: one

two:
  title: MyString
  user: two
# before
todos
# => []

# after
todos
# => [#<Todo id: 980190962, title: "MyString", user_id: 980190962, created_at: "2017-04-07 21:30:11", updated_at: "2017-04-07 21:30:11">, #<Todo id: 298486374, title: "MyString", user_id: 298486374, created_at: "2017-04-07 21:30:11", updated_at: "2017-04-07 21:30:11">]