なるようになるブログ

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

rails commit log流し読み(2018/07/05)

2018/07/05分のコミットです。

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


A Class is a Module so we remove one conditional

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

LazyLoadHooks#execute_hookメソッドでbaseClassModuleかチェックするのに、ClassModuleそれぞれに対してis_a?チェックしていたのを、Moduleに対してだけチェックするよう修正しています。

-            if base.is_a?(Class) || base.is_a?(Module)
+            if base.is_a?(Module)

ClassModuleの為。


Remove vestigial require on ActiveStorage GCSService

activestorage/lib/active_storage/service/gcs_service.rbの修正です。

不要なactive_storage/filenameのrequireを削除しています。


Merge pull request #33220 from anniecodes/notes-command

railtiesの修正です。

rake taskとして実装されていたrails notesrails command(普通のRubyのクラス)として実装しています。

これにより、annotation対象のタグを環境変数ではなくコマンドの引数として指定出来るようになっています。

$ ./bin/rails notes --help
Usage:
  bin/rails notes [options]

Options:
  -a, [--annotations=one two three]  # Filter by specific annotations, e.g. Foobar TODO
                                     # Default: ["OPTIMIZE", "FIXME", "TODO"]

Make NotesCommand tests more performant by getting rid of unecessary map

railties/test/commands/notes_test.rbの修正です。

notes コマンドのテストで不要なダミーデータを作成しないよう修正しています。

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

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

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

actionview/CHANGELOG.md


Add safe html support to arrays of translations

actionview/lib/action_view/helpers/translation_helper.rbの修正です。

TranslationHelper#translateメソッドでI18n.translateで取得した結果がArray、かつ、HTMLだった場合に、html_safeメソッドが呼ばれていなかったのを、結果がArrayだった場合もhtml_safeメソッドを呼び出す(値全てに対してhtml_safeメソッドを呼び出す)よう修正しています。


Merge pull request #33054 from jboler/master

Action Pack、railtiesの修正です。

routesをeager loadする際に、正しくeager load処理が行われず、ActionDispatch::Journey::Pattern::MatchDataNoMethodErrorが発生してしまうバグがあったのを修正しています。

eager loadのタイミングを修正(RoutesReloaderの初期化処理で必ず行うよう修正)し対応しています。


Add changelog entry for 42c3537 [ci skip]

actionview/CHANGELOG.mdの修正です。

Add safe html support to arrays of translationsの対応についてCHANGELOGにエントリーを追加しています。


Remove old TODO comment

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

Rails::ActionMethods#method_missingにあったコメントを削除しています。

-      # TODO: Remove once this is fully in place
       def method_missing(meth, *args, &block)
         @generator.send(meth, *args, &block)

コメントが書かれたのが7年以上前で、現状このmethod_missingを消すのは難しい状態なので、コメントを消してしまって良いのでは、という事で削除されています。


Better compatibility with SPEC.

actioncable/lib/action_cable/connection/stream.rbの修正です。

Connection::Stream#hijack_rack_socketメソッドでHijacking APIを使用する際に、rack.hijack envをcallした値を使用するよう修正しています。

-        @socket_object.env["rack.hijack"].call
-        @rack_hijack_io = @socket_object.env["rack.hijack_io"]
+        # This should return the underlying io according to the SPEC:
+        @rack_hijack_io = @socket_object.env["rack.hijack"].call
+        # Retain existing behaviour if required:
+        @rack_hijack_io ||= @socket_object.env["rack.hijack_io"]

RackのSPECによると、rack.hijack envをcallした結果はrack.hijack_ioを返すよう推奨されており、別途rack.hijack_io envを参照する必要は無い為。

参考:https://github.com/rack/rack/blob/eb040cf1bbb1b2dacd496ab0aa549de8408d8a27/SPEC#L89-L93


Use class_eval or instance_eval when triggering lazy load hooks:

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

lazy load hookを実行する際に、実行する対象がClass or Moduleの場合、instance_evalではなく、class_evalを使用するよう修正しています。

class_evalを使用しないとrun_load_hooksbaseにClass or Moduleが使用された場合に、hookに指定されたメソッドが呼び出せない為。

rails commit log流し読み(2018/07/03)

2018/07/03分のコミットです。

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


Merge pull request #33242 from brasic/sqlite-readonly

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

SQLite3AdapterでSQLite3::Databasereadonlyオプションを渡せるよう修正しています。


Merge pull request #32987 from kevgathuku/patch-2

rails guideのGetting Started with Enginesの修正です。

Engine setupの項、engineのinstall:migrationsコマンドを実行する場所の説明に誤りがあったのを修正していまs.


Don't share seen object cache between different join nodes in eager loading

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

eager loadingで、target classが同じ場合に異なるjoin nodesのcacheを共有するようにしていたのを、共有しないよう修正しています。

target classが同じでもインスタンスの状態が違う(片方は普通にread出来るインスタンスで、もう片方はreadonlyが指定されている等)可能性がある為。


Don't extract readonly_value each time

activerecord/lib/active_record/associations/join_dependency.rbactiverecord/lib/active_record/associations/join_dependency/join_association.rbの修正です。

readonly_valueを必要な時に毎回値を取得していたのを、一度値を取得したらその値をキャッシュするよう修正しています。


Use construct_join_dependency in all places

Active Recordの修正です。

JoinDependencyを生成するのにActiveRecord::Associations::JoinDependency.newを直接呼び出している箇所があったのを、construct_join_dependencyメソッドを使用するよう統一しています。


ActiveJob::Base no longer dependents on Serializers

activejob/lib/active_job/base.rbactivejob/lib/active_job/serializers.rbの修正です。

ActiveJob::Base、及び、ActiveJob::Serializersから不要なincludeextendを削除しています。


