Sha256: 10e27246df78de68d73dd2d2b68f56ec6d9f7f6325c65ceb239638335b7fae4b

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

ENV['RACK_ENV'] ||= 'test'

require 'rspec'
require 'grape/pagy'
require 'rack/test'

Pagy::DEFAULT[:items] = 10
Pagy::DEFAULT[:max_items] = 20

class TestArray < Array
  def limit(num)
    self.class.new slice(0, num)
  end

  def offset(num)
    self.class.new slice(num..-1)
  end
end

class TestAPI < Grape::API
  helpers Grape::Pagy::Helpers

  params do
    use :pagy, items: 5, max_items: 6
  end
  get '' do
    pagy (1..12).to_a
  end

  params do
    use :pagy, items: 3
  end
  get '/countless' do
    pagy TestArray.new((1..12).to_a), using: :countless
  end

  resource :sub do
    params do
      use :pagy, items_param: :per_page
    end
    get '/' do
      pagy (1..12).to_a, count: 13
    end
  end
end

RSpec.configure do |config|
  config.include Rack::Test::Methods
  config.raise_errors_for_deprecations!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-pagy-0.5.0 spec/spec_helper.rb