Sha256: ac81f3df0629203c1b21b88587a91758640b209e0530a95b543f2c664db19e0d

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require "spec_helper"

describe Paginate::Base do
  let(:scope) { double }

  it "returns page from integer" do
    expect(Paginate::Base.new(scope, 12).page).to eql(12)
  end

  it "returns page from string" do
    expect(Paginate::Base.new(scope, "12").page).to eql(12)
  end

  it "defaults to page 1" do
    expect(Paginate::Base.new(scope).page).to eql(1)
  end

  it "returns page from options" do
    expect(Paginate::Base.new(scope, page: 12).page).to eql(12)
  end

  it "returns limit from configuration" do
    Paginate.configuration.size = 25
    expect(Paginate::Base.new(scope).limit).to eql(26)
  end

  it "returns limit from options" do
    Paginate.configuration.size = 25
    expect(Paginate::Base.new(scope, size: 13).limit).to eql(14)
  end

  it "returns default limit" do
    Paginate.configuration.size = nil
    expect(Paginate::Base.new(scope).limit).to eql(11)
  end

  it "returns offset from configuration" do
    Paginate.configuration.size = 15
    expect(Paginate::Base.new(scope, page: 2).offset).to eql(15)
  end

  it "returns offset from options" do
    expect(Paginate::Base.new(scope, page: 2, size: 5).offset).to eql(5)
  end

  it "returns finder options" do
    actual = Paginate::Base.new(scope, page: 3, size: 5).to_options
    expected = {limit: 6, offset: 10}

    expect(actual).to eql(expected)
  end

  specify {
    expect(Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(6)))
      .to have_next_page
  }

  specify {
    expect(Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(5)))
      .not_to have_next_page
  }

  specify {
    expect(Paginate::Base.new(scope, page: 2)).to have_previous_page
  }

  specify {
    expect(Paginate::Base.new(scope, page: 1)).not_to have_previous_page
  }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paginate-4.0.0 spec/paginate/base_spec.rb