なるようになるブログ

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

rails commit log流し読み(2017/03/30)

2017/03/30分のコミットです。

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

activerecord/CHANGELOG.md


CI against Ruby 2.2.7

.travis.ymlの修正です。

CIで使用するRubyのバージョンを2.2.6から2.2.7に更新しています。


Fix link to rails-ujs

rails-ujsリポジトリへのリンクをhttps://github.com/rails/rails-ujsからhttps://github.com/rails/rails/blob/master/actionview/app/assets/javascriptsにまとめて修正しています。

rails/rails-ujsはprivateリポジトリになり、今後はrails配下のファイルが管理されていく為。多分。2回位ブレてる気がする。


Fix the example code for Rails.groups [ci skip]

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

Rails.groupsメソッドのexampleにある実行例で、Rails.envがSymbolで表示されていたのですが、実際はStringが返るようになっていたので、実行例もStringで表示するよう修正しています。


Configure the days until close a stale issue

.github/stale.ymlの修正です。

probot-stateの設定を変更しています。

# Number of days of inactivity before an issue becomes stale
-days: 90
+daysUntilStale: 90
+# Number of days of inactivity before a stale issue is closed
+daysUntilClose: 7

staleラベルをつけるまでが90日で、そのstaleラベルをつけたissueをcloseするまでが7日、というふうに設定を変更したようです。


Add test to make sure subclasses also get helpers

actionpack/test/controller/api/with_helpers_test.rbの修正です。

ActionController::APIを継承したクラスのサブクラスでもhelperメソッドが使える事を確認するテストを追加しています。


Merge pull request #28592 from htanata/ar_relation_inspect_should_not_load_all_records

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

ActiveRecord::Relation#inspectメソッドが毎回必ずrecordsのload処理を行っていたのを、既にrecordsをload済みの場合、load済みの値を使用するよう修正しています。


Small grammar fix

rails guideのAction Controller Overviewの修正です。

After Filters and Around Filtersの項のグラマーの修正を行っています。


Add aliases for reverse_merge to with_defaults

actionpack/lib/action_controller/metal/strong_parameters.rbactivesupport/lib/active_support/core_ext/hash/reverse_merge.rbactivesupport/lib/active_support/hash_with_indifferent_access.rbの修正です。

ActionController::ParametersHashWithIndifferentAccessHashreverse_mergereverse_merge!メソッドのaliasとしてwith_defaultswith_defaults!メソッドを追加しています。


Merge pull request #28417 from schneems/schneems/symlink-failures

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

Path#existentメソッドで指定されたファイルが存在しない、かつ、そのファイルがシンボリックリンクだった場合、Exceptionをraiseするよう修正しています。


Merge pull request #28609 from rossta/patch-2

actionview/test/template/sanitize_helper_test.rbのdocの修正です。

テストについてのdocで、網羅的なテストはtest/controller/html/sanitizer_test.rbでテストが行われている旨説明が記載されていたのですが、今はrails-html-sanitizer gemを使うようになっており、テストはgemの方で行うようになっている為、その旨コメントを修正しています。


Merge pull request #28606 from maclover7/jm-fix-25820

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

ActionController::Metalを継承したcontrollerのresponseのheaderにActionDispatch::Response.default_headersが含まれていたのを、Rails 4系まで同様含まれないよう修正しています。

rails commit log流し読み(2017/03/29)

2017/03/29分のコミットです。

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

activemodel/CHANGELOG.md


Merge pull request #28549 from jess/patch-1

railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.ttの修正です。

tmp/caching-dev.txtの存在チェックをしている箇所のコメントにrails dev:cacheコマンドでキャッシュの切り替えが出来る旨説明を追加しています。


Fix ActiveModel::Errors #keys, #values

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

ActiveModel::Errors#keysメソッドをメッセージが空のkeyを返さないよう修正、及び、ActiveModel::Errors#valuesメソッドを空のvalueは返さないよう修正しています。

# Before
person = Person.new
person.errors.keys     # => []
person.errors.values   # => []
person.errors.messages # => {}
person.errors[:name]   # => []
person.errors.messages # => {:name => []}
person.errors.keys     # => [:name]
person.errors.values   # => [[]]

# After
person = Person.new
person.errors.keys     # => []
person.errors.values   # => []
person.errors.messages # => {}
person.errors[:name]   # => []
person.errors.messages # => {:name => []}
person.errors.keys     # => []
person.errors.values   # => []

Merge pull request #28514 from y-yagi/follow_up_to_28056

actionpack/test/controller/params_wrapper_test.rbの修正です。

store_accessorを使用している、かつ、request parameterにstore_accessorのkeyに一致する値が含まれていた場合に、paramsにその値が正しく設定されないバグがあったのを修正した、Wrap stored accessors in parametersで追加されたテストが、正しくstore_accessorについてのテストが出来ていなかったのを修正しています。


