Sha256: 6a4d79b27174782303a8addac16afa65ac15c8711fd97b225737482b364b175c

Contents?: true

Size: 1.9 KB

Versions: 34

Compression:

Stored size: 1.9 KB

Contents

require_relative "test_helper"

class PaginationTest < Minitest::Test
  def test_limit
    store_names ["Product A", "Product B", "Product C", "Product D"]
    assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
  end

  def test_no_limit
    names = 20.times.map { |i| "Product #{i}" }
    store_names names
    assert_search "product", names
  end

  def test_offset
    store_names ["Product A", "Product B", "Product C", "Product D"]
    assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
  end

  def test_pagination
    store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
    products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
    assert_equal ["Product D", "Product E"], products.map(&:name)
    assert_equal "product", products.entry_name
    assert_equal 2, products.current_page
    assert_equal 1, products.padding
    assert_equal 2, products.per_page
    assert_equal 2, products.size
    assert_equal 2, products.length
    assert_equal 3, products.total_pages
    assert_equal 6, products.total_count
    assert_equal 6, products.total_entries
    assert_equal 2, products.limit_value
    assert_equal 3, products.offset_value
    assert_equal 3, products.offset
    assert_equal 3, products.next_page
    assert_equal 1, products.previous_page
    assert_equal 1, products.prev_page
    assert !products.first_page?
    assert !products.last_page?
    assert !products.empty?
    assert !products.out_of_range?
    assert products.any?
  end

  def test_pagination_nil_page
    store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
    products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
    assert_equal ["Product A", "Product B"], products.map(&:name)
    assert_equal 1, products.current_page
    assert products.first_page?
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
searchkick-hooopo-2.3.3 test/pagination_test.rb
searchkick-hooopo-2.3.2 test/pagination_test.rb
searchkick-hooopo-2.3.1 test/pagination_test.rb
searchkick-hooopo-2.3.0 test/pagination_test.rb
searchkick-2.3.0 test/pagination_test.rb
searchkick-2.2.1 test/pagination_test.rb
searchkick-2.2.0 test/pagination_test.rb
searchkick-2.1.1 test/pagination_test.rb
searchkick-2.1.0 test/pagination_test.rb
searchkick-2.0.4 test/pagination_test.rb
searchkick-2.0.3 test/pagination_test.rb
searchkick-2.0.2 test/pagination_test.rb
searchkick-2.0.1 test/pagination_test.rb
searchkick-2.0.0 test/pagination_test.rb
searchkick-1.5.1 test/pagination_test.rb
searchkick-1.5.0 test/pagination_test.rb
searchkick-1.4.2 test/pagination_test.rb
searchkick-1.4.1 test/pagination_test.rb
searchkick-1.4.0 test/pagination_test.rb
searchkick-1.3.6 test/pagination_test.rb