くりにっき

フルスタックキュアエンジニアです

Rails 4.0.4でActionController::Parametersの挙動が微妙に変わってた

GitpeachRails 4.0.4に上げようとした時にテストがこけて2時間くらいハマってたのでメモ

{
  id: "xxxx/yyyy",
  labels: [
    {name: "Backlog"    , gitlab_label: nil          , is_backlog_issue: true , is_close_issue: false, id: 1},
    {name: "Ready"      , gitlab_label: "ready"      , is_backlog_issue: false, is_close_issue: false, id: 2},
    {name: "In Progress", gitlab_label: "in progress", is_backlog_issue: false, is_close_issue: false, id: 3},
    {name: "Done"       , gitlab_label: nil          , is_backlog_issue: false, is_close_issue: true , id: 4},
  ]
}

上記のようなparamsがあった時に、Arrayの中のHashに対しても ActionController::Parameters#permit が必須になった模様。(4.0.3まではチェックされなかった)

関連するリリースノート

https://github.com/rails/rails/blob/v4.0.4/actionpack/CHANGELOG.md

Converts hashes in arrays of unfiltered params to unpermitted params.

実際の修正

params.permit(labels: [:name, :gitlab_label, :is_backlog_issue, :is_close_issue, :disp_order, :id])

https://github.com/sue445/gitpeach/pull/6/files

まとめ

  • リリースノート読め
  • こまめなアップデート大事
  • テスト大事