diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb index 253acae..bde38d9 100644 --- a/app/models/enterprises_block.rb +++ b/app/models/enterprises_block.rb @@ -12,22 +12,6 @@ class EnterprisesBlock < ProfileListBlock _('Enterprises') end - def footer - owner = self.owner - case owner - when Profile - proc do - link_to s_('enterprises|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises' - end - when Environment - proc do - link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' - end - else - '' - end - end - def profiles owner.enterprises end diff --git a/app/views/blocks/footers/enterprises.html.erb b/app/views/blocks/footers/enterprises.html.erb new file mode 100644 index 0000000..9bc49ab --- /dev/null +++ b/app/views/blocks/footers/enterprises.html.erb @@ -0,0 +1,5 @@ +<% if block.owner.is_a?(Profile) %> + <%= link_to s_('enterprises|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'enterprises' %> +<% elsif block.owner.is_a?(Environment) %> + <%= link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' %> +<% end %> diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb index 50b1b0e..27e3b40 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -27,32 +27,6 @@ class EnterprisesBlockTest < ActiveSupport::TestCase assert_same list, 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(:link_to).with('View all', :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(:link_to).with('View all', :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 - should 'count number of owner enterprises' do user = create_user('testuser').person @@ -71,3 +45,35 @@ class EnterprisesBlockTest < ActiveSupport::TestCase end end + +require 'boxes_helper' + +class EnterprisesBlockViewTest < ActionView::TestCase + include BoxesHelper + + should 'link to all enterprises for profile' do + profile = Profile.new + profile.identifier = 'theprofile' + block = EnterprisesBlock.new + block.expects(:owner).twice.returns(profile) + + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') + + render_block_footer(block) + end + + should 'link to all enterprises for environment' do + env = Environment.default + block = EnterprisesBlock.new + block.expects(:owner).twice.returns(env) + + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises') + render_block_footer(block) + end + + should 'give empty footer for unsupported owner type' do + block = EnterprisesBlock.new + block.expects(:owner).twice.returns(1) + assert_equal '', render_block_footer(block) + end +end -- libgit2 0.21.2