Commit 55e713093f3a6f5a7c8b3ca29202feaff0c4234b
Committed by
Antonio Terceiro
1 parent
740e8524
Exists in
master
and in
23 other branches
ActionItem909: don't list UploadFile articles in the recent contents block
Showing
2 changed files
with
17 additions
and
6 deletions
Show diff stats
app/models/article.rb
| @@ -89,12 +89,13 @@ class Article < ActiveRecord::Base | @@ -89,12 +89,13 @@ class Article < ActiveRecord::Base | ||
| 89 | def self.recent(limit) | 89 | def self.recent(limit) |
| 90 | # FIXME this method is a horrible hack | 90 | # FIXME this method is a horrible hack |
| 91 | options = { :limit => limit, | 91 | options = { :limit => limit, |
| 92 | - :conditions => { | ||
| 93 | - :advertise => true, | ||
| 94 | - :public_article => true, | ||
| 95 | - :published => true, | ||
| 96 | - 'profiles.public_profile' => true | ||
| 97 | - }, | 92 | + :conditions => [ |
| 93 | + "advertise = ? AND | ||
| 94 | + public_article = ? AND | ||
| 95 | + published = ? AND | ||
| 96 | + profiles.public_profile = ? AND | ||
| 97 | + (articles.type != ? OR articles.type is NULL)", true, true, true, true, 'UploadedFile' | ||
| 98 | + ], | ||
| 98 | :include => 'profile', | 99 | :include => 'profile', |
| 99 | :order => 'articles.updated_at desc, articles.id desc' | 100 | :order => 'articles.updated_at desc, articles.id desc' |
| 100 | } | 101 | } |
test/unit/article_test.rb
| @@ -197,6 +197,16 @@ class ArticleTest < Test::Unit::TestCase | @@ -197,6 +197,16 @@ class ArticleTest < Test::Unit::TestCase | ||
| 197 | assert_equal [ first, second ], Article.recent(2) | 197 | assert_equal [ first, second ], Article.recent(2) |
| 198 | end | 198 | end |
| 199 | 199 | ||
| 200 | + should 'not show UploadedFile as recent' do | ||
| 201 | + p = create_user('usr1').person | ||
| 202 | + Article.destroy_all | ||
| 203 | + | ||
| 204 | + first = UploadedFile.new(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! | ||
| 205 | + second = p.articles.build(:name => 'second'); second.save! | ||
| 206 | + | ||
| 207 | + assert_equal [ second ], Article.recent(nil) | ||
| 208 | + end | ||
| 209 | + | ||
| 200 | should 'require that subclasses define description' do | 210 | should 'require that subclasses define description' do |
| 201 | assert_raise NotImplementedError do | 211 | assert_raise NotImplementedError do |
| 202 | Article.description | 212 | Article.description |