mirror of
				https://github.com/kaminari/kaminari.git
				synced 2022-11-09 13:44:37 -05:00 
			
		
		
		
	Restore backwards compatibility of #num_pages in #paginate
This commit is contained in:
		
							parent
							
								
									9bd5feb47e
								
							
						
					
					
						commit
						b206d89922
					
				
					 3 changed files with 6 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -15,7 +15,7 @@ module Kaminari
 | 
			
		|||
    # * <tt>:remote</tt> - Ajax? (false by default)
 | 
			
		||||
    # * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
 | 
			
		||||
    def paginate(scope, options = {}, &block)
 | 
			
		||||
      options[:total_pages] ||= scope.total_pages
 | 
			
		||||
      options[:total_pages] ||= options[:num_pages] || scope.total_pages
 | 
			
		||||
 | 
			
		||||
      paginator = Kaminari::Helpers::Paginator.new(self, options.reverse_merge(:current_page => scope.current_page, :per_page => scope.limit_value, :remote => false))
 | 
			
		||||
      paginator.to_s
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,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[:total_pages] = options[:num_pages] if options[:num_pages].present?
 | 
			
		||||
        options[:num_pages] ||= options[:total_pages]
 | 
			
		||||
 | 
			
		||||
        @window_options = {}.tap do |h|
 | 
			
		||||
          h[:window] = options.delete(:window) || options.delete(:inner_window) || Kaminari.config.window
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,18 +28,11 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do
 | 
			
		|||
      subject { helper.paginate @users, :views_prefix => "alternative/", :params => {:controller => 'users', :action => 'index'} }
 | 
			
		||||
      it { should eq("  <b>1</b>\n") }
 | 
			
		||||
    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('<span class="page">').count).to eq(2)
 | 
			
		||||
    context "num_pages: 3" do
 | 
			
		||||
      subject { helper.paginate @users, :num_pages => 3, :params => {:controller => 'users', :action => 'index'} }
 | 
			
		||||
      it { should match(/<a href="\/users\?page=3">Last/) }
 | 
			
		||||
    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('<span class="page">').count).to eq(2)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe '#link_to_previous_page' do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue