Commit 15262820cb734169a381ac0c25fe02083949cac2
1 parent
0bee68c8
Exists in
master
and in
22 other branches
ActionItem8: displaying profile
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@420 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
81 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +module ProfileHelper | ||
2 | + | ||
3 | + def display_profile_info(profile) | ||
4 | + info = profile.info | ||
5 | + if info.nil? | ||
6 | + content_tag('div', _('This profile does not have any public information')) | ||
7 | + else | ||
8 | + table_rows = '' | ||
9 | + info.each do |item| | ||
10 | + name = item[0] | ||
11 | + value = item[1] | ||
12 | + if value.is_a?(Proc) | ||
13 | + value = self.instance_eval(value) | ||
14 | + end | ||
15 | + | ||
16 | + table_rows << content_tag('tr', content_tag('th', name) + content_tag('td', value)) | ||
17 | + table_rows << "\n" | ||
18 | + end | ||
19 | + | ||
20 | + content_tag( | ||
21 | + 'table', | ||
22 | + table_rows, | ||
23 | + :class => 'profile_info' | ||
24 | + ) | ||
25 | + end | ||
26 | + end | ||
27 | + | ||
28 | +end |
@@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class ProfileHelperTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @profile = Profile.new | ||
7 | + @helper = mock | ||
8 | + helper.extend(ProfileHelper) | ||
9 | + end | ||
10 | + attr_reader :profile, :helper | ||
11 | + | ||
12 | + def test_should_ignore_nil | ||
13 | + profile.stubs(:info).returns(nil) | ||
14 | + | ||
15 | + helper.expects(:content_tag) | ||
16 | + helper.expects(:_) | ||
17 | + | ||
18 | + helper.display_profile_info(profile) | ||
19 | + end | ||
20 | + | ||
21 | + def test_should_display_info | ||
22 | + f1 = 'Field 1' | ||
23 | + v1 = 'value 1' | ||
24 | + f2 = 'Field 2' | ||
25 | + v2 = 'value 2' | ||
26 | + array = [ | ||
27 | + [ f1, v1 ], | ||
28 | + [ f2, v2 ] | ||
29 | + ] | ||
30 | + profile.stubs(:info).returns(array) | ||
31 | + | ||
32 | + helper.expects(:content_tag).with('th', f1).returns(f1) | ||
33 | + helper.expects(:content_tag).with('td', v1).returns(v1) | ||
34 | + helper.expects(:content_tag).with('tr', f1 + v1).returns('r1') | ||
35 | + helper.expects(:content_tag).with('th', f2).returns(f2) | ||
36 | + helper.expects(:content_tag).with('td', v2).returns(v2) | ||
37 | + helper.expects(:content_tag).with('tr', f2 + v2).returns('r2') | ||
38 | + helper.expects(:content_tag).with('table', "r1\nr2\n", :class => 'profile_info' ).returns('final') | ||
39 | + | ||
40 | + assert_equal 'final', helper.display_profile_info(profile) | ||
41 | + end | ||
42 | + | ||
43 | + def test_should_call_blocks | ||
44 | + myproc = lambda { content_tag('div', 'lalala') } | ||
45 | + profile.stubs(:info).returns([['f1', myproc ]]) | ||
46 | + helper.stubs(:content_tag).returns('') | ||
47 | + | ||
48 | + helper.expects(:instance_eval).with(myproc) | ||
49 | + | ||
50 | + helper.display_profile_info(profile) | ||
51 | + end | ||
52 | + | ||
53 | +end |