Commit 2ab9e1f4275c5bf808c40432b88f7df9a70e2d1e
1 parent
4735b157
Exists in
master
and in
28 other branches
ActionItem41: actually generating the list of people
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1335 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
55 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
@@ -3,7 +3,7 @@ class ProfileDesignController < BoxOrganizerController | @@ -3,7 +3,7 @@ class ProfileDesignController < BoxOrganizerController | ||
3 | needs_profile | 3 | needs_profile |
4 | 4 | ||
5 | def available_blocks | 5 | def available_blocks |
6 | - @available_blocks ||= [ Block, ArticleBlock, TagsBlock, RecentDocumentsBlock ] | 6 | + @available_blocks ||= [ Block, ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock ] |
7 | end | 7 | end |
8 | 8 | ||
9 | end | 9 | end |
app/models/profile_list_block.rb
1 | class ProfileListBlock < Block | 1 | class ProfileListBlock < Block |
2 | 2 | ||
3 | - settings_items :limit, :default => 10 | 3 | + settings_items :limit, :default => 6 |
4 | 4 | ||
5 | def self.description | 5 | def self.description |
6 | _('A block that displays random profiles') | 6 | _('A block that displays random profiles') |
7 | end | 7 | end |
8 | 8 | ||
9 | + def profiles | ||
10 | + top = Profile.count | ||
11 | + | ||
12 | + result = [] | ||
13 | + maxsize = [limit,top].compact.min | ||
14 | + | ||
15 | + maxsize.times do | ||
16 | + profile = Profile.find(random(top) + 1) | ||
17 | + result << profile | ||
18 | + end | ||
19 | + | ||
20 | + result | ||
21 | + end | ||
22 | + | ||
23 | + def random(top) | ||
24 | + Kernel.rand(top) | ||
25 | + end | ||
26 | + | ||
9 | def content | 27 | def content |
10 | profiles = self.profiles | 28 | profiles = self.profiles |
11 | lambda do | 29 | lambda do |
12 | - profiles.map {|item| profile_image_link(item) } | 30 | + block_title(_('People')) + |
31 | + profiles.map {|item| content_tag('div', profile_image_link(item)) }.join("\n") | ||
13 | end | 32 | end |
14 | end | 33 | end |
15 | 34 |
test/unit/profile_list_block_test.rb
@@ -6,9 +6,9 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -6,9 +6,9 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
6 | assert_not_equal Block.description, ProfileListBlock.description | 6 | assert_not_equal Block.description, ProfileListBlock.description |
7 | end | 7 | end |
8 | 8 | ||
9 | - should 'accept a limit of people to be displayed (and default to 10)' do | 9 | + should 'accept a limit of people to be displayed (and default to 6)' do |
10 | block = ProfileListBlock.new | 10 | block = ProfileListBlock.new |
11 | - assert_equal 10, block.limit | 11 | + assert_equal 6, block.limit |
12 | 12 | ||
13 | block.limit = 20 | 13 | block.limit = 20 |
14 | assert_equal 20, block.limit | 14 | assert_equal 20, block.limit |
@@ -33,7 +33,30 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -33,7 +33,30 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
33 | self.expects(:profile_image_link).with(person2).never | 33 | self.expects(:profile_image_link).with(person2).never |
34 | self.expects(:profile_image_link).with(person3).once | 34 | self.expects(:profile_image_link).with(person3).once |
35 | 35 | ||
36 | - instance_eval(&block.content) | 36 | + self.expects(:content_tag).returns('<div></div>').at_least_once |
37 | + self.expects(:_).returns('text').at_least_once | ||
38 | + self.expects(:block_title).returns('block title').at_least_once | ||
39 | + | ||
40 | + assert_kind_of String, instance_eval(&block.content) | ||
41 | + end | ||
42 | + | ||
43 | + should 'pick random people' do | ||
44 | + block = ProfileListBlock.new | ||
45 | + | ||
46 | + Profile.expects(:count).returns(3) | ||
47 | + | ||
48 | + block.expects(:random).times(3).returns(7).then.returns(4).then.returns(5) | ||
49 | + | ||
50 | + Profile.expects(:find).with(8) | ||
51 | + Profile.expects(:find).with(5) | ||
52 | + Profile.expects(:find).with(6) | ||
53 | + | ||
54 | + block.profiles | ||
55 | + end | ||
56 | + | ||
57 | + should 'use Kernel.rand to generate random numbers' do | ||
58 | + Kernel.expects(:rand).with(77).once | ||
59 | + ProfileListBlock.new.random(77) | ||
37 | end | 60 | end |
38 | 61 | ||
39 | end | 62 | end |