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
2 changed files with 20 additions and 4 deletions
|
@ -204,8 +204,9 @@ module CouchRest
|
||||||
def pagination_options(page, per_page)
|
def pagination_options(page, per_page)
|
||||||
view_options = @view_options.clone
|
view_options = @view_options.clone
|
||||||
if @last_key && @last_docid && @last_page == page - 1
|
if @last_key && @last_docid && @last_page == page - 1
|
||||||
view_options.delete(:key)
|
key = view_options.delete(:key)
|
||||||
options = { :startkey => @last_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
|
end_key = view_options[:endkey] || key
|
||||||
|
options = { :startkey => @last_key, :endkey => end_key, :startkey_docid => @last_docid, :limit => per_page, :skip => 1 }
|
||||||
else
|
else
|
||||||
options = { :limit => per_page, :skip => per_page * (page - 1) }
|
options = { :limit => per_page, :skip => per_page * (page - 1) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -348,12 +348,19 @@ describe "ExtendedDocument views" do
|
||||||
describe "with a collection" do
|
describe "with a collection" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
reset_test_db!
|
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"]
|
"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 = Article.new(:title => title, :date => Date.today)
|
||||||
a.save
|
a.save
|
||||||
end
|
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
|
end
|
||||||
require 'date'
|
require 'date'
|
||||||
it "should return a proxy that looks like an array of 7 Article objects" do
|
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.collection_proxy_for('Article', nil)}.should raise_error
|
||||||
lambda{Article.paginate(:design_doc => 'Article')}.should raise_error
|
lambda{Article.paginate(:design_doc => 'Article')}.should raise_error
|
||||||
end
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue