From d9b5ea7f88f6940bff23c1d53c3a8e3791b90aeb Mon Sep 17 00:00:00 2001 From: sermoa Date: Tue, 25 Nov 2008 21:40:36 +0000 Subject: [PATCH] Validation of login ID is now case insensitive so no 'test' and 'TEST'. --- app/models/person.rb | 2 +- spec/models/person_spec.rb | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 spec/models/person_spec.rb diff --git a/app/models/person.rb b/app/models/person.rb index 884b3e0..aab507b 100755 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb new file mode 100644 index 0000000..071598a --- /dev/null +++ b/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