diff --git a/app/models/profile.rb b/app/models/profile.rb index 8848cd823..145732d7c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index f15f0e2ae..1f1333e56 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index fed124726..728fc4c3d 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 9449c4cdb..077224674 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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