Sha256: 9b81b5cb056b3cb8ab19c3e8b734356030d86ef754f36039932fd2d8d566b5ed
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require "spec_helper" describe "pagination" do describe "using LIMIT and OFFSET" do with_model :PaginatedModel do table do |t| t.string :name end model do include PgSearch pg_search_scope :search_name, :against => :name def self.page(page_number) offset = (page_number - 1) * 2 limit(2).offset(offset) end end end it "is chainable before a search scope" do better = PaginatedModel.create!(:name => "foo foo bar") best = PaginatedModel.create!(:name => "foo foo foo") good = PaginatedModel.create!(:name => "foo bar bar") expect(PaginatedModel.page(1).search_name("foo")).to eq([best, better]) expect(PaginatedModel.page(2).search_name("foo")).to eq([good]) end it "is chainable after a search scope" do better = PaginatedModel.create!(:name => "foo foo bar") best = PaginatedModel.create!(:name => "foo foo foo") good = PaginatedModel.create!(:name => "foo bar bar") expect(PaginatedModel.search_name("foo").page(1)).to eq([best, better]) expect(PaginatedModel.search_name("foo").page(2)).to eq([good]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pg_search-2.1.4 | spec/integration/pagination_spec.rb |