Sha256: 80660f687821ebf2a94bbea8f4603b6c412e515152013a01db9b7abb709a9b9a

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

# Test the BentoSearch::Results::Pagination object
class PaginationTest < ActiveSupport::TestCase
  Pagination = BentoSearch::Results::Pagination

  def test_implicit_page
    pag = Pagination.new(100, {:per_page => 10})

    assert_equal 1, pag.current_page
    assert_equal 1, pag.start_record
    assert_equal 10, pag.end_record
    assert pag.first_page?
    assert ! pag.last_page?
    assert_equal 100, pag.count_records
    assert_equal 100, pag.total_count # some kaminari's want it called this instead.
    assert_equal 10, pag.total_pages
    assert_equal 10, pag.per_page
  end

  def test_last_page
    pag = Pagination.new(100, {:page => 5, :start => 80, :per_page => 20})

    assert_equal 5, pag.current_page
    assert_equal 81, pag.start_record
    assert_equal 80, pag.offset_value
    assert_equal 100, pag.end_record
    assert ! pag.first_page?
    assert pag.last_page?
    assert_equal 100, pag.count_records
    assert_equal 5, pag.total_pages
    assert_equal 20, pag.per_page
  end

  def test_uneven_pages
    pag = Pagination.new(95, {:page => 10, :start => 90, :per_page => 10})

    assert_equal 10, pag.current_page
    assert_equal 91, pag.start_record
    assert_equal 95, pag.end_record
    assert ! pag.first_page?
    assert pag.last_page?
    assert_equal 95, pag.count_records
    assert_equal 10, pag.total_pages
    assert_equal 10, pag.per_page
  end

  def test_empty_args
    pag = Pagination.new(nil, {})

    assert_equal 1, pag.current_page
    assert_equal 0, pag.start_record
    assert_equal 0, pag.end_record
    assert pag.first_page?
    assert pag.last_page?
    assert_equal 0, pag.count_records
    assert_equal 0, pag.total_pages
  end


end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bento_search-2.0.0.rc1 test/unit/pagination_test.rb
bento_search-1.7.0 test/unit/pagination_test.rb
bento_search-1.6.1 test/unit/pagination_test.rb
bento_search-1.7.0.beta.1 test/unit/pagination_test.rb
bento_search-1.6.0 test/unit/pagination_test.rb