Merge pull request #1 from radiospiel/tickets/26955-listen-paths

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

ActiveSupport::EventedFileUpdateCheckerrails app以外のファイル(bundlerで追加されたgemのファイル)の更新検知まで行っていたのを、rails app内のファイルのみ更新検知するよう修正しています。


starts_with? is removed in Ruby 2.4

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

先の対応でstart_with?starts_with?にタイポしていたのを修正しています。


Merge pull request #28480 from mubashirhanif/add_keep_id_suffix_option_to_humanize_new

activesupport/lib/active_support/core_ext/string/inflections.rbactivesupport/lib/active_support/inflector/methods.rbの修正です。

ActiveSupport::Inflector.titleizeActiveSupport::Inflector.humanizeメソッドにkeep_id_suffixオプションを追加しています。

名前の通りで、Stringの末尾にidという文字があった場合に、それをそのまま表示するかどうかを指定する為のオプションです。

irb(main):003:0> 'author_id'.humanize
# => "Author"
irb(main):005:0* 'author_id'.humanize(keep_id_suffix: true)
# => "Author id"

Use keyword arguments instead of hash

activesupport/lib/active_support/core_ext/string/inflections.rbactivesupport/lib/active_support/inflector/methods.rbの修正です。

ActiveSupport::Inflector.titleizeActiveSupport::Inflector.humanizeメソッドの引数指定に、Hashではなくキーワード引数を指定出来るよう修正しています。


Merge pull request #28052 from kamipo/make_internal_methods_to_private

Active Recordの修正です。

AR内部で使うためだけの各種メソッドの可視性をprivateに変更しています。


Remove unnecessary javascript option check

railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.ttの修正です。

Remove -j (–javascript) option from rails new command.で削除されたjavascriptオプションを参照している箇所があったのを削除しています。


Make driven_by overridable

actionpack/lib/action_dispatch/system_test_case.rbの修正です。

driven_byメソッドを子クラスでオーバーライド出来るよう対応しています。

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: {url: "http://chrome:4444/wd/hub"}
end

class WithoutJavascriptTest < ApplicationSystemTestCase
  driven_by :rack_test
end

上記のような書き方が出来るようになっています。


Remove CHANGELOG.md entry that appears in 5-1-stable

activemodel/CHANGELOG.mdの修正です。

Merge pull request #28050 from namusyaka/avoid-converting-int-into-floatの対応のエントリーを削除しています。

Rails 5.1にバックポートされた対応であり、Rails 5.2の新規対応では無い為。


Merge pull request #28478 from kamipo/fix_primary_keys_across_multiple_schemas

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

PostgreSQL adapterを使用している、かつ、異なるschemaに同じテーブル名のテーブルが存在している場合に、ActiveRecord::Base.connection.primary_keysメソッドが返す値がおかしくなってしまう(schema数分primary keyの値が返ってくる。e.g. ['id', 'id'])バグがあったのを修正しています。


add hint on after_action filters

rails guideのAction Controller Overviewの修正です。

After Filters and Around Filtersの項に、after_actionはactionが正常に行われた場合のみ実行される旨注記を追加しています。


FinderMethods#fourty_two docs cite proper source

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

forty_twoメソッドのdocのコメントを修正しています。

-    # Find the forty-second record. Also known as accessing "the reddit".
+    # Find the forty-second record. Also known as accessing "the answer to life the universe and everything".

rails commit log流し読み(2017/03/28)

2017/03/28分のコミットです。

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

activemodel/CHANGELOG.md

railties/CHANGELOG.md

activesupport/CHANGELOG.md


Merge pull request #28367 from ptoomey3/ignore-disabled-buttons

actionview/app/assets/javascripts/features/disable.coffeeactionview/app/assets/javascripts/rails-ujs.coffeeの修正です。

elementにdisabledが設定されている場合に、rail-ujsのeventを実行しないよう修正しています。

通常、対象となるelementにdisabledが設定されていれば当然eventは発火しないのですが、

<button type="submit" disabled="disabled" data-confirm="Confirm"><strong>Click me</strong></button>

上記のようなhtmlがあった場合に、strongタグのテキストをクリックした場合の挙動はブラウザによって異なる為、上記のような場合にもeventが発生しないようujs側でガード処理を入れた、との事です。へー。


Add probot/stale configuration

Integrations - probot-staleの設定をrails/railsリポジトリに追加しています。


Use the stale branch

.github/stale.ymlの修正です。

probotが設定するlabelをstaleに修正しています。


Merge pull request #27636 from mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2

activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rbactiverecord/lib/active_record/connection_adapters/postgresql_adapter.rbの修正です。

fixturesのインサート処理等のように、一時的に外部キー制約を無効にしたい場合、PostgreSQLではDISABLE TRIGGER ALLを使用するようになっていたのを、SET CONSTRAINTS ALL DEFERREDが使用出来る場合(9.4.2以上)の場合、そちらを使用するよう修正しています。

