Skip to content
This repository
Browse code

follow Kaminari 0.14.0 API change: num_pages => total_pages

  • Loading branch information...
commit 8aebe5f031994c43c3844f68f79c3c842d32d154 1 parent b4a365b
Akira Matsuda authored September 04, 2012
3  lib/couchrest/model/designs/view.rb
@@ -371,9 +371,10 @@ def limit_value
371 371
           query[:limit]
372 372
         end
373 373
 
374  
-        def num_pages
  374
+        def total_pages
375 375
           (total_count.to_f / limit_value).ceil
376 376
         end
  377
+        alias num_pages total_pages
377 378
 
378 379
         def current_page
379 380
           (offset_value / limit_value) + 1
13  spec/unit/designs/view_spec.rb
@@ -719,6 +719,15 @@ class DesignViewModel < CouchRest::Model::Base
719 719
           end
720 720
         end
721 721
 
  722
+        describe "#total_pages" do
  723
+          it "should use total_count and limit_value" do
  724
+            @obj.should_receive(:total_count).and_return(200)
  725
+            @obj.should_receive(:limit_value).and_return(25)
  726
+            @obj.total_pages.should eql(8)
  727
+          end
  728
+        end
  729
+
  730
+        # `num_pages` aliases to `total_pages` for compatibility for Kaminari '< 0.14'
722 731
         describe "#num_pages" do
723 732
           it "should use total_count and limit_value" do
724 733
             @obj.should_receive(:total_count).and_return(200)
@@ -887,7 +896,7 @@ class DesignViewModel < CouchRest::Model::Base
887 896
       end
888 897
 
889 898
       it "should calculate number of pages" do
890  
-        @view.num_pages.should eql(2)
  899
+        @view.total_pages.should eql(2)
891 900
       end
892 901
       it "should return results from first page" do
893 902
         @view.all.first.name.should eql('Judith')
@@ -900,7 +909,7 @@ class DesignViewModel < CouchRest::Model::Base
900 909
 
901 910
       it "should allow overriding per page count" do
902 911
         @view = @view.per(10)
903  
-        @view.num_pages.should eql(1)
  912
+        @view.total_pages.should eql(1)
904 913
         @view.all.last.name.should eql('Vilma')
905 914
       end
906 915
     end

0 notes on commit 8aebe5f

Please sign in to comment.
Something went wrong with that request. Please try again.