From cbb50df8d04a414699f06eb190a25e40b53b85dd Mon Sep 17 00:00:00 2001 From: Anthony Atkinson Date: Sat, 25 Jul 2015 13:18:30 -0400 Subject: [PATCH] Resolved #562 - Pagination of notifications. --- Gemfile | 3 +++ Gemfile.lock | 8 ++++++++ app/controllers/notifications_controller.rb | 2 +- app/views/notifications/index.html.haml | 2 ++ spec/features/notifications_spec.rb | 21 +++++++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index bb774b703..ffd1da341 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,9 @@ gem 'ruby-units' # for unit conversion gem 'comfortable_mexican_sofa', '~> 1.12.0' # content management system +gem 'kaminari' # pagination +gem 'bootstrap-kaminari-views' # bootstrap views for kaminari + # vendored activemerchant for testing- needed for bogus paypal # gateway monkeypatch gem 'activemerchant', '1.33.0', diff --git a/Gemfile.lock b/Gemfile.lock index fef7b8258..261a40185 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,9 @@ GEM bonsai-elasticsearch-rails (0.0.4) bootstrap-datepicker-rails (1.3.0.2) railties (>= 3.0) + bootstrap-kaminari-views (0.0.5) + kaminari (>= 0.13) + rails (>= 3.1) bootstrap-sass (3.3.3) autoprefixer-rails (>= 5.0.0.1) sass (>= 3.2.19) @@ -216,6 +219,9 @@ GEM railties (>= 3.2) sprockets-rails json (1.8.2) + kaminari (0.16.3) + actionpack (>= 3.0.0) + activesupport (>= 3.0.0) kgio (2.9.2) kramdown (1.5.0) launchy (2.4.3) @@ -402,6 +408,7 @@ DEPENDENCIES bluecloth bonsai-elasticsearch-rails bootstrap-datepicker-rails + bootstrap-kaminari-views bundler (>= 1.1.5) byebug cancancan (~> 1.9) @@ -430,6 +437,7 @@ DEPENDENCIES jquery-rails jquery-ui-rails (~> 5.0.2) js-routes + kaminari leaflet-markercluster-rails leaflet-rails less (~> 2.5.0) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 4608d3f99..f1934ded3 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -5,7 +5,7 @@ class NotificationsController < ApplicationController # GET /notifications def index - @notifications = Notification.where(recipient_id: current_member) + @notifications = Notification.where(recipient_id: current_member).page(params[:page]) respond_to do |format| format.html # index.html.erb diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index d5b373606..e5352ad26 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,6 +1,7 @@ - content_for :title, "Inbox" - if @notifications.size > 0 + = paginate @notifications, theme: 'twitter-bootstrap-3' %table.table.table-striped %tr %th From @@ -28,5 +29,6 @@ %strong= n.created_at %td = link_to 'Delete', n, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + = paginate @notifications, theme: 'twitter-bootstrap-3' - else You have no messages. diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 5135a1c72..bb1be5907 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -22,4 +22,25 @@ feature "Notifications", :js => true do expect(page).to have_content "Message was successfully sent" end end + + describe 'pagination' do + before do + 34.times { FactoryGirl.create :notification, recipient: recipient } + login_as recipient + visit notifications_path + end + + it 'has page navigation' do + expect(page).to have_selector 'a[rel="next"]' + end + + it 'paginates at 30 notifications per page' do + expect(page).to have_selector 'tr', count: 31 + end + + it 'navigates pages' do + first('a[rel="next"]').click + expect(page).to have_selector 'tr', count: 5 + end + end end \ No newline at end of file