Add minimum name length for users (#594)

This commit is contained in:
Ben Halpern 2018-07-19 15:36:29 -04:00 committed by GitHub
parent 6f9248c97e
commit b2b1068715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -40,7 +40,7 @@ class User < ApplicationRecord
length: { maximum: 50 },
email: true,
allow_blank: true
validates :name, length: { maximum: 100 }
validates :name, length: { minimum: 1, maximum: 100 }
validates :username,
presence: true,
uniqueness: { case_sensitive: false },

View file

@ -145,6 +145,13 @@ RSpec.describe User, type: :model do
expect(user.old_old_username).to eq(old_username)
end
it "does not allow too short or too long name" do
user.name = ""
expect(user).not_to be_valid
user.name = Faker::Lorem.paragraph_by_chars(200)
expect(user).not_to be_valid
end
it "does not accept invalid employer url" do
user.employer_url = "ben.com"
expect(user).not_to be_valid