diff --git a/app/models/add_friend.rb b/app/models/add_friend.rb index 7bed2e5..b0e7164 100644 --- a/app/models/add_friend.rb +++ b/app/models/add_friend.rb @@ -6,6 +6,8 @@ class AddFriend < Task validates_uniqueness_of :target_id, :scope => [ :requestor_id ] + validates_length_of :group_for_person, :group_for_friend, :maximum => 150, :allow_nil => true + alias :person :requestor alias :person= :requestor= diff --git a/app/views/friends/add.rhtml b/app/views/friends/add.rhtml index b50e790..2432ae0 100644 --- a/app/views/friends/add.rhtml +++ b/app/views/friends/add.rhtml @@ -15,7 +15,7 @@
<%= __('Classify your new friend %s: ') % @friend.name %> - <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups) %> + <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups, :maxlength => 150) %>

<%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %>

diff --git a/app/views/tasks/_add_friend.rhtml b/app/views/tasks/_add_friend.rhtml index 9bf04e4..eb8e0ba 100644 --- a/app/views/tasks/_add_friend.rhtml +++ b/app/views/tasks/_add_friend.rhtml @@ -27,7 +27,7 @@ <%= _('Classify your new friend:') %> <%= text_field_with_local_autocomplete("task[group_for_friend]", profile.suggested_friend_groups, - :id => "field-group-for-friend-#{task.id}") %> + {:id => "field-group-for-friend-#{task.id}", :maxlength => 150}) %>

<%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %>

diff --git a/test/unit/add_friend_test.rb b/test/unit/add_friend_test.rb index 023211f..5c80d1e 100644 --- a/test/unit/add_friend_test.rb +++ b/test/unit/add_friend_test.rb @@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase end end + should 'limit "group for person" number of characters' do + #Max value is 150 + big_word = 'a' * 155 + task = AddFriend.new + + task.group_for_person = big_word + task.valid? + assert task.errors[:group_for_person] + + task.group_for_person = 'short name' + task.valid? + assert !task.errors[:group_for_person] + end + + should 'limit "group for friend" number of characters' do + #Max value is 150 + big_word = 'a' * 155 + task = AddFriend.new + + task.group_for_friend = big_word + task.valid? + assert task.errors[:group_for_friend] + + task.group_for_friend = 'short name' + task.valid? + assert !task.errors[:group_for_friend] + end + + end -- libgit2 0.21.2