mirror of
				https://github.com/kaminari/kaminari.git
				synced 2022-11-09 13:44:37 -05:00 
			
		
		
		
	
							parent
							
								
									d10e2d39e0
								
							
						
					
					
						commit
						4a960b30ca
					
				
					 4 changed files with 30 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -12,6 +12,11 @@ module Kaminari
 | 
			
		|||
      model_name.human.downcase
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def reset #:nodoc:
 | 
			
		||||
      @total_count = nil
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def total_count(column_name = :all, options = {}) #:nodoc:
 | 
			
		||||
      # #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
 | 
			
		||||
      @total_count ||= begin
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,10 @@
 | 
			
		|||
module Kaminari
 | 
			
		||||
  module MongoidCriteriaMethods
 | 
			
		||||
    def initialize_copy(other) #:nodoc:
 | 
			
		||||
      @total_count = nil
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def entry_name
 | 
			
		||||
      model_name.human.downcase
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,6 +14,12 @@ if defined? ActiveRecord
 | 
			
		|||
        @books.each {|book| book.readers << @readers }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the scope is cloned" do
 | 
			
		||||
        it "should reset total_coount momoization" do
 | 
			
		||||
          User.page.tap(&:total_count).where(:name => 'author').total_count.should == 1
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the scope includes an order which references a generated column" do
 | 
			
		||||
        it "should successfully count the results" do
 | 
			
		||||
          @author.readers.by_read_count.page(1).total_count.should == @readers.size
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,20 @@
 | 
			
		|||
require 'spec_helper'
 | 
			
		||||
 | 
			
		||||
if defined? Mongoid
 | 
			
		||||
  describe Kaminari::MongoidCriteriaMethods do
 | 
			
		||||
    describe "#total_count" do
 | 
			
		||||
      before do
 | 
			
		||||
        2.times {|i| User.create!(:salary => i) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the scope is cloned" do
 | 
			
		||||
        it "should reset total_coount momoization" do
 | 
			
		||||
          User.page.tap(&:total_count).where(:salary => 1).total_count.should == 1
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe Kaminari::MongoidExtension do
 | 
			
		||||
    before(:each) do
 | 
			
		||||
      41.times do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue