limit to recent comments

This commit is contained in:
Skud
2013-02-08 17:56:26 +11:00
parent d37e7a148d
commit 8caa4d12e8
4 changed files with 4 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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')
])