diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 3fc8f5a90..5d81b2807 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -18,9 +18,8 @@ class NotificationsController < ApplicationController end 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") } respond_with @notifications end - end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index f4099a2d1..5eea8a67d 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -40,3 +40,4 @@ = object_link(note) %span.time= "#{t('ago', :time => time_ago_in_words(note.created_at))}" + = will_paginate @notifications diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 7a41f887f..152c98a8b 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -32,4 +32,18 @@ describe NotificationsController do Notification.find(note.id).unread.should == true 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