Sha256: 6ee9452131b735fa14d4dab300a88738a1be6bbf1e4f14c21805f5069212073c

Contents?: true

Size: 1.05 KB

Versions: 37

Compression:

Stored size: 1.05 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
    results.should == @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
    results.should == @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
    results.should == @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
    results.should == @posts[8,5]
  end
end

Version data entries

37 entries across 37 versions & 7 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/integration/test_pagination.rb
sunspot-2.2.7 spec/integration/test_pagination.rb
sunspot-2.2.6 spec/integration/test_pagination.rb
sunspot-2.2.5 spec/integration/test_pagination.rb
sunspot-2.2.4 spec/integration/test_pagination.rb
sunspot-2.2.3 spec/integration/test_pagination.rb
sunspot-2.2.2 spec/integration/test_pagination.rb
sunspot-2.2.1 spec/integration/test_pagination.rb
sunspot-2.2.0 spec/integration/test_pagination.rb
sunspot-2.1.1 spec/integration/test_pagination.rb
sunspot-2.1.0 spec/integration/test_pagination.rb
sunspot-2.0.0 spec/integration/test_pagination.rb
sunspot-2.0.0.pre.130115 spec/integration/test_pagination.rb
gojee-sunspot-2.0.5 spec/integration/test_pagination.rb
sunspot-2.0.0.pre.120925 spec/integration/test_pagination.rb
sunspot_solr-2.0.0.pre.120924 sunspot/spec/integration/test_pagination.rb
sunspot_rails-2.0.0.pre.120924 sunspot/spec/integration/test_pagination.rb
sunspot-2.0.0.pre.120924 sunspot/spec/integration/test_pagination.rb
gojee-sunspot-2.0.4 spec/integration/test_pagination.rb
gojee-sunspot-2.0.2 spec/integration/test_pagination.rb