Skip to content

Commit

Permalink
Validation of login ID is now case insensitive so no 'test' and 'TEST'.
Browse files Browse the repository at this point in the history
  • Loading branch information
sermoa committed Nov 25, 2008
1 parent f305a1b commit d9b5ea7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/person.rb
Expand Up @@ -607,7 +607,7 @@ def create_code

validates_length_of :login, :within => 3..40
validates_presence_of :login
validates_uniqueness_of :login
validates_uniqueness_of :login, :case_sensitive => false
validates_format_of :login, :with => /^[\w-]+$/, :message => "can only contain letters and numbers"

validates_length_of :password, :within => 5..40
Expand Down
43 changes: 43 additions & 0 deletions spec/models/person_spec.rb
@@ -0,0 +1,43 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Person do

describe "validation of login id" do

before(:each) do
@person = Person.create!(:login => 'test', :name => 'Test',
:password => 'w00t!', :password_confirmation => 'w00t!',
:email => 'test@test.com')
end

it "should allow a new person to be saved" do
@person.errors_on(:login).should == []
end

it "should allow letters and numbers in the login ID" do
person2 = Person.new(:login => '123abc')
person2.errors_on(:login).should == []
end

it "should actually allow underscores and minus characters too" do
person2 = Person.new(:login => '123_ab--c')
person2.errors_on(:login).should == []
end

it "should certainly not allow spaces in the login ID" do
person2 = Person.new(:login => '123 ab -c')
person2.errors_on(:login).should == ['can only contain letters and numbers']
end

it "should not allow another person to be created with the same login ID" do
person2 = Person.new(:login => 'test')
person2.errors_on(:login).should == ['has already been taken']
end

it "should not the same login ID, even if the case is different" do
person2 = Person.new(:login => 'TEST')
person2.errors_on(:login).should == ['has already been taken']
end

end
end

0 comments on commit d9b5ea7

Please sign in to comment.