From 1c58998201baa80d72742253c5acce93d8f1377c Mon Sep 17 00:00:00 2001 From: Kleber Shimabuku Date: Wed, 24 Sep 2014 11:16:27 -0300 Subject: [PATCH] Fix :num_pages options to keep backwards-compatible --- lib/kaminari/helpers/paginator.rb | 2 +- spec/helpers/action_view_extension_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/kaminari/helpers/paginator.rb b/lib/kaminari/helpers/paginator.rb index 03d6e42..a49f997 100644 --- a/lib/kaminari/helpers/paginator.rb +++ b/lib/kaminari/helpers/paginator.rb @@ -14,7 +14,7 @@ module Kaminari def initialize(template, options) #:nodoc: #FIXME for compatibility. remove num_pages at some time in the future options[:total_pages] ||= options[:num_pages] - options[:num_pages] ||= options[:total_pages] + options[:total_pages] = options[:num_pages] if options[:num_pages].present? @window_options = {}.tap do |h| h[:window] = options.delete(:window) || options.delete(:inner_window) || Kaminari.config.window diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index 74bb7cc..b44f21a 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -30,6 +30,18 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do end end + specify '#total_pages' do + @users = User.page(1).per(1) + result = helper.paginate @users, total_pages: 3, :params => {:controller => 'users', :action => 'index'} + expect(result.scan('').count).to eq(2) + end + + specify '#total_pages legacy' do + @users = User.page(1).per(1) + result = helper.paginate @users, num_pages: 3, :params => {:controller => 'users', :action => 'index'} + expect(result.scan('').count).to eq(2) + end + describe '#link_to_previous_page' do before do 60.times {|i| User.create! :name => "user#{i}"}