Commit efcdb72260c8e2b33e26321ebd792290a5543a92
1 parent
20000188
Exists in
master
and in
29 other branches
ActionItem21: generating the HTML from Article instances
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@948 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
22 additions
and
0 deletions
Show diff stats
app/models/article.rb
@@ -9,4 +9,19 @@ class Article < ActiveRecord::Base | @@ -9,4 +9,19 @@ class Article < ActiveRecord::Base | ||
9 | 9 | ||
10 | acts_as_versioned | 10 | acts_as_versioned |
11 | 11 | ||
12 | + # retrives all articles belonging to the given +profile+ that are not | ||
13 | + # sub-articles of any other article. | ||
14 | + def Article.top_level_for(profile) | ||
15 | + self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ]) | ||
16 | + end | ||
17 | + | ||
18 | + # produces the HTML code that is to be displayed as this article's contents. | ||
19 | + # | ||
20 | + # The implementation in this class just provides the +body+ attribute as the | ||
21 | + # HTML. Other article types can override this method to provide customized | ||
22 | + # views of themselves. | ||
23 | + def to_html | ||
24 | + body | ||
25 | + end | ||
26 | + | ||
12 | end | 27 | end |
test/unit/article_test.rb
@@ -59,4 +59,11 @@ class ArticleTest < Test::Unit::TestCase | @@ -59,4 +59,11 @@ class ArticleTest < Test::Unit::TestCase | ||
59 | assert_equal 'another-name/child-article', Article.find(b.id).path | 59 | assert_equal 'another-name/child-article', Article.find(b.id).path |
60 | end | 60 | end |
61 | 61 | ||
62 | + should 'provide HTML version' do | ||
63 | + profile = create_user('testinguser').person | ||
64 | + a = Article.create!(:name => 'my article', :profile_id => profile.id) | ||
65 | + a.expects(:body).returns('the body of the article') | ||
66 | + assert_equal 'the body of the article', a.to_html | ||
67 | + end | ||
68 | + | ||
62 | end | 69 | end |