Sha256: 981b4109cd472ac74dc43d120757b6718ce12401a8c354812a5187ed1c4d4dc3

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))

describe 'pagination' do
  before :all do
    Sunspot.remove_all
    @posts = (0..19).map do |i|
      Post.new(:blog_id => i)
    end
    Sunspot.index!(*@posts)
  end

  it 'should return all by default' do
    results = Sunspot.search(Post) { order_by :blog_id }.results
    expect(results).to eq(@posts)
  end

  it 'should return first page of 10' do
    results = Sunspot.search(Post) do
      order_by :blog_id
      paginate :page => 1, :per_page => 10
    end.results
    expect(results).to eq(@posts[0,10])
  end

  it 'should return second page of 10' do
    results = Sunspot.search(Post) do
      order_by :blog_id
      paginate :page => 2, :per_page => 10
    end.results
    expect(results).to eq(@posts[10,10])
  end

  it 'should return pages with offsets' do
    results = Sunspot.search(Post) do
      order_by :blog_id
      paginate :page => 2, :per_page => 5, :offset => 3
    end.results

    # page 1 is 3, 4, 5, 6, 7
    # page 2 is 8, 9, 10, 11, 12
    expect(results).to eq(@posts[8,5])
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sunspot-2.7.1 spec/integration/test_pagination.rb
sunspot-2.7.0 spec/integration/test_pagination.rb
sunspot-2.6.0 spec/integration/test_pagination.rb
sunspot-2.5.0 spec/integration/test_pagination.rb
sunspot-2.4.0 spec/integration/test_pagination.rb
sunspot-2.3.0 spec/integration/test_pagination.rb
sunspot-2.2.8 spec/integration/test_pagination.rb