From 5f77c847f8c5d6636cb43e4960bd4d1c310acc17 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 2 Jan 2008 19:39:18 +0000 Subject: [PATCH] ActionItem141: documenting the possibility to search recent documents in all profiles --- app/models/article.rb | 6 +++++- test/unit/article_test.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index d049855..e94d4d8 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -28,8 +28,12 @@ class Article < ActiveRecord::Base # retrieves the latest +limit+ articles in profile +profile+, sorted from the # most recent to the oldest. + # + # If +profile+ is +nil+, then all profiles are searched for articles. def self.recent(profile, limit) - self.find(:all, :limit => limit, :order => 'created_on') + options = { :limit => limit, :order => 'created_on' } + options[:conditions] = { :profile_id => profile.id } if profile + self.find(:all, options) end # produces the HTML code that is to be displayed as this article's contents. diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 6162afe..ce68b3b 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -138,11 +138,15 @@ class ArticleTest < Test::Unit::TestCase third = profile.articles.build(:name => 'third'); third.save! forth = profile.articles.build(:name => 'forth'); forth.save! fifth = profile.articles.build(:name => 'fifth'); fifth.save! + + other_profile = create_user('otherpropfile').person + other_first = other_profile.articles.build(:name => 'first'); other_first.save! assert_equal [first,second,third], Article.recent(profile, 3) assert_equal [first,second,third,forth,fifth], Article.recent(profile, 10) - + + assert_equal [first,second,third,forth,fifth,other_first], Article.recent(nil, 10) end should 'provied proper descriptions' do -- libgit2 0.21.2