Commit 380db7993927d97ad0f950b732ff3217d3d9874c
1 parent
c211161f
Exists in
master
and in
29 other branches
ActionItem320: finished splitting up the 3 types fo blocks
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1713 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
81 additions
and
6 deletions
Show diff stats
app/models/communities_block.rb
... | ... | @@ -13,9 +13,18 @@ class CommunitiesBlock < ProfileListBlock |
13 | 13 | end |
14 | 14 | |
15 | 15 | def footer |
16 | - profile = self.owner | |
17 | - lambda do | |
18 | - link_to _('All communities'), :profile => profile.identifier, :controller => 'profile', :action => 'communities' | |
16 | + owner = self.owner | |
17 | + case owner | |
18 | + when Profile | |
19 | + lambda do | |
20 | + link_to _('All communities'), :profile => owner.identifier, :controller => 'profile', :action => 'communities' | |
21 | + end | |
22 | + when Environment | |
23 | + lambda do | |
24 | + link_to _('All communities'), :controller => 'search', :action => 'assets', :asset => 'communities' | |
25 | + end | |
26 | + else | |
27 | + '' | |
19 | 28 | end |
20 | 29 | end |
21 | 30 | ... | ... |
app/models/enterprises_block.rb
... | ... | @@ -13,9 +13,18 @@ class EnterprisesBlock < ProfileListBlock |
13 | 13 | end |
14 | 14 | |
15 | 15 | def footer |
16 | - profile = self.owner | |
17 | - lambda do | |
18 | - link_to _('All enterprises'), :profile => profile.identifier, :controller => 'profile', :action => 'enterprises' | |
16 | + owner = self.owner | |
17 | + case owner | |
18 | + when Profile | |
19 | + lambda do | |
20 | + link_to _('All enterprises'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises' | |
21 | + end | |
22 | + when Environment | |
23 | + lambda do | |
24 | + link_to _('All enterprises'), :controller => 'search', :action => 'assets', :asset => 'enterprises' | |
25 | + end | |
26 | + else | |
27 | + '' | |
19 | 28 | end |
20 | 29 | end |
21 | 30 | ... | ... |
test/unit/communities_block_test.rb
... | ... | @@ -42,4 +42,33 @@ class CommunitiesBlockTest < Test::Unit::TestCase |
42 | 42 | assert_equal [member3, member1], block.profiles |
43 | 43 | end |
44 | 44 | |
45 | + should 'link to all communities of profile' do | |
46 | + profile = Profile.new | |
47 | + profile.expects(:identifier).returns("theprofile") | |
48 | + | |
49 | + block = CommunitiesBlock.new | |
50 | + block.expects(:owner).returns(profile) | |
51 | + | |
52 | + expects(:_).with('All communities').returns('All communities') | |
53 | + expects(:link_to).with('All communities', :controller => 'profile', :profile => 'theprofile', :action => 'communities') | |
54 | + instance_eval(&block.footer) | |
55 | + end | |
56 | + | |
57 | + should 'support environment as owner' do | |
58 | + env = Environment.default | |
59 | + block = CommunitiesBlock.new | |
60 | + block.expects(:owner).returns(env) | |
61 | + | |
62 | + expects(:_).with('All communities').returns('All communities') | |
63 | + expects(:link_to).with('All communities', :controller => 'search', :action => 'assets', :asset => 'communities') | |
64 | + | |
65 | + instance_eval(&block.footer) | |
66 | + end | |
67 | + | |
68 | + should 'give empty footer on unsupported owner type' do | |
69 | + block = CommunitiesBlock.new | |
70 | + block.expects(:owner).returns(1) | |
71 | + assert_equal '', block.footer | |
72 | + end | |
73 | + | |
45 | 74 | end | ... | ... |
test/unit/enterprises_block_test.rb
... | ... | @@ -42,4 +42,32 @@ class EnterprisesBlockTest < Test::Unit::TestCase |
42 | 42 | assert_equal [member3, member1], block.profiles |
43 | 43 | end |
44 | 44 | |
45 | + should 'link to all enterprises for profile' do | |
46 | + profile = Profile.new | |
47 | + profile.expects(:identifier).returns('theprofile') | |
48 | + block = EnterprisesBlock.new | |
49 | + block.expects(:owner).returns(profile) | |
50 | + | |
51 | + expects(:_).with('All enterprises').returns('All enterprises') | |
52 | + expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') | |
53 | + | |
54 | + instance_eval(&block.footer) | |
55 | + end | |
56 | + | |
57 | + should 'link to all enterprises for environment' do | |
58 | + env = Environment.default | |
59 | + block = EnterprisesBlock.new | |
60 | + block.expects(:owner).returns(env) | |
61 | + | |
62 | + expects(:_).with('All enterprises').returns('All enterprises') | |
63 | + expects(:link_to).with('All enterprises', :controller => 'search', :action => 'assets', :asset => 'enterprises') | |
64 | + instance_eval(&block.footer) | |
65 | + end | |
66 | + | |
67 | + should 'give empty footer for unsupported owner type' do | |
68 | + block = EnterprisesBlock.new | |
69 | + block.expects(:owner).returns(1) | |
70 | + assert_equal '', block.footer | |
71 | + end | |
72 | + | |
45 | 73 | end | ... | ... |