diff --git a/app/models/folder.rb b/app/models/folder.rb new file mode 100644 index 0000000..1e1ed9c --- /dev/null +++ b/app/models/folder.rb @@ -0,0 +1,19 @@ +class Folder < Article + + def self.short_description + _('Folder') + end + + def self.description + _('A folder, inside which you can put other articles') + end + + # FIXME we should not need all this just to write a link + include ActionView::Helpers::TagHelper + include ActionView::Helpers::UrlHelper + include ActionController::UrlWriter + def to_html + content_tag('ul', children.map { |child| content_tag('li', link_to(child.name, child.url)) }, :class => 'folder-listing') + end + +end diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb new file mode 100644 index 0000000..ac7ad5a --- /dev/null +++ b/test/unit/folder_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FolderTest < ActiveSupport::TestCase + + should 'be an article' do + assert_kind_of Article, Folder.new + end + + should 'provide proper description' do + Folder.stubs(:==).with(Article).returns(true) + assert_not_equal Article.description, Folder.description + end + + should 'provide proper short description' do + Folder.stubs(:==).with(Article).returns(true) + assert_not_equal Article.short_description, Folder.short_description + end + + should 'list subitems as HTML content' do + p = create_user('testuser').person + f = Folder.create!(:profile => p, :name => 'f') + f.children.create!(:profile => p, :name => 'onearticle') + f.children.create!(:profile => p, :name => 'otherarticle') + + assert_match(/