From 8caa4d12e81e5cca82b3fa88f8223156edbdba06 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 8 Feb 2013 17:56:26 +1100 Subject: [PATCH] limit to recent comments --- app/controllers/comments_controller.rb | 1 + app/views/comments/index.html.haml | 2 +- spec/controllers/comments_controller_spec.rb | 1 + spec/views/comments/index.html.haml_spec.rb | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5190013de..53e453410 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -3,6 +3,7 @@ class CommentsController < ApplicationController # GET /comments.json def index @comments = Comment.all + @recent_comments = Comment.limit(100).order('created_at desc').all respond_to do |format| format.html # index.html.erb diff --git a/app/views/comments/index.html.haml b/app/views/comments/index.html.haml index 5cef3053d..a6a95d2d9 100644 --- a/app/views/comments/index.html.haml +++ b/app/views/comments/index.html.haml @@ -1,6 +1,6 @@ = content_for :title, "Recent comments" -- @comments.reverse.each do |comment| +- @recent_comments.each do |comment| %h2 Comment on = link_to comment.post.subject, comment.post diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 3d68ecf6c..a3b085553 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -14,6 +14,7 @@ describe CommentsController do comment = Comment.create! valid_attributes get :index, {} assigns(:comments).should eq([comment]) + assigns(:recent_comments).should eq([comment]) end end diff --git a/spec/views/comments/index.html.haml_spec.rb b/spec/views/comments/index.html.haml_spec.rb index cb3ab5fab..f2633c648 100644 --- a/spec/views/comments/index.html.haml_spec.rb +++ b/spec/views/comments/index.html.haml_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe "comments/index" do before(:each) do controller.stub(:current_user) { nil } - assign(:comments, [ + assign(:recent_comments, [ FactoryGirl.create(:comment), FactoryGirl.create(:comment, :body => 'ROFL') ])