Commit 194e82123933fea0ec16ba786b74988856a0a55c
1 parent
6fbde715
Exists in
master
and in
23 other branches
ActionItem36: adding a friends block
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1506 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
61 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
| @@ -5,10 +5,15 @@ class ProfileDesignController < BoxOrganizerController | @@ -5,10 +5,15 @@ class ProfileDesignController < BoxOrganizerController | ||
| 5 | def available_blocks | 5 | def available_blocks |
| 6 | blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock ] | 6 | blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock ] |
| 7 | 7 | ||
| 8 | + # blocks exclusive for organizations | ||
| 8 | if profile.has_members? | 9 | if profile.has_members? |
| 9 | blocks << MembersBlock | 10 | blocks << MembersBlock |
| 10 | end | 11 | end |
| 11 | 12 | ||
| 13 | + if profile.person? | ||
| 14 | + blocks << FriendsBlock | ||
| 15 | + end | ||
| 16 | + | ||
| 12 | blocks | 17 | blocks |
| 13 | end | 18 | end |
| 14 | 19 |
| @@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
| 1 | +class FriendsBlock < ProfileListBlock | ||
| 2 | + | ||
| 3 | + def self.description | ||
| 4 | + _('A block that displays your friends') | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def title | ||
| 8 | + _('Friends') | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + class FriendsBlock::Finder < ProfileListBlock::Finder | ||
| 12 | + def ids | ||
| 13 | + self.block.owner.friend_ids | ||
| 14 | + end | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + def profile_finder | ||
| 18 | + @profile_finder ||= FriendsBlock::Finder.new(self) | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +end |
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class FriendsBlockTest < ActiveSupport::TestCase | ||
| 4 | + | ||
| 5 | + should 'describe itself' do | ||
| 6 | + assert_not_equal ProfileListBlock.description, FriendsBlock.description | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + should 'declare its title' do | ||
| 10 | + assert_not_equal ProfileListBlock.new.title, FriendsBlock.new.title | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + should 'use its own finder' do | ||
| 14 | + assert_not_equal ProfileListBlock::Finder, FriendsBlock::Finder | ||
| 15 | + assert_kind_of FriendsBlock::Finder, FriendsBlock.new.profile_finder | ||
| 16 | + end | ||
| 17 | + | ||
| 18 | + should 'list owner friends' do | ||
| 19 | + p1 = create_user('testuser1').person | ||
| 20 | + p2 = create_user('testuser2').person | ||
| 21 | + p3 = create_user('testuser3').person | ||
| 22 | + p4 = create_user('testuser4').person | ||
| 23 | + | ||
| 24 | + p1.add_friend(p2) | ||
| 25 | + p1.add_friend(p3) | ||
| 26 | + p1.add_friend(p4) | ||
| 27 | + | ||
| 28 | + block = FriendsBlock.new | ||
| 29 | + block.expects(:owner).returns(p1) | ||
| 30 | + | ||
| 31 | + assert_equivalent [p2, p3, p4], block.profiles | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | +end |