From af0cec4454138cb1e889ab976e38371a5f9b0399 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Thu, 10 Mar 2016 10:30:12 -0300 Subject: [PATCH] Refactor RecentDocumentsBlock footer --- app/models/recent_documents_block.rb | 9 --------- app/views/blocks/footers/recent_documents.html.erb | 3 +++ test/unit/recent_documents_block_test.rb | 30 +++++++++++++++--------------- 3 files changed, 18 insertions(+), 24 deletions(-) create mode 100644 app/views/blocks/footers/recent_documents.html.erb diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index 2acf624..3f38542 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -22,15 +22,6 @@ class RecentDocumentsBlock < Block settings_items :limit, :type => :integer, :default => 5 - def footer - return nil unless self.owner.is_a?(Profile) - - profile = self.owner - proc do - link_to _('All content'), :profile => profile.identifier, :controller => 'profile', :action => 'sitemap' - end - end - def docs self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.get_limit, {}, false) end diff --git a/app/views/blocks/footers/recent_documents.html.erb b/app/views/blocks/footers/recent_documents.html.erb new file mode 100644 index 0000000..e1c9b71 --- /dev/null +++ b/app/views/blocks/footers/recent_documents.html.erb @@ -0,0 +1,3 @@ +<% if block.owner.is_a?(Profile) %> + <%= link_to _('All content'), :profile => block.owner.identifier, :controller => 'profile', :action => 'sitemap' %> +<% end %> diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index 5b70c50..e900a5f 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -57,21 +57,6 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase assert block.limit > 0 end - should 'display a link to sitemap with title "All content"' do - expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) - expects(:_).with('All content').returns('All content') - - instance_eval(&(block.footer)) - end - - should 'not display link to sitemap when owner is environment' do - block = RecentDocumentsBlock.new - box = mock - block.expects(:box).returns(box).at_least_once - box.expects(:owner).returns(Environment.new).at_least_once - assert_equal nil, block.footer - end - should 'be able to update display setting' do assert @block.update!(:display => 'always') @block.reload @@ -126,4 +111,19 @@ class RecentDocumentsBlockViewTest < ActionView::TestCase render_block_content(block) end + + should 'display a link to sitemap with title "All content"' do + ActionView::Base.any_instance.expects(:link_to).with('All content', :controller => 'profile', :action => 'sitemap', :profile => profile.identifier) + ActionView::Base.any_instance.expects(:_).with('All content').returns('All content') + + render_block_footer(block) + end + + should 'not display link to sitemap when owner is environment' do + block = RecentDocumentsBlock.new + box = mock + block.expects(:box).returns(box).at_least_once + box.expects(:owner).returns(Environment.new).at_least_once + assert_equal '', render_block_footer(block) + end end -- libgit2 0.21.2