vendredi 3 novembre 2017

Why is the rails password validation not catching too short a password?

I want the password to have a minimum length of 5 characters. My test file with regard to the passwords are as follows.

    test "password should be present (nonblank)" do
        @user.password = @user.password_confirmation = " " * 6
        assert_not @user.valid?
    end

    test "password should have a minimum length" do
        @user.password = @user.password_confirmation = "a" * 5
        assert_not @user.valid?
    end

My user model has

    validates :password, presence: true, length: { minimum: 6 }

But on the rails console --sandbox, when I create a user with a password of "a" and then try to validate it with user.valid?, it still returns true. Am I missing something here?

Aucun commentaire:

Enregistrer un commentaire