Skip to content
Extraits de code Groupes Projets
Valider 21463582 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Fix pagination on notifications page, it was getting all notifications for a user

parent e22eee36
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -19,8 +19,20 @@ class NotificationsController < ApplicationController ...@@ -19,8 +19,20 @@ class NotificationsController < ApplicationController
def index def index
@aspect = :notification @aspect = :notification
@notifications = Notification.find(:all, :conditions => {:recipient_id => current_user.id}, conditions = {:recipient_id => current_user.id}
:order => 'created_at desc', :include => [:target, {:actors => :profile}]).paginate :page => params[:page], :per_page => 25 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')) } @group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }
respond_with @notifications respond_with @notifications
end end
......
...@@ -43,16 +43,23 @@ describe NotificationsController do ...@@ -43,16 +43,23 @@ describe NotificationsController do
end end
describe '#index' do describe '#index' do
it 'paginates the notifications' do before do
26.times do 26.times do
Factory(:notification, :recipient => @user) Factory(:notification, :recipient => @user)
end end
end
it 'paginates the notifications' do
get :index get :index
assigns[:notifications].count.should == 25 assigns[:notifications].count.should == 25
get :index, :page => 2 get :index, :page => 2
assigns[:notifications].count.should == 1 assigns[:notifications].count.should == 1
end end
it 'eager loads the target' do
get :index
assigns[:notifications].each{ |note| note.loaded_target?.should be_true }
end
end end
end end
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter