Fixed a bug in the pagination code that caused it to paginate over records outside of the scope of the view parameters.
This commit is contained in:
parent
2057e59777
commit
b0dca70b02
|
@ -204,8 +204,9 @@ module CouchRest
|
|||
def pagination_options(page, per_page)
|
||||
view_options = @view_options.clone
|
||||
if @last_key && @last_docid && @last_page == page - 1
|
||||
view_options.delete(:key)
|
||||
options = { :startkey => @last_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
|
||||
key = view_options.delete(:key)
|
||||
end_key = view_options[:endkey] || key
|
||||
options = { :startkey => @last_key, :endkey => end_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
|
||||
else
|
||||
options = { :limit => per_page, :skip => per_page * (page - 1) }
|
||||
end
|
||||
|
|
|
@ -348,12 +348,19 @@ describe "ExtendedDocument views" do
|
|||
describe "with a collection" do
|
||||
before(:all) do
|
||||
reset_test_db!
|
||||
@titles = ["very uniq one", "really interesting", "some fun",
|
||||
titles = ["very uniq one", "really interesting", "some fun",
|
||||
"really awesome", "crazy bob", "this rocks", "super rad"]
|
||||
@titles.each_with_index do |title,i|
|
||||
titles.each_with_index do |title,i|
|
||||
a = Article.new(:title => title, :date => Date.today)
|
||||
a.save
|
||||
end
|
||||
|
||||
titles = ["yesterday very uniq one", "yesterday really interesting", "yesterday some fun",
|
||||
"yesterday really awesome", "yesterday crazy bob", "yesterday this rocks"]
|
||||
titles.each_with_index do |title,i|
|
||||
a = Article.new(:title => title, :date => Date.today - 1)
|
||||
a.save
|
||||
end
|
||||
end
|
||||
require 'date'
|
||||
it "should return a proxy that looks like an array of 7 Article objects" do
|
||||
|
@ -421,6 +428,14 @@ describe "ExtendedDocument views" do
|
|||
lambda{Article.collection_proxy_for('Article', nil)}.should raise_error
|
||||
lambda{Article.paginate(:design_doc => 'Article')}.should raise_error
|
||||
end
|
||||
it "should be able to span multiple keys" do
|
||||
articles = Article.by_date :startkey => Date.today, :endkey => Date.today - 1
|
||||
articles.paginate(:page => 1, :per_page => 3).size.should == 3
|
||||
articles.paginate(:page => 2, :per_page => 3).size.should == 3
|
||||
articles.paginate(:page => 3, :per_page => 3).size.should == 3
|
||||
articles.paginate(:page => 4, :per_page => 3).size.should == 3
|
||||
articles.paginate(:page => 5, :per_page => 3).size.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue