Commit e913cf3f authored by James Lopez's avatar James Lopez

add pagination util and spec

parent c1ed642f
module Gitlab
module PaginationUtil
delegate :total_count,
:total_pages,
:current_page,
:limit_value,
:first_page?,
:prev_page,
:last_page?,
:next_page, to: :pagination_delegate
# requires a Gitlab::PaginationDelegate instance with the default configuration.
# Example:
# @pagination_delegate ||= Gitlab::PaginationDelegate.new(page: 1,
# per_page: 10,
# count: 20)
def pagination_delegate
raise NotImplementedError.new("Expected #{self.class.name} to implement #{__method__}")
end
end
end
require 'spec_helper'
describe Gitlab::PaginationUtil, lib: true do
context 'class with no pagination delegate defined' do
let(:pagination_class) { Class.new { extend Gitlab::PaginationUtil } }
it 'throws an error calling the method' do
expect { pagination_class.pagination_delegate }.to raise_error(NotImplementedError)
end
end
context 'class with no pagination delegate defined' do
let(:pagination_class) { Class.new { extend Gitlab::PaginationUtil } }
let(:pagination_delegate) {
Gitlab::PaginationDelegate.new(page: 1,
per_page: 10,
count: 20)
}
let(:delegated_methods) { %i[total_count total_pages current_page limit_value first_page? prev_page last_page? next_page] }
before do
allow(pagination_class).to receive(:pagination_delegate).and_return(pagination_delegate)
end
it 'does not throw an error' do
expect { pagination_class.pagination_delegate }.not_to raise_error
end
it 'includes the delegated methods' do
expect(pagination_class.public_methods).to include(*delegated_methods)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment