diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb index 7670c71..41c82f1 100644 --- a/app/models/recent_documents_block.rb +++ b/app/models/recent_documents_block.rb @@ -15,11 +15,11 @@ class RecentDocumentsBlock < Block settings_items :limit, :type => :integer, :default => 5 def content(args={}) - docs = self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false) + docs = self.docs title = self.title proc do block_title(title) + - content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) + content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) end end @@ -32,6 +32,10 @@ class RecentDocumentsBlock < Block end end + def docs + self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false) + end + def self.expire_on { :profile => [:article], :environment => [:article] } end diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb index 2708a03..f327ef0 100644 --- a/test/unit/recent_documents_block_test.rb +++ b/test/unit/recent_documents_block_test.rb @@ -31,14 +31,19 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase assert_not_equal Block.new.default_title, RecentDocumentsBlock.new.default_title end - should 'output list with links to recent documents' do - output = block.content - - assert_match /href=.*\/testinguser\/first/, output - assert_match /href=.*\/testinguser\/second/, output - assert_match /href=.*\/testinguser\/third/, output - assert_match /href=.*\/testinguser\/fourth/, output - assert_match /href=.*\/testinguser\/fifth/, output + should 'list recent documents' do + assert_equivalent block.docs, articles + end + + should 'link to documents' do + articles.each do |a| + expects(:link_to).with(a.title, a.url) + end + stubs(:block_title).returns("") + stubs(:content_tag).returns("") + stubs(:li).returns("") + + instance_eval(&block.content) end should 'respect the maximum number of items as configured' do -- libgit2 0.21.2