Commit 61e1b12f709aea0bbbc39916c30c769a3ef74300

Authored by AntonioTerceiro
1 parent dd6b5db7

ActionItem320: using different blocks for people, enterprises and

communities; adapting enterprise and community ones to also accept
environment as owner


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1710 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/admin/environment_design_controller.rb
... ... @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController
3 3 protect 'edit_environment_design', :environment
4 4  
5 5 def available_blocks
6   - @available_blocks ||= [ LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, ProfileListBlock ]
  6 + @available_blocks ||= [ LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock ]
7 7 end
8 8  
9 9 end
... ...
app/models/communities_block.rb
... ... @@ -25,7 +25,9 @@ class CommunitiesBlock < ProfileListBlock
25 25  
26 26 class Finder < ProfileListBlock::Finder
27 27 def ids
28   - block.owner.community_memberships.map(&:id)
  28 + # FIXME when owner is an environment (i.e. listing communities globally
  29 + # this can become SLOW)
  30 + block.owner.communities.map(&:id)
29 31 end
30 32 end
31 33  
... ...
app/models/enterprises_block.rb
... ... @@ -26,7 +26,9 @@ class EnterprisesBlock &lt; ProfileListBlock
26 26  
27 27 class Finder < ProfileListBlock::Finder
28 28 def ids
29   - block.owner.enterprise_memberships.map(&:id)
  29 + # FIXME when owner is an environment (i.e. listing enterprises globally
  30 + # this can become SLOW)
  31 + block.owner.enterprises.map(&:id)
30 32 end
31 33 end
32 34  
... ...
app/models/people_block.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +class PeopleBlock < ProfileListBlock
  2 +
  3 + def title
  4 + _('People')
  5 + end
  6 +
  7 + def help
  8 + _('Clicking a person takes you to his/her homepage')
  9 + end
  10 +
  11 + def self.description
  12 + _('A block displays random people')
  13 + end
  14 +
  15 + def profile_finder
  16 + @profile_finder ||= PeopleBlock::Finder.new(self)
  17 + end
  18 +
  19 + class Finder < ProfileListBlock::Finder
  20 + def ids
  21 + Person.find(:all, :select => 'id', :conditions => { :environment_id => block.owner.id})
  22 + end
  23 + end
  24 +
  25 +end
... ...
test/unit/communities_block_test.rb
... ... @@ -31,7 +31,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
31 31 member2 = mock; member2.stubs(:id).returns(2)
32 32 member3 = mock; member3.stubs(:id).returns(3)
33 33  
34   - owner.expects(:community_memberships).returns([member1, member2, member3])
  34 + owner.expects(:communities).returns([member1, member2, member3])
35 35  
36 36 block.profile_finder.expects(:pick_random).with(3).returns(2)
37 37 block.profile_finder.expects(:pick_random).with(2).returns(0)
... ...
test/unit/enterprises_block_test.rb
... ... @@ -31,7 +31,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
31 31 member2 = mock; member2.stubs(:id).returns(2)
32 32 member3 = mock; member3.stubs(:id).returns(3)
33 33  
34   - owner.expects(:enterprise_memberships).returns([member1, member2, member3])
  34 + owner.expects(:enterprises).returns([member1, member2, member3])
35 35  
36 36 block.profile_finder.expects(:pick_random).with(3).returns(2)
37 37 block.profile_finder.expects(:pick_random).with(2).returns(0)
... ...
test/unit/people_block_test.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class PeopleBlockTest < ActiveSupport::TestCase
  4 +
  5 + should 'inherit from ProfileListBlock' do
  6 + assert_kind_of ProfileListBlock, PeopleBlock.new
  7 + end
  8 +
  9 + should 'declare its title' do
  10 + assert_not_equal ProfileListBlock.new.title, PeopleBlock.new.title
  11 + end
  12 +
  13 + should 'describe itself' do
  14 + assert_not_equal ProfileListBlock.description, PeopleBlock.description
  15 + end
  16 +
  17 + should 'give help' do
  18 + assert_not_equal ProfileListBlock.new.help, PeopleBlock.new.help
  19 + end
  20 +
  21 + should 'use its own finder' do
  22 + assert_not_equal ProfileListBlock::Finder, PeopleBlock::Finder
  23 + assert_kind_of PeopleBlock::Finder, PeopleBlock.new.profile_finder
  24 + end
  25 +
  26 + should 'list people' do
  27 + owner = mock
  28 + owner.expects(:id).returns(99)
  29 + Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => 99}).returns([])
  30 + block = PeopleBlock.new
  31 + block.expects(:owner).returns(owner).at_least_once
  32 + block.content
  33 + end
  34 +
  35 +end
... ...