diff --git a/app/models/article.rb b/app/models/article.rb index 08e9ac3..e25e015 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -9,4 +9,19 @@ class Article < ActiveRecord::Base acts_as_versioned + # retrives all articles belonging to the given +profile+ that are not + # sub-articles of any other article. + def Article.top_level_for(profile) + self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ]) + end + + # produces the HTML code that is to be displayed as this article's contents. + # + # The implementation in this class just provides the +body+ attribute as the + # HTML. Other article types can override this method to provide customized + # views of themselves. + def to_html + body + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index db16cb8..6e8e865 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -59,4 +59,11 @@ class ArticleTest < Test::Unit::TestCase assert_equal 'another-name/child-article', Article.find(b.id).path end + should 'provide HTML version' do + profile = create_user('testinguser').person + a = Article.create!(:name => 'my article', :profile_id => profile.id) + a.expects(:body).returns('the body of the article') + assert_equal 'the body of the article', a.to_html + end + end -- libgit2 0.21.2