Commit c11b2c876d4beded5263c9ee1a00e359fa0ad851

Authored by Rafael Reggiani Manzo
1 parent ce075450

Refactor EnterprisesBlock footer into helper/view

app/models/enterprises_block.rb
... ... @@ -12,22 +12,6 @@ class EnterprisesBlock < ProfileListBlock
12 12 _('Enterprises')
13 13 end
14 14  
15   - def footer
16   - owner = self.owner
17   - case owner
18   - when Profile
19   - proc do
20   - link_to s_('enterprises|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'
21   - end
22   - when Environment
23   - proc do
24   - link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'
25   - end
26   - else
27   - ''
28   - end
29   - end
30   -
31 15 def profiles
32 16 owner.enterprises
33 17 end
... ...
app/views/blocks/footers/enterprises.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<% if block.owner.is_a?(Profile) %>
  2 + <%= link_to s_('enterprises|View all'), :profile => block.owner.identifier, :controller => 'profile', :action => 'enterprises' %>
  3 +<% elsif block.owner.is_a?(Environment) %>
  4 + <%= link_to s_('enterprises|View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' %>
  5 +<% end %>
... ...
test/unit/enterprises_block_test.rb
... ... @@ -27,32 +27,6 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase
27 27 assert_same list, block.profiles
28 28 end
29 29  
30   - should 'link to all enterprises for profile' do
31   - profile = Profile.new
32   - profile.expects(:identifier).returns('theprofile')
33   - block = EnterprisesBlock.new
34   - block.expects(:owner).returns(profile)
35   -
36   - expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')
37   -
38   - instance_eval(&block.footer)
39   - end
40   -
41   - should 'link to all enterprises for environment' do
42   - env = Environment.default
43   - block = EnterprisesBlock.new
44   - block.expects(:owner).returns(env)
45   -
46   - expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises')
47   - instance_eval(&block.footer)
48   - end
49   -
50   - should 'give empty footer for unsupported owner type' do
51   - block = EnterprisesBlock.new
52   - block.expects(:owner).returns(1)
53   - assert_equal '', block.footer
54   - end
55   -
56 30 should 'count number of owner enterprises' do
57 31 user = create_user('testuser').person
58 32  
... ... @@ -71,3 +45,35 @@ class EnterprisesBlockTest &lt; ActiveSupport::TestCase
71 45 end
72 46  
73 47 end
  48 +
  49 +require 'boxes_helper'
  50 +
  51 +class EnterprisesBlockViewTest < ActionView::TestCase
  52 + include BoxesHelper
  53 +
  54 + should 'link to all enterprises for profile' do
  55 + profile = Profile.new
  56 + profile.identifier = 'theprofile'
  57 + block = EnterprisesBlock.new
  58 + block.expects(:owner).twice.returns(profile)
  59 +
  60 + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')
  61 +
  62 + render_block_footer(block)
  63 + end
  64 +
  65 + should 'link to all enterprises for environment' do
  66 + env = Environment.default
  67 + block = EnterprisesBlock.new
  68 + block.expects(:owner).twice.returns(env)
  69 +
  70 + ActionView::Base.any_instance.expects(:link_to).with('View all', :controller => 'search', :action => 'assets', :asset => 'enterprises')
  71 + render_block_footer(block)
  72 + end
  73 +
  74 + should 'give empty footer for unsupported owner type' do
  75 + block = EnterprisesBlock.new
  76 + block.expects(:owner).twice.returns(1)
  77 + assert_equal '', render_block_footer(block)
  78 + end
  79 +end
... ...