diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb index 6c41651..872655e 100644 --- a/app/models/communities_block.rb +++ b/app/models/communities_block.rb @@ -13,9 +13,18 @@ class CommunitiesBlock < ProfileListBlock end def footer - profile = self.owner - lambda do - link_to _('All communities'), :profile => profile.identifier, :controller => 'profile', :action => 'communities' + owner = self.owner + case owner + when Profile + lambda do + link_to _('All communities'), :profile => owner.identifier, :controller => 'profile', :action => 'communities' + end + when Environment + lambda do + link_to _('All communities'), :controller => 'search', :action => 'assets', :asset => 'communities' + end + else + '' end end diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb index fa62cf3..898620d 100644 --- a/app/models/enterprises_block.rb +++ b/app/models/enterprises_block.rb @@ -13,9 +13,18 @@ class EnterprisesBlock < ProfileListBlock end def footer - profile = self.owner - lambda do - link_to _('All enterprises'), :profile => profile.identifier, :controller => 'profile', :action => 'enterprises' + owner = self.owner + case owner + when Profile + lambda do + link_to _('All enterprises'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises' + end + when Environment + lambda do + link_to _('All enterprises'), :controller => 'search', :action => 'assets', :asset => 'enterprises' + end + else + '' end end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index 10af09c..c3d4b29 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -42,4 +42,33 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_equal [member3, member1], block.profiles end + should 'link to all communities of profile' do + profile = Profile.new + profile.expects(:identifier).returns("theprofile") + + block = CommunitiesBlock.new + block.expects(:owner).returns(profile) + + expects(:_).with('All communities').returns('All communities') + expects(:link_to).with('All communities', :controller => 'profile', :profile => 'theprofile', :action => 'communities') + instance_eval(&block.footer) + end + + should 'support environment as owner' do + env = Environment.default + block = CommunitiesBlock.new + block.expects(:owner).returns(env) + + expects(:_).with('All communities').returns('All communities') + expects(:link_to).with('All communities', :controller => 'search', :action => 'assets', :asset => 'communities') + + instance_eval(&block.footer) + end + + should 'give empty footer on unsupported owner type' do + block = CommunitiesBlock.new + block.expects(:owner).returns(1) + assert_equal '', block.footer + end + end diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb index de87abb..a163b5f 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -42,4 +42,32 @@ class EnterprisesBlockTest < Test::Unit::TestCase assert_equal [member3, member1], block.profiles end + should 'link to all enterprises for profile' do + profile = Profile.new + profile.expects(:identifier).returns('theprofile') + block = EnterprisesBlock.new + block.expects(:owner).returns(profile) + + expects(:_).with('All enterprises').returns('All enterprises') + expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') + + instance_eval(&block.footer) + end + + should 'link to all enterprises for environment' do + env = Environment.default + block = EnterprisesBlock.new + block.expects(:owner).returns(env) + + expects(:_).with('All enterprises').returns('All enterprises') + expects(:link_to).with('All enterprises', :controller => 'search', :action => 'assets', :asset => 'enterprises') + instance_eval(&block.footer) + end + + should 'give empty footer for unsupported owner type' do + block = EnterprisesBlock.new + block.expects(:owner).returns(1) + assert_equal '', block.footer + end + end -- libgit2 0.21.2