diff --git a/app/models/article.rb b/app/models/article.rb index 4f564d8..796c34e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -444,6 +444,7 @@ class Article < ActiveRecord::Base named_scope :galleries, :conditions => { :type => 'Gallery' } named_scope :images, :conditions => { :is_image => true } named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] + named_scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } named_scope :more_popular, :order => 'hits DESC' named_scope :more_comments, :order => "comments_count DESC" diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 6838b6c..97eeb3c 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1744,4 +1744,17 @@ class ArticleTest < ActiveSupport::TestCase assert_nil article.author_id end + should 'return articles with specific types' do + Article.delete_all + + c1 = fast_create(TinyMceArticle, :name => 'Testing article 1', :body => 'Article body 1', :profile_id => profile.id) + c2 = fast_create(TextArticle, :name => 'Testing article 2', :body => 'Article body 2', :profile_id => profile.id) + c3 = fast_create(Event, :name => 'Testing article 3', :body => 'Article body 3', :profile_id => profile.id) + c4 = fast_create(RssFeed, :name => 'Testing article 4', :body => 'Article body 4', :profile_id => profile.id) + c5 = fast_create(TextileArticle, :name => 'Testing article 5', :body => 'Article body 5', :profile_id => profile.id) + + assert_equivalent [c1,c2], Article.with_types(['TinyMceArticle', 'TextArticle']) + assert_equivalent [c3], Article.with_types(['Event']) + end + end -- libgit2 0.21.2