diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0cd15ac..3fe7c40 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -99,6 +99,10 @@ module ApplicationHelper link_to text, { :profile => profile }.merge(url), options end + def link_to_document(doc) + link_homepage(doc.title, doc.profile.identifier, :page => doc.full_path) + end + # TODO: add the actual links # TODO: test this helper def user_links diff --git a/app/models/recent_documents_block.rb b/app/models/recent_documents_block.rb new file mode 100644 index 0000000..5e8f2a4 --- /dev/null +++ b/app/models/recent_documents_block.rb @@ -0,0 +1,12 @@ +class RecentDocumentsBlock < Design::Block + + def content + lambda do + content_tag( + 'ul', + profile.recent_documents.map {|item| link_to_document(item) }.join("\n") + ) + end + end + +end diff --git a/test/unit/recent_documents_block_test.rb b/test/unit/recent_documents_block_test.rb new file mode 100644 index 0000000..52fcccd --- /dev/null +++ b/test/unit/recent_documents_block_test.rb @@ -0,0 +1,24 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class RecentDocumentsBlockTest < Test::Unit::TestCase + + # Replace this with your real tests. + def test_should_output_list_with_links_to_recent_documents + profile = mock + profile.stubs(:identifier).returns('a_test_profile') + + doc1 = mock + doc2 = mock + doc3 = mock + profile.expects(:recent_documents).returns([doc1, doc2, doc3]) + + helper = mock + helper.expects(:profile).returns(profile) + helper.expects(:link_to_document).with(doc1).returns('doc1') + helper.expects(:link_to_document).with(doc2).returns('doc2') + helper.expects(:link_to_document).with(doc3).returns('doc3') + helper.expects(:content_tag).with('ul', "doc1\ndoc2\ndoc3").returns('the_tag') + + assert_equal('the_tag', helper.instance_eval(&RecentDocumentsBlock.new.content)) + end +end -- libgit2 0.21.2