なるようになるブログ

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

rails commit log流し読み(2017/10/16)

2017/10/16分のコミットです。

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


Add a test case that eager-loading with a polymorphic association and using exists?

activerecord/test/cases/associations/eager_test.rbの修正です。

polymorphic associationをeager load + exists?メソッドを使用した場合のテストを追加しています。


Merge pull request #30872 from yhirano55/capitalize_sprockets_in_engine_guide

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

sprockets -> Sprockets(先頭を大文字)に修正しています。


Merge pull request #30862 from yhirano55/remove_needless_space_in_action_view_guide

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

time_zone_selectメソッドのexampleコードに不要なスペースがあったのを削除しています。


Remove extra spaces in the args in the time_zone_select [ci skip]

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

time_zone_selectメソッドのdoc内のexampleコードに不要なスペースがあったのを削除しています。


Remove association(true) references from docs [ci skip]

activerecord/lib/active_record/associations.rbactiverecord/lib/active_record/associations/collection_proxy.rbのdocの修正です。

docに既に存在しないassociation(true)メソッドを使用している箇所があったのを削除、及び、reloadメソッドを使用するよう修正しています。

rails commit log流し読み(2017/10/15)

2017/10/15分のコミットです。

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

activerecord/CHANGELOG.md


Add accept-charset to the output of form_with in JS guide [ci skip]

rails guideのWorking with JavaScript in Railsの修正です。

form_withメソッドの実行例が実際の結果と異なっていた(accept-charsetが不足していた)のを修正しています。


Remove unused before_filters

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

使用していないbefore_filtersメソッドを削除しています。


MySQL: Don't lose auto_increment: true in the db/schema.rb

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

migrationファイルでauto_increment オプションを明示的に指定した場合に、その指定がschema.rbに反映されないバグがあったのを修正しています。


Merge pull request #30860 from olimart/patch-1

Gemfileの修正です。

Active Storageで使用するgemを指定している箇所にActive Storage用であるというコメントを追加しています。


