Merge remote branch 'nickvdb/763-notifications-paginate'

This commit is contained in:
Raphael 2011-01-04 16:18:46 -08:00
commit 83d6b95c46
3 changed files with 16 additions and 2 deletions

View file

@ -18,9 +18,8 @@ class NotificationsController < ApplicationController
end end
def index def index
@notifications = Notification.for(current_user).limit(25) @notifications = Notification.for(current_user).paginate :page => params[:page], :per_page => 25
@group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } @group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") }
respond_with @notifications respond_with @notifications
end end
end end

View file

@ -40,3 +40,4 @@
= object_link(note) = object_link(note)
%span.time= "#{t('ago', :time => time_ago_in_words(note.created_at))}" %span.time= "#{t('ago', :time => time_ago_in_words(note.created_at))}"
= will_paginate @notifications

View file

@ -32,4 +32,18 @@ describe NotificationsController do
Notification.find(note.id).unread.should == true Notification.find(note.id).unread.should == true
end end
end end
describe '#index' do
it 'paginates the notifications' do
35.times do
Notification.create(:user_id => user.id)
end
get :index
assigns[:notifications].should == Notification.all(:user_id => user.id, :limit => 25)
get :index, :page => 2
assigns[:notifications].should == Notification.all(:user_id => user.id, :offset => 25, :limit => 25)
end
end
end end