diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 31044bd..b837c85 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -5,10 +5,15 @@ class ProfileDesignController < BoxOrganizerController def available_blocks blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock ] + # blocks exclusive for organizations if profile.has_members? blocks << MembersBlock end + if profile.person? + blocks << FriendsBlock + end + blocks end diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb new file mode 100644 index 0000000..baa5f93 --- /dev/null +++ b/app/models/friends_block.rb @@ -0,0 +1,22 @@ +class FriendsBlock < ProfileListBlock + + def self.description + _('A block that displays your friends') + end + + def title + _('Friends') + end + + class FriendsBlock::Finder < ProfileListBlock::Finder + def ids + self.block.owner.friend_ids + end + end + + def profile_finder + @profile_finder ||= FriendsBlock::Finder.new(self) + end + + +end diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb new file mode 100644 index 0000000..7bb0dda --- /dev/null +++ b/test/unit/friends_block_test.rb @@ -0,0 +1,34 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FriendsBlockTest < ActiveSupport::TestCase + + should 'describe itself' do + assert_not_equal ProfileListBlock.description, FriendsBlock.description + end + + should 'declare its title' do + assert_not_equal ProfileListBlock.new.title, FriendsBlock.new.title + end + + should 'use its own finder' do + assert_not_equal ProfileListBlock::Finder, FriendsBlock::Finder + assert_kind_of FriendsBlock::Finder, FriendsBlock.new.profile_finder + end + + should 'list owner friends' do + p1 = create_user('testuser1').person + p2 = create_user('testuser2').person + p3 = create_user('testuser3').person + p4 = create_user('testuser4').person + + p1.add_friend(p2) + p1.add_friend(p3) + p1.add_friend(p4) + + block = FriendsBlock.new + block.expects(:owner).returns(p1) + + assert_equivalent [p2, p3, p4], block.profiles + end + +end -- libgit2 0.21.2