Issue #446: Adding 32-character length limit to User#username, Profile#first_name, Profile#last_name

This commit is contained in:
Justin Wienckowski 2010-10-28 20:58:39 -07:00
parent f1ae95fac9
commit cdcb693c95
4 changed files with 34 additions and 1 deletions

View file

@ -24,6 +24,8 @@ class Profile
key :bio, String
after_validation :strip_names
validates_length_of :first_name, :maximum => 32
validates_length_of :last_name, :maximum => 32
before_save :strip_names

View file

@ -45,7 +45,8 @@ class User
before_validation :strip_username, :on => :create
validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false
validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/
validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/
validates_length_of :username, :maximum => 32
validates_with InvitedUserValidator
one :person, :class_name => 'Person', :foreign_key => :owner_id

View file

@ -12,6 +12,16 @@ describe Profile do
profile.should be_valid
profile.first_name.should == "Shelly"
end
it "can be 32 characters long" do
profile = Factory.build(:profile, :first_name => "Hexagoooooooooooooooooooooooooon")
profile.should be_valid
end
it "cannot be 33 characters" do
profile = Factory.build(:profile, :first_name => "Hexagooooooooooooooooooooooooooon")
profile.should_not be_valid
end
end
describe "of last_name" do
it "strips leading and trailing whitespace" do
@ -19,6 +29,16 @@ describe Profile do
profile.should be_valid
profile.last_name.should == "Ohba"
end
it "can be 32 characters long" do
profile = Factory.build(:profile, :last_name => "Hexagoooooooooooooooooooooooooon")
profile.should be_valid
end
it "cannot be 33 characters" do
profile = Factory.build(:profile, :last_name => "Hexagooooooooooooooooooooooooooon")
profile.should_not be_valid
end
end
end
end

View file

@ -102,6 +102,16 @@ describe User do
user = Factory.build(:user, :username => "kittens;")
user.should_not be_valid
end
it "can be 32 characters long" do
user = Factory.build(:user, :username => "hexagoooooooooooooooooooooooooon")
user.should be_valid
end
it "cannot be 33 characters" do
user = Factory.build(:user, :username => "hexagooooooooooooooooooooooooooon")
user.should_not be_valid
end
end
describe "of email" do