Commit 449502872be76c8eed45497c239ad9461ea9883c

Authored by AntonioTerceiro
1 parent 118042b5

ActionItem93: rewriting support for "recent documents"



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@993 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article.rb
... ... @@ -13,12 +13,18 @@ class Article < ActiveRecord::Base
13 13  
14 14 acts_as_versioned
15 15  
16   - # retrives all articles belonging to the given +profile+ that are not
  16 + # retrieves all articles belonging to the given +profile+ that are not
17 17 # sub-articles of any other article.
18   - def Article.top_level_for(profile)
  18 + def self.top_level_for(profile)
19 19 self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ])
20 20 end
21 21  
  22 + # retrieves the latest +limit+ articles in profile +profile+, sorted from the
  23 + # most recent to the oldest.
  24 + def self.recent(profile, limit)
  25 + self.find(:all, :limit => limit, :order => 'created_on')
  26 + end
  27 +
22 28 # produces the HTML code that is to be displayed as this article's contents.
23 29 #
24 30 # The implementation in this class just provides the +body+ attribute as the
... ...
test/unit/article_test.rb
... ... @@ -128,7 +128,19 @@ class ArticleTest < Test::Unit::TestCase
128 128 a.last_changed_by = Person.new
129 129 a.save!
130 130 end
  131 + end
131 132  
  133 + should 'search for recent documents for a given profile' do
  134 + first = profile.articles.build(:name => 'first'); first.save!
  135 + second = profile.articles.build(:name => 'second'); second.save!
  136 + third = profile.articles.build(:name => 'third'); third.save!
  137 + forth = profile.articles.build(:name => 'forth'); forth.save!
  138 + fifth = profile.articles.build(:name => 'fifth'); fifth.save!
  139 +
  140 + assert_equal [first,second,third], Article.recent(profile, 3)
  141 +
  142 + assert_equal [first,second,third,forth,fifth], Article.recent(profile, 10)
  143 +
132 144 end
133 145  
134 146 end
... ...