Files
simply_based/spec/pagination_spec.rb
GregandClaude Opus 4.8 45659c957e Port ancestry/trees to N1QL + soft-delete finders + pagination order
- Ancestry now runs on the materialized path (path_ids), no map/reduce: children
  = path_ids[len-2] = $id, subtree = $id IN path_ids, roots = ARRAY_LENGTH = 1.
  ancestry_spec: 31/31.
- Soft-delete-aware find_by/find_all_by: composite [key, deleted_at] keys compare
  element-wise so a nil component matches MISSING/NULL (non-deleted docs).
- Deterministic ordering: secondary sort by created_at; timestamps now microsecond
  precision so same-second creations paginate in creation order.
- by_property (namespaced) trees span all partitions when no value is given.
- Tagged the remaining CouchDB-mechanic specs :couchdb_only (view generation,
  design-doc maintenance, raw JS views, documented not-supported habtm cases).

Result: 403/403 applicable examples green on a clean run (one namespaced-ancestry
reparent edge is intermittently flaky). Up from 378/432.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 14:36:51 -05:00

79 lines
3.1 KiB
Ruby

require 'spec_helper'
RSpec.describe 'Pagination' do
it "does not raise error when page and per_page are specified" do
expect{ User.all(page: 1, per_page: 2) }.not_to raise_error
end
it "respond to pagination methods" do
paginated = User.all(page: 1, per_page: 2 )
paginated.current_page.should eq 1
paginated.num_pages.should eq 1
paginated.per_page.should eq 2
end
it "respond to modified pagination methods" do
paginated = Comment.all(page: 1, per_page: 2 )
paginated.current_page_modified.should eq 1
paginated.num_pages_modified.should eq 1
paginated.per_page_modified.should eq 2
end
it "display individual objects on pages with per_page is one" do
u1 = User.create(title: 'user1', created_at: Time.now )
u2 = User.create(title: 'user2', created_at: Time.now + 5.minutes )
u3 = User.create(title: 'user3', created_at: Time.now + 10.minutes )
User.all.should eq [u1, u2, u3] # normal behaviour
User.all(per_page: 1).first.should eq u1 # default to page 1
User.all(page: 2, per_page: 1).first.should eq u2
User.all(page: 3, per_page: 1).first.should eq u3
end
it "paginates all finder" do
15.times{|i| User.create(title: "user#{i}", created_at: i.minutes.from_now) }
User.count.should eq 15
result = User.all(page: 2, per_page: 2)
result.current_page.should eq 2
result.per_page.should eq 2
result.map(&:title).sort.should eq ['user2', 'user3']
result.total_entries.should eq 15
result.total_count.should eq 15
result.num_pages.should eq 8
end
it "paginate find_all_by finders" do
6.times{|i| User.create(title: "user#{i}", homepage: 'http://localhost/1') }
9.times{|i| User.create(title: "user#{i + 6}", homepage: 'http://localhost/2') }
User.count.should eq 15
User.find_all_by_homepage('http://localhost/1').size.should eq 6
result = User.find_all_by_homepage('http://localhost/1', page: 2, per_page: 2)
result.current_page.should eq 2
result.per_page.should eq 2
result.map(&:title).sort.should eq ['user2', 'user3']
result.total_entries.should eq 6
result.total_count.should eq 6
result.num_pages.should eq 3
end
it "paginate has and belongs to many view", :couchdb_only do
server = Server.create
for klass in 'A'..'Z'
server.add_network Network.create( klass: klass)
end
res = Network.with_pagination_options(startkey: [server.id], endkey: ["#{server.id}\u9999"], page: 1, per_page: 100, reduce: false, include_docs: true) do |o|
Network.database.view(Network.association_network_has_and_belongs_to_many_servers(o))
end
res.size.should eq 26
end
it "paginate has and belongs to many view with non trivial options", :couchdb_only do
server = Server.create
for klass in 'A'..'Z'
server.add_network Network.create( klass: klass)
end
res = Network.with_pagination_options(startkey: [server.id], endkey: ["#{server.id}\u9999"], page: 2, per_page: 3, reduce: false, include_docs: true) do |o|
Network.database.view(Network.association_network_has_and_belongs_to_many_servers(o))
end
res.size.should eq 3
end
end