Commit af0cec4454138cb1e889ab976e38371a5f9b0399

Authored by Rafael Reggiani Manzo
1 parent 4199280a

Refactor RecentDocumentsBlock footer

app/models/recent_documents_block.rb
@@ -22,15 +22,6 @@ class RecentDocumentsBlock < Block @@ -22,15 +22,6 @@ class RecentDocumentsBlock < Block
22 22
23 settings_items :limit, :type => :integer, :default => 5 23 settings_items :limit, :type => :integer, :default => 5
24 24
25 - def footer  
26 - return nil unless self.owner.is_a?(Profile)  
27 -  
28 - profile = self.owner  
29 - proc do  
30 - link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap'  
31 - end  
32 - end  
33 -  
34 def docs 25 def docs
35 self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false) 26 self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false)
36 end 27 end
app/views/blocks/footers/recent_documents.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<% if block.owner.is_a?(Profile) %>
  2 + <%= link_to _('All content'), :profile => block.owner.identifier, :controller => 'profile', :action => 'sitemap' %>
  3 +<% end %>
test/unit/recent_documents_block_test.rb
@@ -57,21 +57,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase @@ -57,21 +57,6 @@ class RecentDocumentsBlockTest &lt; ActiveSupport::TestCase
57 assert block.limit > 0 57 assert block.limit > 0
58 end 58 end
59 59
60 - should 'display a link to sitemap with title "All content"' do  
61 - expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)  
62 - expects(:_).with('All content').returns('All content')  
63 -  
64 - instance_eval(&(block.footer))  
65 - end  
66 -  
67 - should 'not display link to sitemap when owner is environment' do  
68 - block = RecentDocumentsBlock.new  
69 - box = mock  
70 - block.expects(:box).returns(box).at_least_once  
71 - box.expects(:owner).returns(Environment.new).at_least_once  
72 - assert_equal nil, block.footer  
73 - end  
74 -  
75 should 'be able to update display setting' do 60 should 'be able to update display setting' do
76 assert @block.update!(:display => 'always') 61 assert @block.update!(:display => 'always')
77 @block.reload 62 @block.reload
@@ -126,4 +111,19 @@ class RecentDocumentsBlockViewTest &lt; ActionView::TestCase @@ -126,4 +111,19 @@ class RecentDocumentsBlockViewTest &lt; ActionView::TestCase
126 111
127 render_block_content(block) 112 render_block_content(block)
128 end 113 end
  114 +
  115 + should 'display a link to sitemap with title "All content"' do
  116 + ActionView::Base.any_instance.expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier)
  117 + ActionView::Base.any_instance.expects(:_).with('All content').returns('All content')
  118 +
  119 + render_block_footer(block)
  120 + end
  121 +
  122 + should 'not display link to sitemap when owner is environment' do
  123 + block = RecentDocumentsBlock.new
  124 + box = mock
  125 + block.expects(:box).returns(box).at_least_once
  126 + box.expects(:owner).returns(Environment.new).at_least_once
  127 + assert_equal '', render_block_footer(block)
  128 + end
129 end 129 end