Merge pull request #33208 from utilum/bump_sprockets

Gemfile.lockの修正です。

sprocketsのバージョンを3.7.2に更新しています。

rails commit log流し読み(2018/07/02)

2018/07/02分のコミットです。

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


Merge pull request #32706 from yhirano55/fix-app-update-when-hyphenated-name-is-given

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

AppGenerator#app_nameメソッドでアプリ名を生成する際に、-_に変換しています。

-はDBの設定ファイルに使えない等の問題がある、かつ、生成済みのアプリケーションからアプリ名を生成する際に-を正しく扱えない、等の問題があった為。


fix error of a file name

rails guideのThe Rails Initialization Processの修正です。

railties/exe/railsの項で、説明しているファイル名をタイポしている箇所があったのを修正しています。

rails commit log流し読み(2018/07/01)

2018/07/01分のコミットです。

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

activejob/CHANGELOG.md


Allow queue option to assert_no_enqueued_jobs

activejob/lib/active_job/test_helper.rbの修正です。

assert_no_enqueued_jobsメソッドのqueueオプションを指定出来るよう修正しています。


Fix assignment of TESTOPTS in railties test task

railties/Rakefileの修正です。

railtiesのテストでテスト実行時にTESTOPTSにオプションを複数指定した場合に、オプションが正しく使用されないバグがあったのを修正しています。


Refactor #33254.

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

RedisCacheStore#increment#decrementメソッドそれぞれで行っていたexpiryの書き込み処理のメソッドへの切り出し、optonsに不正な値が指定された場合の処理の削除、等のリファクタリングを行っています。


Revert "Merge pull request #33234 from alpaca-tc/autoload_activejob_arguments"

ActiveJob::Argumentsをautoloadするよう修正した、Merge pull request #33234 from alpaca-tc/autoload_activejob_argumentsをrevertしています。

単体で実行した場合にエラーになってしまうテストが発生してしまった為。

rails commit log流し読み(2018/06/30)

2018/06/30分のコミットです。

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


Remove erroneous remove_column option from example

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

remove_columnメソッドのexampleで指定出来ないindexオプションを使用している箇所があったのを削除しています。


Clarify activejob/lib/active_job/test_helper.rb

activejob/lib/active_job/test_helper.rbactivejob/test/cases/test_helper_test.rbの修正です。

assert_enqueued_withメソッドにatオプションを指定した場合のテストを追加、及び、テスト名や変数名をより適切な名前に修正、等を行っています。


Fix Cache :redis_store increment/decrement ttl check and add more tests.

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

RedisCacheStoreincrement / decrementメソッドでttlメソッドの戻り値のチェックに誤りがあったのを修正しています。

             redis.with do |c|
               val = c.incrby key, amount
-              if expires_in > 0 && c.ttl(key) == -2
+              if expires_in > 0 && c.ttl(key) < 0
                 c.expire key, expires_in
               end

ttlメソッドはkeyが存在しないときは-2で、keyが存在する、かつ、有効期限が無い場合は-1を返すようになっており、-1の場合もexpireを呼ぶ必要がある為、上記のように0未満かどうかをチェックするよう修正を行っています。

参考:https://github.com/redis/redis-rb/blob/ddf058bfa03d8cdde492adeb59930dea831466e2/lib/redis.rb#L413-L429


Fix Ruby warnings tickled by the test suite

各テストでRubyのwarningが出ていた箇所があったのをまとめて修正しています。

rails commit log流し読み(2018/06/29)

2018/06/29分のコミットです。

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

activesupport/CHANGELOG.md

actionmailer/CHANGELOG.md

activejob/CHANGELOG.md


Tweak Previewer::PopplerPDFPreviewer#pdftoppm_exists?

activestorage/lib/active_storage/previewer/poppler_pdf_previewer.rbの修正です。

Previewer::PopplerPDFPreviewer#pdftoppm_exists?メソッドで@pdftoppm_existsが定義されているかをチェックするのに、nil?メソッドを使用していたのを、defined?を使用するよ修正しています。

@pdftoppm_existsは初期化がされていない為、nil?でチェックするとRubyのwarning(instance variable @pdftoppm_exists not initialized)が表示されてしまう為。


Add :expires_in option support for RedisCacheStore increment/decrement method.

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

RedisCacheStoreincrement / decrementメソッドにexpires_inオプションを指定出来るよう修正しています。

指定されたcounterが存在しない時(新規に作成したcounterの場合)のみ、expires_inオプションに指定された値がRedis EXPIREとして指定されるようになっています。


Incompatibility of Direct Uploads & Mirror Service

rails guideのActive Storage Overviewの修正です。

Mirror Serviceの項に、Mirror Serviceを指定している場合Direct Uploadsは使えない旨注記を追加しています。


Merge pull request #33238 from dikond/explicit_action_mailer_deliver_later_queue_name

rails guideのAction Mailer Basicsの修正です。

Calling the Mailerの項に、Action Mailerがデフォルトで使用するqueueについての説明、及び、そのqueueを変更する方法についての説明を追加しています。


Allow call assert_enqueued_with and assert_enqueued_email_with with no block

activejob/lib/active_job/test_helper.rbの修正です。

assert_enqueued_email_withassert_enqueued_withメソッドが、blockを指定しないでも正しく動作するよう修正しています。

Fix ActionMailer assert_enqueued_email_withの対応と異なり、blockの指定が無い場合はenqueueされているjobを即座に取得するようにし、assertionが通るように対応しています。


Fix docs of assert_no_emails [ci skip]

actionmailer/lib/action_mailer/test_helper.rbのdocの修正です。

assert_no_emailsのdoc内、assert_no_emailsがショートカットとなるメソッドについて説明している箇所で、引数の指定が不足していたのを修正しています。