Removed amount_pages calculation for the pagination collection, since it cannot be reliably calculated without a view

This commit is contained in:
John Wood 2009-08-20 08:05:39 -05:00 committed by Matt Aimonetti
parent b0dca70b02
commit feb09f9764
2 changed files with 0 additions and 18 deletions

View file

@ -1,14 +1,5 @@
module CouchRest
module Mixins
module PaginatedResults
def amount_pages
@amount_pages ||= 0
end
def amount_pages=(value)
@amount_pages = value
end
end
module Collection
def self.included(base)
@ -93,8 +84,6 @@ module CouchRest
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 30
attr_accessor :amount_pages
# Create a new CollectionProxy to represent the specified view. If a
# container class is specified, the proxy will create an object of the
# given type for each row that comes back from the view. If no
@ -122,11 +111,8 @@ module CouchRest
def paginate(options = {})
page, per_page = parse_options(options)
results = @database.view(@view_name, pagination_options(page, per_page))
@amount_pages ||= (results['total_rows'].to_f / per_page.to_f).ceil
remember_where_we_left_off(results, page)
results = convert_to_container_array(results)
results.extend(PaginatedResults)
results.amount_pages = @amount_pages
results
end

View file

@ -380,10 +380,6 @@ describe "ExtendedDocument views" do
a.should_not be_nil
end
end
it "should have the amount of paginated pages" do
articles = Article.by_date :key => Date.today
articles.paginate(:per_page => 3).amount_pages.should == 3
end
it "should provide a class method to access the collection directly" do
articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
:key => Date.today, :include_docs => true)