Allow capital letters in usernames

This commit is contained in:
Marcin Kulik 2014-04-10 22:14:20 +02:00
parent 698767ad82
commit a6bb7bf5ba
2 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
USERNAME_FORMAT = /\A[a-z0-9][a-z0-9-]+[a-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 :api_tokens, :dependent => :destroy
has_many :asciicasts, :dependent => :destroy has_many :asciicasts, :dependent => :destroy
@ -11,7 +11,7 @@ class User < ActiveRecord::Base
has_many :comments, :dependent => :destroy has_many :comments, :dependent => :destroy
validates :username, presence: true validates :username, presence: true
validates :username, uniqueness: { scope: :dummy }, validates :username, uniqueness: { scope: :dummy, case_sensitive: false },
format: { with: USERNAME_FORMAT }, format: { with: USERNAME_FORMAT },
length: { minimum: 3, maximum: 16 }, length: { minimum: 3, maximum: 16 },
unless: :dummy unless: :dummy

View File

@ -15,7 +15,7 @@ describe User do
end end
describe "#valid?" do describe "#valid?" do
let!(:existing_user) { create(:user) } let!(:existing_user) { create(:user, username: 'the-user-name') }
let(:user) { described_class.new } let(:user) { described_class.new }
it { should validate_presence_of(:username) } it { should validate_presence_of(:username) }
@ -53,7 +53,7 @@ describe User do
it { should allow_value('sick-ill').for(:username) } it { should allow_value('sick-ill').for(:username) }
it { should allow_value('abc').for(:username) } it { should allow_value('abc').for(:username) }
it { should allow_value('s' * 16).for(:username) } it { should allow_value('s' * 16).for(:username) }
it { should_not allow_value('Sickill').for(:username) } it { should allow_value('Sickill').for(:username) }
it { should_not allow_value('sick.ill').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('sickill-').for(:username) } it { should_not allow_value('sickill-').for(:username) }
@ -61,7 +61,7 @@ describe User do
it { should_not allow_value('s' * 17).for(:username) } it { should_not allow_value('s' * 17).for(:username) }
it "checks username uniqueness" do it "checks username uniqueness" do
user.username = existing_user.username user.username = 'The-User-Name'
user.valid? user.valid?
expect(user.errors[:username]).to_not be_empty expect(user.errors[:username]).to_not be_empty
end end