Skip to content
Extraits de code Groupes Projets
Valider c929ce21 rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

fixed validation on tag length in profile

parent 058b7484
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -33,6 +33,7 @@ class Profile < ActiveRecord::Base ...@@ -33,6 +33,7 @@ class Profile < ActiveRecord::Base
validates_length_of :last_name, :maximum => 32 validates_length_of :last_name, :maximum => 32
validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :first_name, :with => /\A[^;]+\z/, :allow_blank => true
validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true validates_format_of :last_name, :with => /\A[^;]+\z/, :allow_blank => true
validate :max_tags
attr_accessible :first_name, :last_name, :image_url, :image_url_medium, attr_accessible :first_name, :last_name, :image_url, :image_url_medium,
:image_url_small, :birthday, :gender, :bio, :searchable, :date, :tag_string :image_url_small, :birthday, :gender, :bio, :searchable, :date, :tag_string
...@@ -112,12 +113,17 @@ class Profile < ActiveRecord::Base ...@@ -112,12 +113,17 @@ class Profile < ActiveRecord::Base
end end
protected protected
def strip_names def strip_names
self.first_name.strip! if self.first_name self.first_name.strip! if self.first_name
self.last_name.strip! if self.last_name self.last_name.strip! if self.last_name
end end
def max_tags
if self.tag_string.count('#') > 5
errors[:base] << 'Profile cannot have more than five tags'
end
end
private private
def absolutify_local_url url def absolutify_local_url url
pod_url = AppConfig[:pod_url].dup pod_url = AppConfig[:pod_url].dup
......
...@@ -174,9 +174,16 @@ describe Profile do ...@@ -174,9 +174,16 @@ describe Profile do
@object = person.profile @object = person.profile
end end
it 'allows 5 tags' do it 'allows 5 tags' do
@object.tag_string = '#one #two #three #four #five'
@object.valid?
@object.errors.full_messages
@object.should be_valid
end
it 'allows no more than 5 tags' do
@object.tag_string = '#one #two #three #four #five #six' @object.tag_string = '#one #two #three #four #five #six'
@object.build_tags @object.should_not be_valid
@object.valid?.should be_false
end end
it_should_behave_like 'it is taggable' it_should_behave_like 'it is taggable'
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter