From 8a2e0eef7c5c1958af5d5d310f565fd224696ad6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 2 Feb 2011 16:36:12 -0800 Subject: [PATCH] No semicolons in names --- app/models/profile.rb | 2 ++ spec/models/profile_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/profile.rb b/app/models/profile.rb index ea5e7c42a..72a597b7f 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -23,6 +23,8 @@ class Profile < ActiveRecord::Base validates_length_of :first_name, :maximum => 32 validates_length_of :last_name, :maximum => 32 + validates_format_of :first_name, :with => /\A[^;]+\z/ + validates_format_of :last_name, :with => /\A[^;]+\z/ attr_accessible :first_name, :last_name, :image_url, :image_url_medium, :image_url_small, :birthday, :gender, :bio, :searchable, :date diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index e32b63534..d094b476d 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -22,6 +22,10 @@ describe Profile do profile = Factory.build(:profile, :first_name => "Hexagooooooooooooooooooooooooooon") profile.should_not be_valid end + it 'cannot have ;' do + profile = Factory.build(:profile, :first_name => "Hex;agon") + profile.should_not be_valid + end end describe "of last_name" do it "strips leading and trailing whitespace" do @@ -39,6 +43,15 @@ describe Profile do profile = Factory.build(:profile, :last_name => "Hexagooooooooooooooooooooooooooon") profile.should_not be_valid end + + it 'cannot have ;' do + profile = Factory.build(:profile, :last_name => "Hex;agon") + profile.should_not be_valid + end + it 'disallows ; with a newline in the string' do + profile = Factory.build(:profile, :last_name => "H\nex;agon") + profile.should_not be_valid + end end end