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