Commit 9b43a97d33f42397c5138acf20961abcb2dffbba

Authored by AntonioTerceiro
1 parent 8c270900

ActionItem18: creating block that lists recent documents of current profile



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@432 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/application_helper.rb
... ... @@ -99,6 +99,10 @@ module ApplicationHelper
99 99 link_to text, { :profile => profile }.merge(url), options
100 100 end
101 101  
  102 + def link_to_document(doc)
  103 + link_homepage(doc.title, doc.profile.identifier, :page => doc.full_path)
  104 + end
  105 +
102 106 # TODO: add the actual links
103 107 # TODO: test this helper
104 108 def user_links
... ...
app/models/recent_documents_block.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class RecentDocumentsBlock < Design::Block
  2 +
  3 + def content
  4 + lambda do
  5 + content_tag(
  6 + 'ul',
  7 + profile.recent_documents.map {|item| link_to_document(item) }.join("\n")
  8 + )
  9 + end
  10 + end
  11 +
  12 +end
... ...
test/unit/recent_documents_block_test.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class RecentDocumentsBlockTest < Test::Unit::TestCase
  4 +
  5 + # Replace this with your real tests.
  6 + def test_should_output_list_with_links_to_recent_documents
  7 + profile = mock
  8 + profile.stubs(:identifier).returns('a_test_profile')
  9 +
  10 + doc1 = mock
  11 + doc2 = mock
  12 + doc3 = mock
  13 + profile.expects(:recent_documents).returns([doc1, doc2, doc3])
  14 +
  15 + helper = mock
  16 + helper.expects(:profile).returns(profile)
  17 + helper.expects(:link_to_document).with(doc1).returns('doc1')
  18 + helper.expects(:link_to_document).with(doc2).returns('doc2')
  19 + helper.expects(:link_to_document).with(doc3).returns('doc3')
  20 + helper.expects(:content_tag).with('ul', "doc1\ndoc2\ndoc3").returns('the_tag')
  21 +
  22 + assert_equal('the_tag', helper.instance_eval(&RecentDocumentsBlock.new.content))
  23 + end
  24 +end
... ...