diff --git a/app/models/profile.rb b/app/models/profile.rb index c49601038972d443b4ead087cbb94e38c6d28c3a..d432d73e747f41550801b095e0e034d51005866f 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 991111644d7bd9e5f6a75b5f03edf1859993d7b6..c050172fa9f7c608632f6935d5ea3b58a748885a 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -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