Removed amount_pages calculation for the pagination collection, since it cannot be reliably calculated without a view
This commit is contained in:
parent
b0dca70b02
commit
feb09f9764
|
@ -1,14 +1,5 @@
|
||||||
module CouchRest
|
module CouchRest
|
||||||
module Mixins
|
module Mixins
|
||||||
module PaginatedResults
|
|
||||||
def amount_pages
|
|
||||||
@amount_pages ||= 0
|
|
||||||
end
|
|
||||||
def amount_pages=(value)
|
|
||||||
@amount_pages = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module Collection
|
module Collection
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
@ -93,8 +84,6 @@ module CouchRest
|
||||||
DEFAULT_PAGE = 1
|
DEFAULT_PAGE = 1
|
||||||
DEFAULT_PER_PAGE = 30
|
DEFAULT_PER_PAGE = 30
|
||||||
|
|
||||||
attr_accessor :amount_pages
|
|
||||||
|
|
||||||
# Create a new CollectionProxy to represent the specified view. If a
|
# Create a new CollectionProxy to represent the specified view. If a
|
||||||
# container class is specified, the proxy will create an object of the
|
# 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
|
# given type for each row that comes back from the view. If no
|
||||||
|
@ -122,11 +111,8 @@ module CouchRest
|
||||||
def paginate(options = {})
|
def paginate(options = {})
|
||||||
page, per_page = parse_options(options)
|
page, per_page = parse_options(options)
|
||||||
results = @database.view(@view_name, pagination_options(page, per_page))
|
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)
|
remember_where_we_left_off(results, page)
|
||||||
results = convert_to_container_array(results)
|
results = convert_to_container_array(results)
|
||||||
results.extend(PaginatedResults)
|
|
||||||
results.amount_pages = @amount_pages
|
|
||||||
results
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -380,10 +380,6 @@ describe "ExtendedDocument views" do
|
||||||
a.should_not be_nil
|
a.should_not be_nil
|
||||||
end
|
end
|
||||||
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
|
it "should provide a class method to access the collection directly" do
|
||||||
articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
|
articles = Article.collection_proxy_for('Article', 'by_date', :descending => true,
|
||||||
:key => Date.today, :include_docs => true)
|
:key => Date.today, :include_docs => true)
|
||||||
|
|
Loading…
Reference in a new issue