なるようになるブログ

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

rails commit log流し読み(2015/06/23)

2015/06/23分のコミットです。

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

activerecord/CHANGELOG.md


Remove mistaken end from controller_path doc [ci skip]

actionpack/lib/abstract_controller/base.rbのdocの修正です。

AbstractController::Baseのexampleに不要なendがあったのを削除しています。


Minor fixes [ci skip]

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

Single Table Inheritanceの項にあるexampleのメソッド呼び出しに()を追加、及び生成されるSQLが実際のSQLと異なっていたのを修正していmす。


Add nodoc to the Validations::Helpers [ci skip]

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

Validations::HelperMethods moduleにnodocを追加しています。


Merge pull request #19431 from hmarr/head-routing

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

HEAD リクエストの場合に、routingが正しくマッチしないバグがあったのを修正しています。

# routes.rb
get 'is-alive-token' => 'heart_beat#index'

# controller
class HeartBeatController < ApplicationController
  def index
    render json: {}, status: 200
  end
end

上記のようなファイルがあった際にcurl -I http://127.0.0.1:3000/is-alive-tokenをした場合、ActionController::RoutingError (No route matches [HEAD] "/is-alive-token")のエラーが発生してしまうリグレッションがRails 4.2にあり、その修正の為の対応を行っています。

Explicitly ignored wildcard verbs from head_routes by tsun1215 · Pull Request #18764 · rails/rails のPRで一度対応が行われたのですが、GETメソッドに対する考慮が足りていないという理由でrevertされてしまっており、再度の対応になります。


do not show "Failed tests" message when a failed test is not

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

rails test実行時、失敗したテストは無いかつスキップしたテストがあった場合に、Failed testsというメッセージが表示されてしまっていたのを、表示されないよう修正しています。


Merge pull request #20545 from dcrec1/20541

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

associationを使用している際、そのassociationに指定しているクラスと違うクラスを指定した場合、通常ActiveRecord::AssociationTypeMismatchクラスがraiseされるのですが、associationnにネームスペースを使用していた場合に、正しくActiveRecord::AssociationTypeMismatchがraiseされないバグがあったのを修正しています。

issueより。

class Wheel < ActiveRecord::Base
  belongs_to :car
end

class Car < ActiveRecord::Base
  has_many :wheels
end

module Namespace
  def self.table_name_prefix
    'namespace_'
  end
end

class Namespace::Teacher < ActiveRecord::Base
  has_many :apples
end

class Namespace::Apple < ActiveRecord::Base
  belongs_to :teacher
end
Namespace::Apple.new(teacher: "hello")
# => `ActiveRecord::AssociationTypeMismatch`になるべきが、`NameError`がおきてしまっていた

Merge pull request #20552 from jamesdabbs/belongs-to-polymorphic-force-reload

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

polymorphic belongs_to association を使用している場合に、force_reloadオプションにtrueを指定した場合に、NoMethodErrorエラーが発生してしまうバグがあったのを修正しています。

issueより。

class Post < ActiveRecord::Base
  has_one :comment, as: :commentable
end

class Comment < ActiveRecord::Base
  belongs_to :commentable, polymorphic: true
end

Comment.new.commentable(force_reload: true) #=> `NoMethodError`

SingularAssociation#readerメソッドでklassのチェック処理漏れがあった為のようで、チェック処理を追加しています。


[ci skip] correct for ActiveRecord::Associations::Preloader:

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

ActiveRecord::Associations::Preloaderクラスのexampleで、正常に動作させるには、カラムが足りてなかったのを修正しています。


docs, add missing closing bracket. [ci skip]

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

ActiveRecord::Associations::Preloaderクラスのexampleで、コードに閉じカッコが足りてない箇所があったのを修正しています。