Skip to content

Commit

Permalink
Use paginate method instead of using the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jwright committed Mar 14, 2019
1 parent 237fe5d commit 44f2b5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/laziness/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ module Slack
class Cursor
attr_reader :page

def initialize(page, &blk)
def initialize(page)
@page = page
paginate(&blk)
end

private

def paginate(&blk)
blk.call(Pager.new(page)) if block_given?
end
Expand Down
16 changes: 12 additions & 4 deletions spec/laziness/cursor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@
it 'initializes with page attributes' do
expect(described_class.new(page).page).to eq page
end
end

describe '#paginate' do
let(:page) { { limit: 10 } }

subject { described_class.new(page) }

it 'does not require a block' do
expect { described_class.new(page) }.to_not raise_error
expect { subject.paginate }.to_not raise_error
end

it 'yields a pager' do
expect { |b| described_class.new(page, &b) }.to yield_with_args(Slack::Pager)
expect { |b| subject.paginate(&b) }.to yield_with_args(Slack::Pager)
end

context 'with a nil page' do
it 'yields an empty pager' do
described_class.new(nil) do |pager|
subject { described_class.new(nil) }

it 'yields with an empty pager' do
subject.paginate do |pager|
expect(pager).to be_empty
end
end
Expand Down

0 comments on commit 44f2b5d

Please sign in to comment.