Merge remote branch 'jwinky/446-user-name-length-limit'

Conflicts:
	app/models/user.rb
This commit is contained in:
Raphael 2010-11-01 11:00:02 -07:00
commit 6c0b187d40
4 changed files with 36 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

@ -40,8 +40,11 @@ class User
validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false
validates_format_of :username, :with => /\A[A-Za-z0-9_.]+\z/
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
validates_length_of :username, :maximum => 32
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
validates_presence_of :person, :unless => proc {|user| user.invitation_token.present?}
validates_associated :person
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

@ -106,6 +106,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