SET CONSTRAINTS ALL DEFERREDDISABLE TRIGGER ALLと異なりsuperuser権限は不要です。


Merge pull request #28488 from kamipo/preprocess_association_query_handling

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

predicate builderでassociation queryの処理が後処理で行われていたのを、処理の最初に行うよう修正しています。

これにより、不要なskip処理やガード句を減らせる為、との事です。


Merge pull request #28050 from namusyaka/avoid-converting-int-into-float

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

Numericality Validatorが、validateする値にStringを指定された場合、validation処理実行時に値をFloatに変更して処理を行っていたのを、値がIntegerと思われる場合Integerとして処理を実行するよう修正しています。

Floatに変換してしまうと、less_than_or_equal_to等のチェックが正しく行われない為。


Apply the log_level default

railties/lib/rails/application/configuration.rbの修正です。

log_levelのデフォルトを全ての環境で:debugになるよう修正しています。

元々Rails 5.0で:debugにするよう、deprecateメッセージも出していた(Remove deprecation warning when log_level is not explicit set on prod…)のですが、値の変更が漏れていた為、こんかい対応したとの事です。


Merge pull request #28546 from claudiob/drop-j-option

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

rails newコマンドから-j (--javascript) オプションを削除しています。

元々prototype-railsjquery-railsのようにJSをラップしたgemを指定する為のオプションだったのですが、prototypeはもう使われなくなり、jqueryももうデフォルトでは無くなった為、オプション自体もう不要だろうという事で削除されています。


Merge pull request #28557 from y-yagi/remove_unnecessary_files_to_api_applications_when_app_task_task_executed

railtiesの修正です。

API-only Applicationsでapp:updateタスクを実行した場合に、API-only Applicationsに不要なファイル(config/initializers/assets.rbbin/yarn等)が生成されてしまっていたのを、削除するよう修正しています。


Make sure that ActionController::Api can include helpers

actionpack/test/controller/api/with_helpers_test.rbの修正です。

ActionController::APIがhelpersをinclude出来る事を確認するテストを追加しています。


Fix the tests to test what they should be testing

railties/test/application/middleware/cache_test.rbの修正です。

cacheのテストで、headerの指定方法に誤りがあったのを修正しています。 Rack::Testを使用している場合、HTTP_にマッチするフォーマットを指定する必要があるんですねえ。


No need to duplicate 5-1-stable CHANGELOG. [ci skip]

railties/CHANGELOG.mdの修正です。

scaffoldで生成するform用のhtmlで、field idを出力するよう修正した対応(Use short-form for the scaffold render calls and drop the needless test)のエントリーを削除しています。

Rails 5.1にバックポートされた対応であり、Rails 5.2の新機能では無い為。


Return unmapped timezones from country_zones

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

ActiveSupport::TimeZone.country_zonesメソッドに、ActiveSupport::TimeZone::MAPPINGに定義されていないコードを指定した場合、空配列が返されていたのを、正しいtime zoneの値を返すよう修正しています。

# before
ActiveSupport::TimeZone.country_zones('GT')
# => [#<ActiveSupport::TimeZone:0x007ff9f0c61c08 @name="Central America", @utc_offset=nil, @tzinfo=#<TZInfo::DataTimezone: America/Guatemala>>]
ActiveSupport::TimeZone.country_zones('SV')
# => []

# after
ActiveSupport::TimeZone.country_zones('GT')
# => [#<ActiveSupport::TimeZone:0x007ff9f0c61c08 @name="Central America", @utc_offset=nil, @tzinfo=#<TZInfo::DataTimezone: America/Guatemala>>]
ActiveSupport::TimeZone.country_zones('SV')
# => [#<ActiveSupport::TimeZone:0x00555b99229288 @name="America/El_Salvador", @utc_offset=nil, @tzinfo=#<TZInfo::DataTimezone: America/El_Salvador>>]

MAPPINGに定義されていない値については、TZInfo::Country#zone_identifiersから値を取得するようになっています。

rails commit log流し読み(2017/03/27)

2017/03/27分のコミットです。

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


Do not show hidden namespaces in destroy commnad help

railties/lib/rails/commands/destroy/destroy_command.rbの修正です。

destroyコマンドのヘルプに表示すべきではないnamespaceが表示されてしまっていたのを、表示されないよう修正しています。


Fixes #28359

activerecord/lib/active_record/railties/databases.rakeactiverecord/lib/active_record/tasks/database_tasks.rbの修正です。

VERSION環境変数に空文字を指定してdb migrate用のtask(db:migratedb:migrate:redo等)を実行した場合に、エラーにならずmigrate処理が実行されてしまっていたのを、エラーにして処理を行わないよう修正しています。