Fix longer sequence name detection for serial columns (#28339)

Active Recordの修正です。

PostgreSQL adapterで、serial columnss用のsequence nameを生成する際に、max lengthを考慮するよう修正しています。

現状、max lengh(63文字)のチェックが行われておらず、テーブル名に長い名前が指定された場合にエラーになってしまうため。

rails commit log流し読み(2017/10/14)

2017/10/14分のコミットです。

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

activerecord/CHANGELOG.md


Define path with dir in activestorage/

Active Storageのテストの修正です。

相対パスでファイルを取得するのに__FILE__を使用していたのを__dir__を使用するよう修正しています。不要な".."を削除出来るようにする為。


Use require_relative instead of require with full path in activestorage/

activestorage/test/test_helper.rbの修正です。

envファイルをロードするのにrequire + File.expand_pathを使用していたのを、require_relativeを使用するよう修正しています。


Merge pull request #30885 from yhirano55/add_action_cable_notifications_to_instrument_guide

rails guideのActive Support Instrumentationの修正です。

`Action Cableのセクションを追加し、Action Cableのhooksについての説明を追加しています


Merge pull request #30883 from PHedkvist/add_daemon_command_test

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

rails serverコマンドにdaemonオプションを指定した場合のテストを追加しています。


Merge pull request #30877 from y-yagi/remove_jquery-rails

Gemfileの修正です。

使用していないjquery-railsを削除しています。


Fix test name for daemon option test

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

rails serverコマンドにdaemonオプションを指定した場合のテストのテスト名が、テスト内容と異なる名前になっていたのを修正しています。


Add unpermitted_parameters.action_controller hook to instrument guide [ci skip]

rails guideのActive Support Instrumentationの修正です。

unpermitted_parameters.action_controller hookについての説明を追加しています。


Show the failed queries in test_has_one_does_not_use_order_by

activerecord/test/cases/associations/has_one_associations_test.rbの修正です。

has_one associationでorder byが使用されない事を確認するテストで、テストが失敗した際に発行されたSQLを表示するよう修正しています。

このテストがCIで時折エラーになってしまい、その調査の為に表示するようにしたようです。


Fix COUNT(DISTINCT ...) for GROUP BY with ORDER BY and LIMIT

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

DISTINCT + COUNT + ORDER BY + LIMIT + GROUP BY を実行した場合に、不正なSQLが生成されてしまいエラーになってしまうバグがあったのを修正しています。

# before
User.group(:id).distinct.order(updated_at: :desc).limit(10).count
# => SELECT  COUNT(DISTINCT *) AS count_all, "users"."id" AS users_id FROM "users" GROUP BY "users"."id" ORDER BY "users"."updated_at" DESC LIMIT ?  [["LIMIT", 10]]
# => ActiveRecord::StatementInvalid: SQLite3::SQLException: near "*": syntax error: SELECT  COUNT(DISTINCT *) AS count_all, "users"."id" AS users_id FROM "users" GROUP BY "users"."id" ORDER BY "users"."updated_at" DESC LIMIT ?

# after
User.group(:id).distinct.order(updated_at: :desc).limit(10).count
# => SELECT  COUNT(DISTINCT "users"."id") AS count_id, "users"."id" AS users_id FROM "users" GROUP BY "users"."id" ORDER BY "users"."updated_at" DESC LIMIT ?  [["LIMIT", 10]]

rails commit log流し読み(2017/10/13)

2017/10/13分のコミットです。

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


Introduce ActiveStorage::Blob#representation

activestorage/app/models/active_storage/blob.rbactivestorage/app/models/active_storage/variant.rbの修正です。

ActiveStorage::BlobActiveStorage::Previewインスタンスを返す為のrepresentationメソッドを追加しています。

blobがpreview可能なデータの場合blobを、そうじゃない場合はActiveStorage::Variantインスタンスを返します。どちらも駄目な場合はエラー(UnrepresentableError)。


Accept variation keys in #preview and #variant

activestorage/app/models/active_storage/blob.rbactivestorage/app/models/active_storage/variation.rbの修正です。

ActiveStorage::Blob#variantメソッド及び#previewメソッドにvariation keysを指定出来るよう修正しています。


Bump RuboCop 0.50.0

.codeclimate.ymlGemfile.lockの修正です。

RuboCopのバージョンを0.50.0に更新、及び、Code ClimateでRuboCop 0.50.0を使用するよう修正しています。


Merge pull request #30750 from k2nr/fix-active-job

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

retry_onメソッドにblockを指定した際に、blockの第二引数にエラーのclassが渡されていたのを、インスタンスを渡すよう修正しています。


Clarify comment [ci skip]

activestorage/app/models/active_storage/variant.rbのdocの修正です。

ActiveStorage::Variant#imageメソッドのコメント内、戻り値についての言い回しを修正しています。


Add process.action_mailer notification to Instrumentation guide [ci skip]

rails guideのActive Support Instrumentationの修正です。

process.action_mailer hookについての説明を追加しています。

rails commit log流し読み(2017/10/12)

2017/10/12分のコミットです。

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


Fix "warning: assigned but unused variable - message"

railties/test/generators/argv_scrubber_test.rbの修正です。

test_rc_whitespace_separatedから使用していない変数を削除しています。


[ci skip]Enable link to ActionDispatch::Integration::Session#process in rdoc

actionpack/lib/action_dispatch/testing/integration.rbのdocの修正です。

Integration::RequestHelpers module配下のHTTP method用のメソッド(getpostpatch等)のdocでActionDispatch::Integration::Session#processメソッドへのリンクを追加しています。


fix the description for the select_all [ci skip]

rails guideのActive Record Query Interfaceの修正です。

select_allメソッドについて説明している箇所に、select_allメソッドの戻り値について詳細な説明を追加しています。

rails commit log流し読み(2017/10/11)

2017/10/11分のコミットです。

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


Add allow_other_host option to redirect_back method

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

redirect_backメソッドに、異なるhostへのredirectを許容するかどうかを指定するためのallow_other_hostオプションを追加しています。

allow_other_hostにfalseを指定した場合、異なるhostへのredirectはおこなわれません(Referer header又はfallback_locationオプションで指定したパスに転送される)。


Fix some typos.

各doc内のタイポをまとめて修正しています。

rails commit log流し読み(2017/10/10)

2017/10/10分のコミットです。

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


Merge pull request #30798 from bogdanvlviv/express-change_column_comment-as-public-api

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

change_column_commentメソッドをpublic APIにしています。通常ユーザが使用するメソッドの為。


Merge pull request #30832 from y-yagi/simplify_console_test

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

ConsoleTest#parse_argumentsメソッドで引数のparse処理にConsoleCommandクラスを使用するようリファクタしています。


Merge pull request #30836 from shioyama/generated_attribute_methods_include_mutex

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

GeneratedAttributeMethodsインスタンスMutex_mをextendしていたのを、クラスに対してincludeするよう修正しています。

-    class GeneratedAttributeMethods < Module; end # :nodoc:
+    class GeneratedAttributeMethods < Module #:nodoc:
+      include Mutex_m
+    end

     module ClassMethods
       def inherited(child_class) #:nodoc:
@@ -42,7 +44,7 @@ def inherited(child_class) #:nodoc:
       end

       def initialize_generated_modules # :nodoc:
-        @generated_attribute_methods = GeneratedAttributeMethods.new { extend Mutex_m }
+        @generated_attribute_methods = GeneratedAttributeMethods.new

ancestorsメソッドの結果にGeneratedAttributeMethodsが正しく表示されるようにする為、との事です。

# before
User.ancestors

# => [User(id: integer, name: string, email: string, created_at: datetime, updated_at: datetime), User::GeneratedAssociationMethods, #<#<Class:0x00560456dc2f20>:0x00560456dc3100>, ApplicationRecord(abstract), ApplicationRecord::GeneratedAssociationMethods, #<#<Class:0x00560456df1190>:0x00560456df1348>, ActiveRecord::Base, GlobalID::Identification, ActiveRecord::Suppressor, ActiveRecord::SecureToken, ActiveRecord::Store, ActiveRecord::Serialization, ActiveModel::Serializers::JSON, ActiveModel::Serialization, ActiveRecord::Reflection, ActiveRecord::NoTouching, ActiveRecord::TouchLater, ActiveRecord::Transactions, ActiveRecord::Aggregations, ActiveRecord::NestedAttributes, ActiveRecord::AutosaveAssociation, ActiveModel::SecurePassword, ActiveRecord::Associations, ActiveRecord::Timestamp, ActiveRecord::Callbacks, ActiveRecord::AttributeMethods::Serialization, ActiveRecord::AttributeMethods::Dirty, ActiveModel::Dirty, ActiveRecord::AttributeMethods::TimeZoneConversion, ActiveRecord::AttributeMethods::PrimaryKey, ActiveRecord::AttributeMethods::Query, ActiveRecord::AttributeMethods::BeforeTypeCast, ActiveRecord::AttributeMethods::Write, ActiveRecord::AttributeMethods::Read, ActiveRecord::Base::GeneratedAssociationMethods, #<#<Class:0x00560455f92888>:0x00560455f92a18>, ActiveRecord::AttributeMethods, ActiveModel::AttributeMethods, ActiveModel::Validations::Callbacks, ActiveRecord::DefineCallbacks, ActiveRecord::Locking::Pessimistic, ActiveRecord::Locking::Optimistic, ActiveRecord::AttributeDecorators, ActiveRecord::Attributes, ActiveRecord::CounterCache, ActiveRecord::Validations, ActiveModel::Validations::HelperMethods, ActiveSupport::Callbacks, ActiveModel::Validations, ActiveRecord::Integration, ActiveModel::Conversion, ActiveRecord::AttributeAssignment, ActiveModel::AttributeAssignment, ActiveModel::ForbiddenAttributesProtection, #<Module:0x00560456dc0298>, ActiveRecord::Sanitization, ActiveRecord::Scoping::Named, ActiveRecord::Scoping::Default, ActiveRecord::Scoping, ActiveRecord::Inheritance, ActiveRecord::ModelSchema, ActiveRecord::ReadonlyAttributes, ActiveRecord::Persistence, ActiveRecord::Core, ActiveSupport::ToJsonWithActiveSupportEncoder, Object, PP::ObjectMixin, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Tryable, ActiveSupport::Dependencies::Loadable, Kernel, BasicObject]
# after
User.ancestors

# => [User(id: integer, name: string, email: string, created_at: datetime, updated_at: datetime), User::GeneratedAssociationMethods, #<ActiveRecord::AttributeMethods::GeneratedAttributeMethods:0x007f8c100b1348>, ApplicationRecord(abstract), ApplicationRecord::GeneratedAssociationMethods, #<ActiveRecord::AttributeMethods::GeneratedAttributeMethods:0x007f8c100b3120>, ActiveRecord::Base, GlobalID::Identification, ActiveRecord::Suppressor, ActiveRecord::SecureToken, ActiveRecord::Store, ActiveRecord::Serialization, ActiveModel::Serializers::JSON, ActiveModel::Serialization, ActiveRecord::Reflection, ActiveRecord::NoTouching, ActiveRecord::TouchLater, ActiveRecord::Transactions, ActiveRecord::Aggregations, ActiveRecord::NestedAttributes, ActiveRecord::AutosaveAssociation, ActiveModel::SecurePassword, ActiveRecord::Associations, ActiveRecord::Timestamp, ActiveRecord::Callbacks, ActiveRecord::AttributeMethods::Serialization, ActiveRecord::AttributeMethods::Dirty, ActiveModel::Dirty, ActiveRecord::AttributeMethods::TimeZoneConversion, ActiveRecord::AttributeMethods::PrimaryKey, ActiveRecord::AttributeMethods::Query, ActiveRecord::AttributeMethods::BeforeTypeCast, ActiveRecord::AttributeMethods::Write, ActiveRecord::AttributeMethods::Read, ActiveRecord::Base::GeneratedAssociationMethods, #<ActiveRecord::AttributeMethods::GeneratedAttributeMethods:0x005622995ceb00>, ActiveRecord::AttributeMethods, ActiveModel::AttributeMethods, ActiveModel::Validations::Callbacks, ActiveRecord::DefineCallbacks, ActiveRecord::Locking::Pessimistic, ActiveRecord::Locking::Optimistic, ActiveRecord::AttributeDecorators, ActiveRecord::Attributes, ActiveRecord::CounterCache, ActiveRecord::Validations, ActiveModel::Validations::HelperMethods, ActiveSupport::Callbacks, ActiveModel::Validations, ActiveRecord::Integration, ActiveModel::Conversion, ActiveRecord::AttributeAssignment, ActiveModel::AttributeAssignment, ActiveModel::ForbiddenAttributesProtection, #<Module:0x00562298182098>, ActiveRecord::Sanitization, ActiveRecord::Scoping::Named, ActiveRecord::Scoping::Default, ActiveRecord::Scoping, ActiveRecord::Inheritance, ActiveRecord::ModelSchema, ActiveRecord::ReadonlyAttributes, ActiveRecord::Persistence, ActiveRecord::Core, ActiveSupport::ToJsonWithActiveSupportEncoder, Object, PP::ObjectMixin, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Tryable, ActiveSupport::Dependencies::Loadable, Kernel, BasicObject]

これで変わるんですねえ。


Merge pull request #30595 from bogdanvlviv/use-railties-rails-command

railtiesのテストの修正です。

  • 不要な Dir.chdirを削除
  • db:test:prepareのテストから不要なRAILS_ENVの設定処理を削除
  • helperファイル生成のテストで、railsメソッドを使用するよう修正

等を行っています。


Update security guide for signed cookie rotations

actionpack/test/dispatch/cookies_test.rb、及び、rails guideのRuby on Rails Security Guideの修正です。

signed cookieのdigestをrotateする場合のテストを追加、及び、guideのRotating Encrypted and Signed Cookies Configurationsの項に説明を追加しています。


Fix documentation [ci skip]

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

ActiveSupport::MessageEncryptorクラスのdoc内のexampleコードで、変数名が誤っていたのを修正しています。