Fix pagination on notifications page, it was getting all notifications for a user
This commit is contained in:
parent
e22eee3669
commit
21463582d4
2 changed files with 23 additions and 4 deletions
|
|
@ -19,8 +19,20 @@ class NotificationsController < ApplicationController
|
|||
|
||||
def index
|
||||
@aspect = :notification
|
||||
@notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id},
|
||||
:order => 'created_at desc', :include => [:target, {:actors => :profile}]).paginate :page => params[:page], :per_page => 25
|
||||
conditions = {:recipient_id => current_user.id}
|
||||
page = params[:page] || 1
|
||||
@notifications = WillPaginate::Collection.create(page, 25, Notification.where(conditions).count ) do |pager|
|
||||
result = Notification.find(:all,
|
||||
:conditions => conditions,
|
||||
:order => 'created_at desc',
|
||||
:include => [:target, {:actors => :profile}],
|
||||
:limit => pager.per_page,
|
||||
:offset => pager.offset
|
||||
)
|
||||
|
||||
pager.replace(result)
|
||||
end
|
||||
|
||||
@group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }
|
||||
respond_with @notifications
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,16 +43,23 @@ describe NotificationsController do
|
|||
end
|
||||
|
||||
describe '#index' do
|
||||
it 'paginates the notifications' do
|
||||
before do
|
||||
26.times do
|
||||
Factory(:notification, :recipient => @user)
|
||||
end
|
||||
end
|
||||
|
||||
it 'paginates the notifications' do
|
||||
get :index
|
||||
assigns[:notifications].count.should == 25
|
||||
|
||||
get :index, :page => 2
|
||||
assigns[:notifications].count.should == 1
|
||||
end
|
||||
|
||||
it 'eager loads the target' do
|
||||
get :index
|
||||
assigns[:notifications].each{ |note| note.loaded_target?.should be_true }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue