LoginSignup
2
2

More than 3 years have passed since last update.

Rails Tutorial7.3.4のテストが通らなかった件。

Last updated at Posted at 2017-01-05

Rails Tutorialも7章まで行きました。
今回は7.3.4のユーザー登録に失敗するテストが通らなかったので書き留めておきます。

概要

Rails Tutorial 7.3.4 失敗時のテスト
教材通りにコードを書いたがテストがエラーになってしまい通らない。

ActionController::ParameterMissing: param is missing or the value is empty: user

原因

postで送るデータの書き方。

assert_no_difference 'User.count' do
  post users_path, params: { user: { name:  "",
                                     email: "user@invalid",
                                     password:              "foo",
                                     password_confirmation: "bar" } }
end

この部分です。説明ではparamsについて

なおRails 4.2以前では、paramsを暗黙的に省略しても (userハッシュのみでも) テストが通りました。Rails 5.0からは非推奨になり、paramsハッシュを明示的に含めることが推奨されています。

となっています。
私の環境はRails4.2.2ですが、どうやらparams[:user]にすると逆にダメなようです。

post users_path, user: { name: "",
                         email: "user@invalid",
                         password: "foo",
                         password_confirmation: "bar" }

に直したところ無事動きました。

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2