From cdcb693c9521530644c46b7d873339c7d748f585 Mon Sep 17 00:00:00 2001 From: Justin Wienckowski Date: Thu, 28 Oct 2010 20:58:39 -0700 Subject: [PATCH] Issue #446: Adding 32-character length limit to User#username, Profile#first_name, Profile#last_name --- app/models/profile.rb | 2 ++ app/models/user.rb | 3 ++- spec/models/profile_spec.rb | 20 ++++++++++++++++++++ spec/models/user_spec.rb | 10 ++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) 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 071abfcb0..cc9a2b7e9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 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 a9530093f..fe92b6b94 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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