Commit adb43797f8854ee1a76df09a9274b22b526ef506
Committed by
Antonio Terceiro
1 parent
5fdb7219
Exists in
master
and in
23 other branches
Limiting number of chars when asking/accepting friendship
* Number of chars limited to 150. * Validation of "group_for_person" and "group_for_friend" (ActionItem1352)
Showing
4 changed files
with
33 additions
and
2 deletions
Show diff stats
app/models/add_friend.rb
| @@ -6,6 +6,8 @@ class AddFriend < Task | @@ -6,6 +6,8 @@ class AddFriend < Task | ||
| 6 | 6 | ||
| 7 | validates_uniqueness_of :target_id, :scope => [ :requestor_id ] | 7 | validates_uniqueness_of :target_id, :scope => [ :requestor_id ] |
| 8 | 8 | ||
| 9 | + validates_length_of :group_for_person, :group_for_friend, :maximum => 150, :allow_nil => true | ||
| 10 | + | ||
| 9 | alias :person :requestor | 11 | alias :person :requestor |
| 10 | alias :person= :requestor= | 12 | alias :person= :requestor= |
| 11 | 13 |
app/views/friends/add.rhtml
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | 15 | ||
| 16 | <div> | 16 | <div> |
| 17 | <%= __('Classify your new friend %s: ') % @friend.name %> | 17 | <%= __('Classify your new friend %s: ') % @friend.name %> |
| 18 | - <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups) %> | 18 | + <%= text_field_with_local_autocomplete('group', profile.suggested_friend_groups, :maxlength => 150) %> |
| 19 | <p> | 19 | <p> |
| 20 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> | 20 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
| 21 | </p> | 21 | </p> |
app/views/tasks/_add_friend.rhtml
| @@ -27,7 +27,7 @@ | @@ -27,7 +27,7 @@ | ||
| 27 | <%= _('Classify your new friend:') %> | 27 | <%= _('Classify your new friend:') %> |
| 28 | <%= text_field_with_local_autocomplete("task[group_for_friend]", | 28 | <%= text_field_with_local_autocomplete("task[group_for_friend]", |
| 29 | profile.suggested_friend_groups, | 29 | profile.suggested_friend_groups, |
| 30 | - :id => "field-group-for-friend-#{task.id}") %> | 30 | + {:id => "field-group-for-friend-#{task.id}", :maxlength => 150}) %> |
| 31 | <p class="friend-classify-suggestions"> | 31 | <p class="friend-classify-suggestions"> |
| 32 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> | 32 | <%= _('Suggestions: %s') % profile.suggested_friend_groups.join(', ') %> |
| 33 | </p> | 33 | </p> |
test/unit/add_friend_test.rb
| @@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -100,4 +100,33 @@ class AddFriendTest < ActiveSupport::TestCase | ||
| 100 | end | 100 | end |
| 101 | end | 101 | end |
| 102 | 102 | ||
| 103 | + should 'limit "group for person" number of characters' do | ||
| 104 | + #Max value is 150 | ||
| 105 | + big_word = 'a' * 155 | ||
| 106 | + task = AddFriend.new | ||
| 107 | + | ||
| 108 | + task.group_for_person = big_word | ||
| 109 | + task.valid? | ||
| 110 | + assert task.errors[:group_for_person] | ||
| 111 | + | ||
| 112 | + task.group_for_person = 'short name' | ||
| 113 | + task.valid? | ||
| 114 | + assert !task.errors[:group_for_person] | ||
| 115 | + end | ||
| 116 | + | ||
| 117 | + should 'limit "group for friend" number of characters' do | ||
| 118 | + #Max value is 150 | ||
| 119 | + big_word = 'a' * 155 | ||
| 120 | + task = AddFriend.new | ||
| 121 | + | ||
| 122 | + task.group_for_friend = big_word | ||
| 123 | + task.valid? | ||
| 124 | + assert task.errors[:group_for_friend] | ||
| 125 | + | ||
| 126 | + task.group_for_friend = 'short name' | ||
| 127 | + task.valid? | ||
| 128 | + assert !task.errors[:group_for_friend] | ||
| 129 | + end | ||
| 130 | + | ||
| 131 | + | ||
| 103 | end | 132 | end |