diff --git a/app/models/article.rb b/app/models/article.rb index ec1f7e6..6a1d038 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -77,7 +77,23 @@ class Article < ActiveRecord::Base # # Only includes articles where advertise == true def self.recent(limit) - options = { :limit => limit, :conditions => { :advertise => true, :public_article => true }, :order => 'created_at desc, articles.id desc' } + # FIXME this method is a horrible hack + options = { :limit => limit, + :conditions => { + :advertise => true, + :public_article => true, + :published => true, + 'profiles.public_profile' => true + }, + :include => 'profile', + :order => 'articles.created_at desc, articles.id desc' + } + if ( scoped_methods && scoped_methods.last && + scoped_methods.last[:find] && + scoped_methods.last[:find][:joins] && + scoped_methods.last[:find][:joins].index('profiles') ) + options.delete(:include) + end self.find(:all, options) end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 1c15c2c..3807680 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -137,6 +137,38 @@ class ArticleTest < Test::Unit::TestCase assert_equal [other_first, fifth, fourth, third, second, first], Article.recent(6) end + should 'not show private documents as recent' do + p = create_user('usr1').person + Article.destroy_all + + first = p.articles.build(:name => 'first', :public_article => true); first.save! + second = p.articles.build(:name => 'second', :public_article => false); second.save! + + assert_equal [ first ], Article.recent(nil) + end + + should 'not show unpublished documents as recent' do + p = create_user('usr1').person + Article.destroy_all + + first = p.articles.build(:name => 'first', :published => true); first.save! + second = p.articles.build(:name => 'second', :published => false); second.save! + + assert_equal [ first ], Article.recent(nil) + end + + should 'not show documents from a private profile as recent' do + p = create_user('usr1').person + p.public_profile = false + p.save! + Article.destroy_all + + first = p.articles.build(:name => 'first', :published => true); first.save! + second = p.articles.build(:name => 'second', :published => false); second.save! + + assert_equal [ ], Article.recent(nil) + end + should 'require that subclasses define description' do assert_raise NotImplementedError do Article.description -- libgit2 0.21.2