From 55e713093f3a6f5a7c8b3ca29202feaff0c4234b Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 21 Jan 2009 15:53:54 -0300 Subject: [PATCH] ActionItem909: don't list UploadFile articles in the recent contents block --- app/models/article.rb | 13 +++++++------ test/unit/article_test.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 47a1731..9bb3245 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -89,12 +89,13 @@ class Article < ActiveRecord::Base def self.recent(limit) # FIXME this method is a horrible hack options = { :limit => limit, - :conditions => { - :advertise => true, - :public_article => true, - :published => true, - 'profiles.public_profile' => true - }, + :conditions => [ + "advertise = ? AND + public_article = ? AND + published = ? AND + profiles.public_profile = ? AND + (articles.type != ? OR articles.type is NULL)", true, true, true, true, 'UploadedFile' + ], :include => 'profile', :order => 'articles.updated_at desc, articles.id desc' } diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index b9e4315..9d86e1f 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -197,6 +197,16 @@ class ArticleTest < Test::Unit::TestCase assert_equal [ first, second ], Article.recent(2) end + should 'not show UploadedFile as recent' do + p = create_user('usr1').person + Article.destroy_all + + first = UploadedFile.new(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! + second = p.articles.build(:name => 'second'); second.save! + + assert_equal [ second ], Article.recent(nil) + end + should 'require that subclasses define description' do assert_raise NotImplementedError do Article.description -- libgit2 0.21.2