fixed validation on tag length in profile
This commit is contained in:
parent
058b74846a
commit
c929ce21ad
2 changed files with 16 additions and 3 deletions
|
|
@ -33,6 +33,7 @@ class Profile < ActiveRecord::Base
|
|||
validates_length_of :last_name, :maximum => 32
|
||||
validates_format_of :first_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,
|
||||
:image_url_small, :birthday, :gender, :bio, :searchable, :date, :tag_string
|
||||
|
|
@ -112,12 +113,17 @@ class Profile < ActiveRecord::Base
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
def strip_names
|
||||
self.first_name.strip! if self.first_name
|
||||
self.last_name.strip! if self.last_name
|
||||
end
|
||||
|
||||
def max_tags
|
||||
if self.tag_string.count('#') > 5
|
||||
errors[:base] << 'Profile cannot have more than five tags'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def absolutify_local_url url
|
||||
pod_url = AppConfig[:pod_url].dup
|
||||
|
|
|
|||
|
|
@ -174,9 +174,16 @@ describe Profile do
|
|||
@object = person.profile
|
||||
end
|
||||
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.build_tags
|
||||
@object.valid?.should be_false
|
||||
@object.should_not be_valid
|
||||
end
|
||||
it_should_behave_like 'it is taggable'
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue