added amount_pages to a paginated collection

This commit is contained in:
Matt Aimonetti 2009-07-20 15:52:14 -07:00
parent 7a124c522b
commit 413a7602e8
3 changed files with 26 additions and 1 deletions

View file

@ -1,3 +1,20 @@
== 0.40
=== Notes
This release slightly modifies the API and if you were using a previous version of CouchRest,
you will need to make the following modifications.
* Major enhancements
*
* Minor enhancements
* Added #amount_pages to a paginated collection. (Matt Aimonetti)
== 0.31
* Major enhancements

View file

@ -83,6 +83,8 @@ 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
@ -110,7 +112,8 @@ module CouchRest
# See Collection.paginate
def paginate(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)
convert_to_container_array(results)
end

View file

@ -365,6 +365,11 @@ describe "ExtendedDocument views" do
articles.paginated_each(:per_page => 3) do |a|
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)
articles.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,