Commit a2e56267d6acc40366dc78e7476b4911b493842a

Authored by Victor Costa
1 parent 19ac9d93

rails3: fix recent_documents_block_test

Apply again recet_documents_block fixes done in commit 54a29b33
app/models/recent_documents_block.rb
... ... @@ -15,11 +15,11 @@ class RecentDocumentsBlock < Block
15 15 settings_items :limit, :type => :integer, :default => 5
16 16  
17 17 def content(args={})
18   - docs = self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false)
  18 + docs = self.docs
19 19 title = self.title
20 20 proc do
21 21 block_title(title) +
22   - content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
  22 + content_tag('ul', docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
23 23 end
24 24 end
25 25  
... ... @@ -32,6 +32,10 @@ class RecentDocumentsBlock < Block
32 32 end
33 33 end
34 34  
  35 + def docs
  36 + self.limit.nil? ? owner.recent_documents(nil, {}, false) : owner.recent_documents(self.limit, {}, false)
  37 + end
  38 +
35 39 def self.expire_on
36 40 { :profile => [:article], :environment => [:article] }
37 41 end
... ...
test/unit/recent_documents_block_test.rb
... ... @@ -31,14 +31,19 @@ class RecentDocumentsBlockTest < ActiveSupport::TestCase
31 31 assert_not_equal Block.new.default_title, RecentDocumentsBlock.new.default_title
32 32 end
33 33  
34   - should 'output list with links to recent documents' do
35   - output = block.content
36   -
37   - assert_match /href=.*\/testinguser\/first/, output
38   - assert_match /href=.*\/testinguser\/second/, output
39   - assert_match /href=.*\/testinguser\/third/, output
40   - assert_match /href=.*\/testinguser\/fourth/, output
41   - assert_match /href=.*\/testinguser\/fifth/, output
  34 + should 'list recent documents' do
  35 + assert_equivalent block.docs, articles
  36 + end
  37 +
  38 + should 'link to documents' do
  39 + articles.each do |a|
  40 + expects(:link_to).with(a.title, a.url)
  41 + end
  42 + stubs(:block_title).returns("")
  43 + stubs(:content_tag).returns("")
  44 + stubs(:li).returns("")
  45 +
  46 + instance_eval(&block.content)
42 47 end
43 48  
44 49 should 'respect the maximum number of items as configured' do
... ...