なるようになるブログ

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

rails commit log流し読み(2014/12/31)

2014/12/31分のコミットです。

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

actionpack/CHANGELOG.md

activerecord/CHANGELOG.md

activejob/CHANGELOG.md


Remove single space response body for head request

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

headメソッドを使用した際に、response bodyにシングルスペースを出力していたのを、シングルスペースを含まないよう修正しています。

元々、Safariのバグの対策の為にシングルスペースを出力していたのですが、現状問題無いとの事で削除しています。同様の対応が以前renderメソッドでは行われていたのですが、headの方は対応が漏れてしまっていたようです。


ActiveJob testing improvements

ActiveJobの修正です。

  1. Test用のadapterがserialize/deserialize処理を行ってたのを行うよう修正
  2. ActiveJobの標準のテストでTest用のAdapterを使うよう修正
  3. activejob/lib/active_job/test_helper.rbに'active_support/core_ext/hash/keys'を追加

を行っています。


Merge pull request #18130 from claudiob/better-record-identifier-doc

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

ActionView::RecordIdentifiermoduleのexample、説明の追加を行っています。


Use more semantic method to check password

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

authenticateメソッドでパスワードのチェック処理にis_password?メソッドを使うよう修正しています。


Tiny documentation fixes [ci skip]

actionview/lib/action_view/record_identifier.rbactiverecord/lib/active_record/locking/optimistic.rbのdocの修正です。

typoの修正、説明に改行の追加等を行っています。


Fix description for application_name method - change simple to simply

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

simple -> simplyに修正しています。


Remove this line which was added by accident [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

誤って追加してしまった行を削除しています。


Ensures that primary_key method will return nil when multi-pk

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

複数主キーを使用している場合、primary_keyメソッドnilを返すよう修正しています。


Replace exhaustive list of helper methods with pointers to helper classes found

rails guideのA Guide to Testing Rails Applicationsの修正です。

integration test用のhelperメソッドの一覧が記載されていたのを削除し、各API docへのリンクを追加しています。


Add implement integration test to Testing Guide. [ci skip]

Implementing an integration testセクションを追加しています。

integration testのgenerateから実際のテストコードの作成までの一連の説明について記載しています。


Update CHANGELOG entry for #18070 [ci skip]

activerecord/CHANGELOG.mdの修正です。先に行われたprimary_keyメソッドの対応の説明を改善しています。


Make "Testing Views" separate section, move "Setup and Teardown" into

rails guideのA Guide to Testing Rails Applicationsの修正です。

setup/teardownの説明をfunctional testingセクションに移動しています。


Move request tests after functional and before views, and move helper tests

rails guideのA Guide to Testing Rails Applicationsの修正です。

Testing Routesセクションをfunctionalテストについての説明の後ろに、Testing helpersセクションをTesting Viewsセクションの後ろに、それぞれ移動しています。


Add result of running articles_routes_test and point to more information for

rails guideのA Guide to Testing Rails Applicationsの修正です。

controllerテストのexampleの実行結果の追加、及びActionDispatch::Assertions::RoutingAssertionsAPI docへのリンクを追加しています。


Replace exhaustive list of methods with pointer to API docs. [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

ActiveJobのテスト用ヘルパーメソッドの一覧が記載されていたのを削除し、API docへのリンクを追加しています。


The Guide to Testing Rails Applications is published! :tada: :tada: [ci skip]

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

A Guide to Testing Rails Applicationsからwork_in_progress: trueを削除、及びdescriptionの修正を行っています。これで正式にTesting Guideが公開状態になっています。


Fix comment typo in debugger.rb

activesupport/lib/active_support/core_ext/kernel/debugger.rbの修正です。

debuggerメソッドのコメントにあったタイポを修正しています。


Fixes simple missprint in docs for #cyle in text_helper

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

simple_formatメソッドのexampleに誤りがあったのを修正しています。


Move Engines guide under Extending Rails [ci skip]

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

Getting Started with EnginesguideをCreating and Customizing Rails Generatorsguideの下に移動しています。


Merge pull request #17680 from larskanis/fix_bytea_change_detection

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

Bytea#type_cast_from_databaseの引数に渡された値がType::Binary::Dataクラスだった場合、PGconn.unescape_byteaを行わないよう修正しています。

pg gemの0.18.0側の挙動変更に合わせての対応との事です。


Raise a better exception for renaming long indexes for mysql adapters

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

MySQL adapterで、名前が長すぎてindex名の変更に失敗した場合のエラーメッセージを、より分り易い内容に修正しています。


Share foreign_key_present? implementation in has associations

ActiveRecordのassociationsの修正です。

HasOneAssociationクラスでforeign_key_present?メソッドを使用出来るよう修正しています。

foreign_key_present?が呼び出せない事で、has_one associationとhas_many associationで挙動が異なってしまった箇所があったので修正したとの事です。以下サンプル。

class User < ActiveRecord::Base
  has_one :review
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :user
end

class Review < ActiveRecord::Base
  belongs_to :user
end

user = User.create!
user.posts << Post.create!
user.review = Review.create!

# This queries the database
User.new(id: user.id).posts  # => [Post<id: 1>]

# This does not query the database
User.new(id: user.id).review # => nil

use methods on the request rather than direct hash access

actionpack/lib/action_controller/metal/url_for.rbactionpack/lib/action_dispatch/http/request.rbの修正です。

env Hashから値を取得していたのを、requestメソッドを使用するよう修正しています。


stop referencing env in url_for

actionpack/lib/action_controller/metal/url_for.rbactionpack/lib/action_dispatch/http/request.rbの修正です。

url_forメソッドenv Hashから値を取得していたのを、requestオブジェクトのメソッドを使用するよう修正しています。


ActiveJob: delegate full deserialization to class

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

ActiveJob::Base.deserializeメソッド内で行っていたdeserialize処理をjob classにdelegateするよう修正しています。

これにより、Job Dataのdeserialize時に任意の処理を行えるようになりました。以下例。

class DeliverWebhookJob < ActiveJob::Base
  def serialize
    super.merge('attempt_number' => (@attempt_number || 0) + 1)
  end

  def deserialize(job_data)
    super(job_data)
    @attempt_number = job_data['attempt_number']
  end

  rescue_from(TimeoutError) do |ex|
    raise ex if @attempt_number > 5
    retry_job(wait: 10)
  end
end

これは割と便利そうですねえ。


Fix error message when trying to create an associated record

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

association recordを作成しようとした際に、外部キーが見つからなかった場合のエラーメッセージを修正しています。

# before
NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>

# afer
ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.

Extract the index length validation to a auxiliar method

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

index長をチェックするメソッド(validate_index_length!)を新規に作成し、rename_indexメソッドでそのメソッドを使用するよう修正しています。


Add Profiling guide skeleton [ci skip] i guides/source/documents.yamlguides/source/profiling.mdの修正です。

Profiling Rails Applications guideのスケルトンを作成しています。楽しみ。


Update Getting Started guide to reflect foreign key in migration [ci skip]

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

Adding a Second Modelセクションのexampleにforeign keyのマイグレーションを追加しています。


ActiveJob is not ActionJob [ci skip] :smile:

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

"ActionJob" -> "ActiveJob"にタイポの修正をしています。


Fix spell life cycle on activejob docs [ ci skip]

activejob/lib/active_job/callbacks.rb、 `guides/source/active_job_basics.mdの修正です。

"lifecycle" -> "life cycle"にタイポの修正をしています。


fix rake command typo in Testing guide [ci skip]

rails guideのA Guide to Testing Rails Applicationsの修正です。

rake コマンドをタイポしている箇所があったのを修正しています。