Commit c4c9643385fbb18f682b4e29a297aab9e7c8e588
1 parent
5e86ce9b
Exists in
master
and in
23 other branches
ActionItem158: adding folder class
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1785 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
48 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
| 1 | +class Folder < Article | ||
| 2 | + | ||
| 3 | + def self.short_description | ||
| 4 | + _('Folder') | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def self.description | ||
| 8 | + _('A folder, inside which you can put other articles') | ||
| 9 | + end | ||
| 10 | + | ||
| 11 | + # FIXME we should not need all this just to write a link | ||
| 12 | + include ActionView::Helpers::TagHelper | ||
| 13 | + include ActionView::Helpers::UrlHelper | ||
| 14 | + include ActionController::UrlWriter | ||
| 15 | + def to_html | ||
| 16 | + content_tag('ul', children.map { |child| content_tag('li', link_to(child.name, child.url)) }, :class => 'folder-listing') | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | +end |
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class FolderTest < ActiveSupport::TestCase | ||
| 4 | + | ||
| 5 | + should 'be an article' do | ||
| 6 | + assert_kind_of Article, Folder.new | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + should 'provide proper description' do | ||
| 10 | + Folder.stubs(:==).with(Article).returns(true) | ||
| 11 | + assert_not_equal Article.description, Folder.description | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + should 'provide proper short description' do | ||
| 15 | + Folder.stubs(:==).with(Article).returns(true) | ||
| 16 | + assert_not_equal Article.short_description, Folder.short_description | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + should 'list subitems as HTML content' do | ||
| 20 | + p = create_user('testuser').person | ||
| 21 | + f = Folder.create!(:profile => p, :name => 'f') | ||
| 22 | + f.children.create!(:profile => p, :name => 'onearticle') | ||
| 23 | + f.children.create!(:profile => p, :name => 'otherarticle') | ||
| 24 | + | ||
| 25 | + assert_match(/<li><a href=".*\/testuser\/f\/onearticle">onearticle<\/a><\/li>/, f.to_html) | ||
| 26 | + assert_match(/<li><a href=".*\/testuser\/f\/otherarticle">otherarticle<\/a><\/li>/, f.to_html) | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | +end |