Commit 5f77c847f8c5d6636cb43e4960bd4d1c310acc17
1 parent
81bd1e5c
Exists in
master
and in
23 other branches
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
Showing
2 changed files
with
10 additions
and
2 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -28,8 +28,12 @@ class Article < ActiveRecord::Base |
| 28 | 28 | |
| 29 | 29 | # retrieves the latest +limit+ articles in profile +profile+, sorted from the |
| 30 | 30 | # most recent to the oldest. |
| 31 | + # | |
| 32 | + # If +profile+ is +nil+, then all profiles are searched for articles. | |
| 31 | 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 | 37 | end |
| 34 | 38 | |
| 35 | 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 | 138 | third = profile.articles.build(:name => 'third'); third.save! |
| 139 | 139 | forth = profile.articles.build(:name => 'forth'); forth.save! |
| 140 | 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 | 145 | assert_equal [first,second,third], Article.recent(profile, 3) |
| 143 | 146 | |
| 144 | 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 | 150 | end |
| 147 | 151 | |
| 148 | 152 | should 'provied proper descriptions' do | ... | ... |