diff --git a/app/controllers/public/home_controller.rb b/app/controllers/public/home_controller.rb index 2968a0b..69a56e6 100644 --- a/app/controllers/public/home_controller.rb +++ b/app/controllers/public/home_controller.rb @@ -1,7 +1,7 @@ class HomeController < PublicController def index - @articles = TextArticle.recent(nil, 10) + @articles = environment.recent_documents(10) end end diff --git a/app/models/article.rb b/app/models/article.rb index e94d4d8..acc01c1 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -26,13 +26,10 @@ class Article < ActiveRecord::Base self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ]) end - # 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) + # retrieves the latest +limit+ articles, sorted from the most recent to the + # oldest. + def self.recent(limit) options = { :limit => limit, :order => 'created_on' } - options[:conditions] = { :profile_id => profile.id } if profile self.find(:all, options) end diff --git a/app/models/profile.rb b/app/models/profile.rb index 27ce483..0700105 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -131,7 +131,7 @@ class Profile < ActiveRecord::Base # +limit+ is the maximum number of documents to be returned. It defaults to # 10. def recent_documents(limit = 10) - self.articles.recent(self, limit) + self.articles.recent(limit) end class << self diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index ce68b3b..da7255f 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -132,7 +132,7 @@ class ArticleTest < Test::Unit::TestCase end end - should 'search for recent documents for a given profile' do + should 'search for recent documents' do first = profile.articles.build(:name => 'first'); first.save! second = profile.articles.build(:name => 'second'); second.save! third = profile.articles.build(:name => 'third'); third.save! @@ -142,11 +142,8 @@ class ArticleTest < Test::Unit::TestCase 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) + assert_equal [first,second,third], Article.recent(3) + assert_equal [first,second,third,forth,fifth,other_first], Article.recent(10) end should 'provied proper descriptions' do -- libgit2 0.21.2