0

In the config of Devise I have the password min length to be 8.

# config/initializers/devise.rb

config.password_length = 8..128

However, my rspec test passes when a password 4 characters:

u = User.new({
  password: "test",
  # ....
})

expect(u).to be_valid
Rattiku
  • 177
  • 2
  • 11
  • I always use shoulda for testing validations, `it { should ensure_length_of(:password).is_at_least(size_of_password) }` – Kedarnag Mukanahallipatna Aug 27 '18 at 02:06
  • 1
    have you checked https://stackoverflow.com/questions/41836736/rails-5-devise-minimum-password-length-not-working ? – fabdurso Aug 27 '18 at 09:01
  • Possible duplicate of [Testing password length validation with RSpec](https://stackoverflow.com/questions/13111328/testing-password-length-validation-with-rspec) – fabdurso Aug 27 '18 at 09:03

1 Answers1

0

If you don't want to use shoulda, can you try doing this

describe User do
  it "should validate the length of password" do
    FactoryGirl.build(:user, password: "aaaaa").should_not be_valid
  end
end

or if you want to use shoulda

it { should ensure_length_of(:password).is_at_least(8) }

and if you want to check for max length,

it { should ensure_length_of(:password).is_at_most(18) }