Commit b2b9747653e45f4f1396f30cfc409b2d6d980186
1 parent
ed6f25a5
Exists in
staging
and in
42 other branches
ActionItem43: adding a block for listing members
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1349 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
68 additions
and
0 deletions
 
Show diff stats
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +class MembersBlock < ProfileListBlock | ||
| 2 | + | ||
| 3 | + def self.description | ||
| 4 | + _('A block that displays members.') | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def title | ||
| 8 | + _('Members') | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + def footer | ||
| 12 | + profile = self.owner | ||
| 13 | + lambda do | ||
| 14 | + link_to _('All members'), :profile => profile.identifier, :controller => 'profile', :action => 'members' | ||
| 15 | + end | ||
| 16 | + end | ||
| 17 | + | ||
| 18 | + class Finder | ||
| 19 | + | ||
| 20 | + def initialize(members) | ||
| 21 | + @members = members | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + # FIXME optimize this !!! | ||
| 25 | + def find(options) | ||
| 26 | + Profile.find(:all, options.merge(:conditions => { :id => @members.map(&:id) })) | ||
| 27 | + end | ||
| 28 | + end | ||
| 29 | + | ||
| 30 | + def profile_finder | ||
| 31 | + @profile_finder ||= Finder.new(owner.members) | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | +end | 
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class MembersBlockTest < Test::Unit::TestCase | ||
| 4 | + | ||
| 5 | + should 'inherit from ProfileListBlock' do | ||
| 6 | + assert_kind_of ProfileListBlock, MembersBlock.new | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + should 'describe itself' do | ||
| 10 | + assert_not_equal ProfileListBlock.description, MembersBlock.description | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + should 'link to "all members" page' do | ||
| 14 | + profile = create_user('mytestuser').person | ||
| 15 | + block = MembersBlock.new | ||
| 16 | + block.box = profile.boxes.first | ||
| 17 | + block.save! | ||
| 18 | + | ||
| 19 | + expects(:_).with('All members').returns('All members') | ||
| 20 | + expects(:link_to).with('All members' , :profile => 'mytestuser', :controller => 'profile', :action => 'members').returns('link-to-members') | ||
| 21 | + | ||
| 22 | + assert_equal 'link-to-members', instance_eval(&block.footer) | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + should 'pick only members' do | ||
| 26 | + profile = create_user('mytestuser').person | ||
| 27 | + block = MembersBlock.new | ||
| 28 | + block.box = profile.boxes.first | ||
| 29 | + block.save! | ||
| 30 | + | ||
| 31 | + assert_equal profile.members, block.profiles | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | +end |