ignore system test gems on Gemfile when execute with –skip-test option

railtiesの修正です。

rails newskip-testオプションを指定した場合、Gemfileにsystem testに関するgem(capybaraselenium-webdriver)を追加しないよう修正しています。

rails commit log流し読み(2017/03/26)

2017/03/26分のコミットです。

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

railties/CHANGELOG.md


Add WIP Rails 5.1 release notes to documents.yaml

guides/source/documents.yamlの修正です。

guideの一覧にRuby on Rails 5.1 Release Notesを追加しています。


Upgrade various Rails 5.0 references to 5.1

rails guideの修正です。

各guide内でRailsのバージョンが5.0になっている箇所を、まとめて5.1に修正しています。


Update middleware list

rails guideのThe Rails Command Lineの修正です。

bin/rails about taskの実行内容を最新の内容に更新しています。


Small grammar fix

rails guideのContributing to Ruby on Railsの修正です。

Testing Patchesの項のグラマーの修正を行っています。


Small grammar fix

rails guideのContributing to Ruby on Railsの修正です。

冒頭guideについての説明部分のグラマーの修正を行っています。


Bump from h3 to h2 tag

RELEASING_RAILS.mdの修正です。

3 Days before releaseのフォーマットをh3からh2に修正しています。他の箇所と段落を合わせる為。


add field ids when generating a scaffold form.

railties/lib/rails/generators/erb/scaffold/templates/_form.html.erbの修正です。

scaffoldで生成するform用のhtmlで、field idを出力するよう修正しています。

-    <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
+    <%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, id: :<%= field_id(attribute.column_name) %> %>

form_withはデフォルトではid属性を出力しないようになっているのですが、id属性が無いとlabelとリンクされない為、明示的にidを出力するようにしたとの事です。


minor CHANGELOG formatting changes. [ci skip]

railties/CHANGELOG.mdの修正です。

先ほど追加されたCHANGELOGのエントリーをファイルの先頭に移動しています。

rails commit log流し読み(2017/03/25)

2017/03/25分のコミットです。

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


Update Action Cable README.md - typo fix

actioncable/README.mdの修正です。

Connectionクラスでuserをverifyする処理のexampleで===にタイポしていたのを修正しています。

      def find_verified_user
-        if current_user = User.find_by(id: cookies.signed[:user_id])
+        if current_user == User.find_by(id: cookies.signed[:user_id])
           current_user

が、元のコード(=)が正しかった為、後ほどrevertされています。


Fix doc format for duplicable? [ci skip]

activesupport/lib/active_support/core_ext/object/duplicable.rbのdocの修正です。

duplicable?メソッドのdoc内のexampleコードでインデントが足りておらず、exampleが正しく表示されてなかったのを修正しています。


Revert “Merge pull request #28569 from HarryCollins/patch-1”

Connectionクラスでuserをverifyする処理のexampleで===にタイポしていたのを修正した、Update Action Cable README.md - typo fix をrevertしています。理由は先に書いた通り。


Rename local variable name current_user to verified_user [ci skip]

actioncable/README.mdの修正です。

Connectionクラスでuserをverifyする処理のexampleで、verifyしたuserを格納する変数の変数名をcurrent_userからverified_userに修正しています。


Rename local variable name current_user to verified_user [ci skip]

rails guideのAction Cable Overviewの修正です。

先のactioncable/README.mdの修正と同様に、verifyしたuserを格納する変数の変数名をverified_userに修正しています。

rails commit log流し読み(2017/03/24)

2017/03/24分のコミットです。

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


Merge pull request #28532 from maclover7/jm-ruby-241

.travis.ymlの修正です。

CIで使用するRubyのバージョンを2.4.1に更新しています。


Additional explanation about cache implementations

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

ActiveSupport::Cache::MemoryStoreの項に、memory storeの場合cache dataをプロセス間で共有しない為、rails console経由でcacheのexpire等は行えない旨説明を追加しいています。


update guide to reflect browser compatibility for HTTP verbs [ci skip]

rails guideのRuby on Rails Security Guideの修正です。

DELETE, PUT, 及び PATCHメソッドについて説明している箇所に、古いブラウザではこれらのメソッドをサポートしてない旨(最新のブラウザではサポートしている)説明を修正しています。


Remove unnecessary ruby version comments [ci skip]

activesupport/lib/active_support/core_ext/object/duplicable.rbのdocの修正です。

Complex#duplicable?Rational#duplicable?メソッドのdocに、Ruby 2.5.0未満では複製出来ない旨説明が記載されていたのを、Rubyのバージョンについての部分を削除しています。ここでRubyのバージョンについて明言する必要は無いという事で削除されたようです。


Doc cleanup for caching guide [ci skip] (#28556)

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

ActiveSupport::Cache::MemoryStoreの項の言い回しを修正しています。