From ace357187ca2a77c7f46451013863e1c77103038 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 10 Apr 2014 22:22:33 +0200 Subject: [PATCH] Well, 2 letter usernames are fine too --- app/models/user.rb | 4 ++-- spec/models/user_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ff07836..ed64477 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,6 @@ class User < ActiveRecord::Base - USERNAME_FORMAT = /\A[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\z/ + USERNAME_FORMAT = /\A[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]\z/ has_many :api_tokens, :dependent => :destroy has_many :asciicasts, :dependent => :destroy @@ -13,7 +13,7 @@ class User < ActiveRecord::Base validates :username, presence: true validates :username, uniqueness: { scope: :dummy, case_sensitive: false }, format: { with: USERNAME_FORMAT }, - length: { minimum: 3, maximum: 16 }, + length: { minimum: 2, maximum: 16 }, unless: :dummy validates :email, presence: true, uniqueness: true, unless: :dummy diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 826f702..32d6d25 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -51,13 +51,13 @@ describe User do it { should allow_value('sickill').for(:username) } it { should allow_value('sick-ill').for(:username) } - it { should allow_value('abc').for(:username) } + it { should allow_value('ab').for(:username) } it { should allow_value('s' * 16).for(:username) } it { should allow_value('Sickill').for(:username) } it { should_not allow_value('sick.ill').for(:username) } it { should_not allow_value('-sickill').for(:username) } it { should_not allow_value('sickill-').for(:username) } - it { should_not allow_value('ab').for(:username) } + it { should_not allow_value('a').for(:username) } it { should_not allow_value('s' * 17).for(:username) } it "checks username uniqueness" do