Sha256: 564ea90503bf92aaf83217b438c683e762df8216b5841df211f6195c185143f0

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

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

18 entries across 18 versions & 1 rubygems

Version Path
pg_search-2.1.3 spec/integration/pagination_spec.rb
pg_search-2.1.2 spec/integration/pagination_spec.rb
pg_search-2.1.1 spec/integration/pagination_spec.rb
pg_search-2.1.0 spec/integration/pagination_spec.rb
pg_search-2.0.1 spec/integration/pagination_spec.rb
pg_search-2.0.0 spec/integration/pagination_spec.rb
pg_search-1.0.6 spec/integration/pagination_spec.rb
pg_search-1.0.5 spec/integration/pagination_spec.rb
pg_search-1.0.4 spec/integration/pagination_spec.rb
pg_search-1.0.3 spec/integration/pagination_spec.rb
pg_search-1.0.2 spec/integration/pagination_spec.rb
pg_search-1.0.1 spec/integration/pagination_spec.rb
pg_search-1.0.0 spec/integration/pagination_spec.rb
pg_search-0.7.9 spec/integration/pagination_spec.rb
pg_search-0.7.8 spec/integration/pagination_spec.rb
pg_search-0.7.7 spec/integration/pagination_spec.rb
pg_search-0.7.6 spec/integration/pagination_spec.rb
pg_search-0.7.5 spec/integration/pagination_spec.rb