Commit dd37857043e02bf4fb85fae744a095803aabf1e8
1 parent
4bd91b76
Exists in
master
and in
29 other branches
ActionItem36: reformulating the friends groups listing
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1500 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
15 additions
and
5 deletions
Show diff stats
app/models/person.rb
| ... | ... | @@ -5,8 +5,12 @@ class Person < Profile |
| 5 | 5 | has_many :friendships |
| 6 | 6 | has_many :friends, :class_name => 'Person', :through => :friendships |
| 7 | 7 | |
| 8 | + def suggested_friend_groups | |
| 9 | + friend_groups + [ _('friends'), _('work'), _('school'), _('family') ] | |
| 10 | + end | |
| 11 | + | |
| 8 | 12 | def friend_groups |
| 9 | - ([_('friends'), _('work'), _('school'), _('family')] + friendships.map {|item| item.group}).uniq | |
| 13 | + friendships.map {|item| item.group}.uniq | |
| 10 | 14 | end |
| 11 | 15 | |
| 12 | 16 | # has_many :person_friendships | ... | ... |
test/unit/person_test.rb
| ... | ... | @@ -158,8 +158,15 @@ class PersonTest < Test::Unit::TestCase |
| 158 | 158 | |
| 159 | 159 | end |
| 160 | 160 | |
| 161 | - should 'provide default friend groups list' do | |
| 162 | - assert_equivalent [ 'friends', 'work', 'school', 'family' ], Person.new.friend_groups | |
| 161 | + should 'suggest default friend groups list' do | |
| 162 | + p = Person.new | |
| 163 | + assert_equivalent [ 'friends', 'work', 'school', 'family' ], p.suggested_friend_groups | |
| 164 | + end | |
| 165 | + | |
| 166 | + should 'suggest current groups as well' do | |
| 167 | + p = Person.new | |
| 168 | + p.expects(:friend_groups).returns(['group1', 'group2']) | |
| 169 | + assert_equivalent [ 'friends', 'work', 'school', 'family', 'group1', 'group2' ], p.suggested_friend_groups | |
| 163 | 170 | end |
| 164 | 171 | |
| 165 | 172 | should 'list friend groups' do |
| ... | ... | @@ -172,8 +179,7 @@ class PersonTest < Test::Unit::TestCase |
| 172 | 179 | Friendship.create!(:person => p1, :friend => p3, :group => 'group2') |
| 173 | 180 | Friendship.create!(:person => p1, :friend => p4, :group => 'group1') |
| 174 | 181 | |
| 175 | - assert_includes p1.friend_groups, 'group1' | |
| 176 | - assert_includes p1.friend_groups, 'group2' | |
| 182 | + assert_equivalent ['group1', 'group2'], p1.friend_groups | |
| 177 | 183 | end |
| 178 | 184 | |
| 179 | 185 | end | ... | ... |