Sha256: df17851bc978ce92e9fdf8e4dc17aeee0b789fbb5d88ff285055822eb0dd0d3c

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'test_helper'

class PaddingTest < ActiveSupport::TestCase
 
  test "negative padding should have 1 page" do
    15.times.each { |index| Model.create name: index }

    relation = Model.page(1, length: 15, padding: 4)
    assert_equal 11, relation.size
    assert_equal 1, relation.total_pages
 
    relation = Model.page(2, length: 15, padding: 4)
    assert_equal 0, relation.size
    assert_equal 1, relation.total_pages

    relation = Model.page(3, length: 15, padding: 4)
    assert_equal 0, relation.size
    assert_equal 1, relation.total_pages
  end

  test "negative padding should have 2 pages" do
    30.times.each { |index| Model.create name: index }
 
    relation = Model.page(1, length: 15, padding: 4)
    assert_equal 11, relation.size
    assert_equal 2, relation.total_pages

    relation = Model.page(2, length: 15, padding: 4)
    assert_equal 15, relation.size
    assert_equal 2, relation.total_pages
 
    relation = Model.page(3, length: 15, padding: 4)
    assert_equal 0, relation.size
    assert_equal 2, relation.total_pages
  end

  test "negative padding should have 3 pages" do
    45.times.each { |index| Model.create name: index }
 
    relation = Model.page(1, length: 15, padding: 4)
    assert_equal 11, relation.size
    assert_equal 3, relation.total_pages
 
    relation = Model.page(2, length: 15, padding: 4)
    assert_equal 15, relation.size
    assert_equal 3, relation.total_pages
 
    relation = Model.page(3, length: 15, padding: 4)
    assert_equal 15, relation.size
    assert_equal 3, relation.total_pages
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagers-3.0.0 test/padding_test.rb