0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

管理者のテストが期待通りにならない理由

Last updated at Posted at 2020-01-12

Rails Tutoriaiの第10章、10.4.1演習において

users_controller.rb
def user_params
  params.require(:user).permit(:name, :email, :password,
                               :password_confirmation, :admin)
end

というコードに対して

users_controller_test.rb
test "should not allow the admin attribute to be edited via the web" do
  log_in_as(@other_user)
  assert_not @other_user.admin?
  patch user_path(@other_user), params: { 
                                  user: { password: @other_user.password,
                                          password_confirmation: @other_user.password 
                                          admin: true } }
  assert_not @other_user.reload.admin?
end

というテストを書きました。

テスト結果はREDになるはずですが、
GREENになってしまします。

なぜこうなってしまうのでしょうか。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?