From a12c0d83c05f3dc4ddfce2dbeda4cf2bef3029c6 Mon Sep 17 00:00:00 2001 From: Sam Radhakrishnan Date: Mon, 2 Feb 2015 01:10:35 +0530 Subject: [PATCH] Fixed Bug #5593. Added length validation to location in profile model with maximum length 255. --- app/models/profile.rb | 1 + spec/models/profile_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/profile.rb b/app/models/profile.rb index bfbb535e5..622a3e919 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -32,6 +32,7 @@ class Profile < ActiveRecord::Base validates :first_name, :length => { :maximum => 32 } validates :last_name, :length => { :maximum => 32 } + validates :location, :length => { :maximum =>255 } validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index b9406c5f3..2e7379fd1 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -112,6 +112,18 @@ describe Profile, :type => :model do end end + describe "of location" do + it "can be 255 characters long" do + profile = FactoryGirl.build(:profile, :location => "a"*255) + expect(profile).to be_valid + end + + it "cannot be 256 characters" do + profile = FactoryGirl.build(:profile, :location => "a"*256) + expect(profile).not_to be_valid + end + end + describe '#image_url=' do before do @profile = FactoryGirl.build(:profile)