Permalink
Browse files

Adding most popular article

  • Loading branch information...
jcasimir committed Jan 11, 2012
1 parent f92eaf0 commit a5b72c004f420f550eee9dacc04c0528337a089c
Showing with 14 additions and 0 deletions.
  1. +4 −0 app/models/article.rb
  2. +10 −0 spec/models/articles_spec.rb
View
@@ -14,6 +14,10 @@ def tag_list
tags.collect{|t| t.name}.join(", ")
end
+ def self.most_popular
+ Article.all.sort_by{|a| a.comments.count}.last
+ end
+
def tag_list=(input)
#self.tags = []
names = input.split(",").collect{|text| text.strip.downcase}
@@ -62,6 +62,16 @@
end
end
+ context ".most_popular" do
+ it "returns the article with the most comments" do
+ articles = (0..5).collect{ Fabricate(:article) }
+ Comment.destroy_all
+ target = articles[rand(articles.length)]
+ Fabricate(:comment, :article => target)
+ Article.most_popular.should == target
+ end
+ end
+
context ".search_by_tag_name" do
context "when given no parameter" do
it "should return all the articles" do

0 comments on commit a5b72c0

Please sign in to comment.