Permalink
Browse files

follow Kaminari 0.14.0 API change: num_pages => total_pages

  • Loading branch information...
1 parent b4a365b commit 8aebe5f031994c43c3844f68f79c3c842d32d154 @amatsuda amatsuda committed Sep 4, 2012
Showing with 13 additions and 3 deletions.
  1. +2 −1 lib/couchrest/model/designs/view.rb
  2. +11 −2 spec/unit/designs/view_spec.rb
View
3 lib/couchrest/model/designs/view.rb
@@ -371,9 +371,10 @@ def limit_value
query[:limit]
end
- def num_pages
+ def total_pages
(total_count.to_f / limit_value).ceil
end
+ alias num_pages total_pages
def current_page
(offset_value / limit_value) + 1
View
13 spec/unit/designs/view_spec.rb
@@ -719,6 +719,15 @@ class DesignViewModel < CouchRest::Model::Base
end
end
+ describe "#total_pages" do
+ it "should use total_count and limit_value" do
+ @obj.should_receive(:total_count).and_return(200)
+ @obj.should_receive(:limit_value).and_return(25)
+ @obj.total_pages.should eql(8)
+ end
+ end
+
+ # `num_pages` aliases to `total_pages` for compatibility for Kaminari '< 0.14'
describe "#num_pages" do
it "should use total_count and limit_value" do
@obj.should_receive(:total_count).and_return(200)
@@ -887,7 +896,7 @@ class DesignViewModel < CouchRest::Model::Base
end
it "should calculate number of pages" do
- @view.num_pages.should eql(2)
+ @view.total_pages.should eql(2)
end
it "should return results from first page" do
@view.all.first.name.should eql('Judith')
@@ -900,7 +909,7 @@ class DesignViewModel < CouchRest::Model::Base
it "should allow overriding per page count" do
@view = @view.per(10)
- @view.num_pages.should eql(1)
+ @view.total_pages.should eql(1)
@view.all.last.name.should eql('Vilma')
end
end

0 comments on commit 8aebe5f

Please sign in to comment.