Commit 5f77c847f8c5d6636cb43e4960bd4d1c310acc17

Authored by AntonioTerceiro
1 parent 81bd1e5c

ActionItem141: documenting the possibility to search recent documents in all profiles



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1166 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article.rb
@@ -28,8 +28,12 @@ class Article < ActiveRecord::Base @@ -28,8 +28,12 @@ class Article < ActiveRecord::Base
28 28
29 # retrieves the latest +limit+ articles in profile +profile+, sorted from the 29 # retrieves the latest +limit+ articles in profile +profile+, sorted from the
30 # most recent to the oldest. 30 # most recent to the oldest.
  31 + #
  32 + # If +profile+ is +nil+, then all profiles are searched for articles.
31 def self.recent(profile, limit) 33 def self.recent(profile, limit)
32 - self.find(:all, :limit => limit, :order => 'created_on') 34 + options = { :limit => limit, :order => 'created_on' }
  35 + options[:conditions] = { :profile_id => profile.id } if profile
  36 + self.find(:all, options)
33 end 37 end
34 38
35 # produces the HTML code that is to be displayed as this article's contents. 39 # produces the HTML code that is to be displayed as this article's contents.
test/unit/article_test.rb
@@ -138,11 +138,15 @@ class ArticleTest < Test::Unit::TestCase @@ -138,11 +138,15 @@ class ArticleTest < Test::Unit::TestCase
138 third = profile.articles.build(:name => 'third'); third.save! 138 third = profile.articles.build(:name => 'third'); third.save!
139 forth = profile.articles.build(:name => 'forth'); forth.save! 139 forth = profile.articles.build(:name => 'forth'); forth.save!
140 fifth = profile.articles.build(:name => 'fifth'); fifth.save! 140 fifth = profile.articles.build(:name => 'fifth'); fifth.save!
  141 +
  142 + other_profile = create_user('otherpropfile').person
  143 + other_first = other_profile.articles.build(:name => 'first'); other_first.save!
141 144
142 assert_equal [first,second,third], Article.recent(profile, 3) 145 assert_equal [first,second,third], Article.recent(profile, 3)
143 146
144 assert_equal [first,second,third,forth,fifth], Article.recent(profile, 10) 147 assert_equal [first,second,third,forth,fifth], Article.recent(profile, 10)
145 - 148 +
  149 + assert_equal [first,second,third,forth,fifth,other_first], Article.recent(nil, 10)
146 end 150 end
147 151
148 should 'provied proper descriptions' do 152 should 'provied proper descriptions' do