Commit b2764fd63a0173985cc72cf847fcc55ce3b63bb8
1 parent
35a5443d
Exists in
master
and in
29 other branches
ActionItem41: adding a block to display profiles
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1333 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
55 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,16 @@ |
1 | +class ProfileListBlock < Block | |
2 | + | |
3 | + settings_items :limit, :default => 10 | |
4 | + | |
5 | + def self.description | |
6 | + _('A block that displays random profiles') | |
7 | + end | |
8 | + | |
9 | + def content | |
10 | + profiles = self.profiles | |
11 | + lambda do | |
12 | + profiles.map {|item| profile_image_link(item) } | |
13 | + end | |
14 | + end | |
15 | + | |
16 | +end | ... | ... |
... | ... | @@ -0,0 +1,39 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class ProfileListBlockTest < Test::Unit::TestCase | |
4 | + | |
5 | + should 'describe itself' do | |
6 | + assert_not_equal Block.description, ProfileListBlock.description | |
7 | + end | |
8 | + | |
9 | + should 'accept a limit of people to be displayed (and default to 10)' do | |
10 | + block = ProfileListBlock.new | |
11 | + assert_equal 10, block.limit | |
12 | + | |
13 | + block.limit = 20 | |
14 | + assert_equal 20, block.limit | |
15 | + end | |
16 | + | |
17 | + should 'list people' do | |
18 | + User.destroy_all | |
19 | + person1 = create_user('testperson1').person | |
20 | + person2 = create_user('testperson2').person | |
21 | + person3 = create_user('testperson3').person | |
22 | + | |
23 | + owner = create_user('mytestuser').person | |
24 | + block = ProfileListBlock.new | |
25 | + owner.boxes.first.blocks << block | |
26 | + block.save! | |
27 | + | |
28 | + # faking that we are picking random people | |
29 | + profiles = [person1, person3] | |
30 | + block.expects(:profiles).returns(profiles) | |
31 | + | |
32 | + self.expects(:profile_image_link).with(person1).once | |
33 | + self.expects(:profile_image_link).with(person2).never | |
34 | + self.expects(:profile_image_link).with(person3).once | |
35 | + | |
36 | + instance_eval(&block.content) | |
37 | + end | |
38 | + | |
39 | +end | ... | ... |